[flashrom] [PATCH] Clean up and fix libz detection

Carl-Daniel Hailfinger c-d.hailfinger.devel.2006 at gmx.net
Fri Oct 2 13:42:32 CEST 2009


There is no need to tell people to install libz if flashrom doesn't need
libz. So far, the only case where libz is needed is when a library
(libpci) pulls in libz and even then it only happens if libpci is
available in a static version only and said static version has libz
requirements.

Check for libpci separately and don't require libz if it isn't needed.

Clarify the README.

Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006 at gmx.net>

Index: flashrom-libz_detection/Makefile
===================================================================
--- flashrom-libz_detection/Makefile	(Revision 742)
+++ flashrom-libz_detection/Makefile	(Arbeitskopie)
@@ -41,7 +41,7 @@
 LDFLAGS += -L/usr/local/lib
 endif
 
-LIBS += -lpci -lz
+LIBS += -lpci
 
 OBJS = chipset_enable.o board_enable.o udelay.o jedec.o stm50flw0x0x.o \
 	sst28sf040.o am29f040b.o mx29f002.o m29f400bt.o pm29f002.o \
@@ -142,6 +142,9 @@
 OBJS += print_wiki.o
 endif
 
+# We could use PULLED_IN_LIBS, but that would be ugly.
+FEATURE_LIBS += $(shell LC_ALL=C grep -q "NEEDLIBZ := yes" .libdeps && printf "%s" "-lz")
+
 $(PROGRAM): $(OBJS)
 	$(CC) $(LDFLAGS) -o $(PROGRAM) $(OBJS) $(LIBS) $(FEATURE_LIBS)
 
@@ -157,7 +160,7 @@
 	rm -f $(PROGRAM) *.o
 
 distclean: clean
-	rm -f .dependencies .features
+	rm -f .dependencies .features .libdeps
 
 dep:
 	@$(CC) $(CPPFLAGS) $(SVNDEF) -MM *.c > .dependencies
@@ -175,17 +178,36 @@
 	@rm -f .test.c .test
 
 pciutils: compiler
-	@printf "Checking for pciutils and zlib... "
+	@printf "Checking for libpci headers... "
 	@$(shell ( echo "#include <pci/pci.h>";		   \
 		   echo "struct pci_access *pacc;";	   \
 		   echo "int main(int argc, char **argv)"; \
 		   echo "{ pacc = pci_alloc(); return 0; }"; ) > .test.c )
-	@$(CC) $(CFLAGS) $(LDFLAGS) .test.c -o .test $(LIBS) >/dev/null 2>&1 &&	\
-		echo "found." || ( echo "not found."; echo;		\
-		echo "Please install pciutils-devel and zlib-devel.";	\
-		echo "See README for more information."; echo;		\
-		rm -f .test.c .test; exit 1)
-	@rm -f .test.c .test
+	@$(CC) -c $(CFLAGS) .test.c -o .test.o >/dev/null 2>&1 &&		\
+		echo "found." || ( echo "not found."; echo;			\
+		echo "Please install libpci headers (package pciutils-devel).";	\
+		echo "See README for more information."; echo;			\
+		rm -f .test.c .test.o; exit 1)
+	@printf "Checking for libpci... "
+	@$(shell ( echo "#include <pci/pci.h>";		   \
+		   echo "int main(int argc, char **argv)"; \
+		   echo "{ return 0; }"; ) > .test1.c )
+	@$(CC) $(CFLAGS) $(LDFLAGS) .test1.c -o .test1 $(LIBS) >/dev/null 2>&1 &&	\
+		echo "found." || ( echo "not found."; echo;				\
+		echo "Please install libpci (package pciutils).";			\
+		echo "See README for more information."; echo;				\
+		rm -f .test1.c .test1; exit 1)
+	@printf "Checking if libpci is sufficient... "
+	@printf "" > .libdeps
+	@$(CC) $(LDFLAGS) .test.o -o .test $(LIBS) >/dev/null 2>&1 &&				\
+		echo "yes." || ( echo "no.";							\
+		printf "Checking if libz is present and supplies all needed symbols...";	\
+		$(CC) $(LDFLAGS) .test.o -o .test $(LIBS) -lz >/dev/null 2>&1 &&		\
+		( echo "yes."; echo "NEEDLIBZ := yes" > .libdeps ) || ( echo "no."; echo;	\
+		echo "Please install libz.";			\
+		echo "See README for more information."; echo;				\
+		rm -f .test.c .test.o .test; exit 1) )
+	@rm -f .test.c .test.o .test .test1.c .test1
 
 .features: features
 
Index: flashrom-libz_detection/README
===================================================================
--- flashrom-libz_detection/README	(Revision 742)
+++ flashrom-libz_detection/README	(Arbeitskopie)
@@ -38,7 +38,7 @@
 
 Linux et al:
 
- * pciutils
+ * pciutils / libpci
  * pciutils-devel / pciutils-dev / libpci-dev
  * zlib-devel / zlib1g-dev (only needed if libpci is static)
 
@@ -79,13 +79,16 @@
 
 In order to install flashrom and the manpage into /usr/local, type:
 
- sudo make install
+ make install
 
 For installation in a different directory use DESTDIR, e.g. like this:
 
- sudo make DESTDIR=/usr install
+ make DESTDIR=/usr install
 
+If you have insufficient permissions for the destination directory, use sudo
+by adding sudo in front of the commands above.
 
+
 Usage / Options
 ---------------
 


-- 
http://www.hailfinger.org/





More information about the flashrom mailing list