summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Heijligen <thomas.heijligen@secunet.com>2021-11-05 12:28:06 +0100
committerNico Huber <nico.h@gmx.de>2022-01-20 17:10:55 +0000
commit462a6159ab8bcebd4ef5c16e9e436ee10ec0cf48 (patch)
tree0bf7cc504c5e01381c027a31d124b34638961bc4
parent980cf7d31f7b18a3da38a8fd954998b9a74dde33 (diff)
downloadflashrom-462a6159ab8bcebd4ef5c16e9e436ee10ec0cf48.tar.gz
flashrom-462a6159ab8bcebd4ef5c16e9e436ee10ec0cf48.tar.bz2
flashrom-462a6159ab8bcebd4ef5c16e9e436ee10ec0cf48.zip
Makefile: Make pkg-config mandatory to find libpci
Use `make HAS_LIBPCI=yes/no` to override the pkg-config detection and `CONFIG_LIBPCI_CFLAGS` and `CONFIG_LIBPCI_LDFLAGS` to set cflags and ldflags manually. The optional dependency of libpci libz, is automatically handled by pkg-config. Change-Id: I21b4a261b34b7e688635fc6e20b7beebfa64c7ed Signed-off-by: Thomas Heijligen <thomas.heijligen@secunet.com> Reviewed-on: https://review.coreboot.org/c/flashrom/+/59050 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Nico Huber <nico.h@gmx.de> Reviewed-by: Paul Menzel <paulepanter@mailbox.org>
-rw-r--r--Makefile102
-rw-r--r--Makefile.d/pci_old_get_dev_test.c17
-rw-r--r--Makefile.include40
3 files changed, 54 insertions, 105 deletions
diff --git a/Makefile b/Makefile
index 3325aa6c5..4ed52e3b0 100644
--- a/Makefile
+++ b/Makefile
@@ -218,26 +218,31 @@ CONFIG_LIBJAYLINK_LDFLAGS := $(call dependency_ldflags, libjaylink)
CONFIG_LIBUSB1_CFLAGS := $(call dependency_cflags, libusb-1.0)
CONFIG_LIBUSB1_LDFLAGS := $(call dependency_ldflags, libusb-1.0)
+CONFIG_LIBPCI_CFLAGS := $(call dependency_cflags, libpci)
+CONFIG_LIBPCI_LDFLAGS := $(call dependency_ldflags, libpci)
+
# Determine the destination OS, architecture and endian
# IMPORTANT: The following lines must be placed before TARGET_OS, ARCH or ENDIAN
# is ever used (of course), but should come after any lines setting CC because
# the lines below use CC itself.
-override TARGET_OS := $(call c_macro_test, Makefile.d/os_test.h)
-override ARCH := $(call c_macro_test, Makefile.d/arch_test.h)
-override ENDIAN := $(call c_macro_test, Makefile.d/endian_test.h)
+override TARGET_OS := $(call c_macro_test, Makefile.d/os_test.h)
+override ARCH := $(call c_macro_test, Makefile.d/arch_test.h)
+override ENDIAN := $(call c_macro_test, Makefile.d/endian_test.h)
-HAS_LIBFTDI1 := $(call find_dependency, libftdi1)
-HAS_LIB_NI845X := no
-HAS_LIBJAYLINK := $(call find_dependency, libjaylink)
-HAS_LIBUSB1 := $(call find_dependency, libusb-1.0)
+HAS_LIBFTDI1 := $(call find_dependency, libftdi1)
+HAS_LIB_NI845X := no
+HAS_LIBJAYLINK := $(call find_dependency, libjaylink)
+HAS_LIBUSB1 := $(call find_dependency, libusb-1.0)
+HAS_LIBPCI := $(call find_dependency, libpci)
-HAS_FT232H := $(call c_compile_test, Makefile.d/ft232h_test.c, $(CONFIG_LIBFTDI1_CFLAGS))
-HAS_UTSNAME := $(call c_compile_test, Makefile.d/utsname_test.c)
-HAS_CLOCK_GETTIME := $(call c_compile_test, Makefile.d/clock_gettime_test.c)
-HAS_LINUX_MTD := $(call c_compile_test, Makefile.d/linux_mtd_test.c)
-HAS_LINUX_SPI := $(call c_compile_test, Makefile.d/linux_spi_test.c)
-HAS_LINUX_I2C := $(call c_compile_test, Makefile.d/linux_i2c_test.c)
+HAS_PCI_OLD_GET_DEV := $(call c_compile_test, Makefile.d/pci_old_get_dev_test.c, $(CONFIG_LIBPCI_CFLAGS))
+HAS_FT232H := $(call c_compile_test, Makefile.d/ft232h_test.c, $(CONFIG_LIBFTDI1_CFLAGS))
+HAS_UTSNAME := $(call c_compile_test, Makefile.d/utsname_test.c)
+HAS_CLOCK_GETTIME := $(call c_compile_test, Makefile.d/clock_gettime_test.c)
+HAS_LINUX_MTD := $(call c_compile_test, Makefile.d/linux_mtd_test.c)
+HAS_LINUX_SPI := $(call c_compile_test, Makefile.d/linux_spi_test.c)
+HAS_LINUX_I2C := $(call c_compile_test, Makefile.d/linux_i2c_test.c)
ifeq ($(TARGET_OS), $(filter $(TARGET_OS), FreeBSD OpenBSD DragonFlyBSD))
override CPPFLAGS += -I/usr/local/include
@@ -327,6 +332,10 @@ ifneq ($(ARCH)-little, $(filter $(ARCH), x86 mips)-$(ENDIAN))
$(call mark_unsupported,CONFIG_INTERNAL)
endif
+ifeq ($(HAS_LIBPCI), no)
+$(call mark_unsupported,$(DEPENDS_ON_LIBPCI))
+endif
+
ifeq ($(HAS_LIBFTDI1), no)
$(call mark_unsupported,$(DEPENDS_ON_LIBFTDI1))
endif
@@ -810,21 +819,6 @@ LIBS += -lsocket -lnsl
endif
endif
-NEED_LIBPCI := $(call filter_deps,$(DEPENDS_ON_LIBPCI))
-ifneq ($(NEED_LIBPCI), )
-CHECK_LIBPCI = yes
-FEATURE_CFLAGS += -D'NEED_PCI=1'
-FEATURE_CFLAGS += $(call debug_shell,grep -q "OLD_PCI_GET_DEV := yes" .libdeps && printf "%s" "-D'OLD_PCI_GET_DEV=1'")
-
-PROGRAMMER_OBJS += pcidev.o
-ifeq ($(TARGET_OS), NetBSD)
-# The libpci we want is called libpciutils on NetBSD and needs NetBSD libpci.
-PCILIBS += -lpciutils -lpci
-else
-PCILIBS += -lpci
-endif
-endif
-
USE_X86_MSR := $(if $(call filter_deps,$(DEPENDS_ON_X86_MSR)),yes,no)
ifeq ($(USE_X86_MSR), yes)
PROGRAMMER_OBJS += hwaccess_x86_msr.o
@@ -853,6 +847,14 @@ ifeq (OpenBSD yes, $(TARGET_OS) $(filter $(USE_X86_MSR) $(USE_X86_PORT_IO), yes)
override LDFLAGS += -l$(shell uname -m)
endif
+USE_LIBPCI := $(if $(call filter_deps,$(DEPENDS_ON_LIBPCI)),yes,no)
+ifeq ($(USE_LIBPCI), yes)
+PROGRAMMER_OBJS += pcidev.o
+FEATURE_CFLAGS += -D'NEED_PCI=1'
+override CFLAGS += $(CONFIG_LIBPCI_CFLAGS)
+override LDFLAGS += $(CONFIG_LIBPCI_LDFLAGS)
+endif
+
USE_LIBUSB1 := $(if $(call filter_deps,$(DEPENDS_ON_LIBUSB1)),yes,no)
ifeq ($(USE_LIBUSB1), yes)
override CFLAGS += $(CONFIG_LIBUSB1_CFLAGS)
@@ -886,9 +888,6 @@ FEATURE_CFLAGS += -D'CONFIG_PRINT_WIKI=1'
CLI_OBJS += print_wiki.o
endif
-# We could use PULLED_IN_LIBS, but that would be ugly.
-FEATURE_LIBS += $(call debug_shell,grep -q "NEEDLIBZ := yes" .libdeps && printf "%s" "-lz")
-
ifeq ($(HAS_UTSNAME), yes)
FEATURE_CFLAGS += -D'HAVE_UTSNAME=1'
endif
@@ -907,7 +906,7 @@ ifeq ($(ARCH), x86)
endif
$(PROGRAM)$(EXEC_SUFFIX): $(OBJS)
- $(CC) -o $(PROGRAM)$(EXEC_SUFFIX) $(OBJS) $(LDFLAGS) $(LIBS) $(PCILIBS) $(FEATURE_LIBS)
+ $(CC) -o $(PROGRAM)$(EXEC_SUFFIX) $(OBJS) $(LDFLAGS) $(LIBS) $(FEATURE_LIBS)
libflashrom.a: $(LIBFLASHROM_OBJS)
$(AR) rcs $@ $^
@@ -953,39 +952,12 @@ compiler: featuresavailable
@if [ $(ENDIAN) = unknown ]; then echo Aborting.; exit 1; fi
hwlibs: compiler
- @printf "" > .libdeps
-ifeq ($(CHECK_LIBPCI), yes)
- @printf "Checking for libpci headers... " | tee -a $(BUILD_DETAILS_FILE)
- @echo "$$LIBPCI_TEST" > .test.c
- @printf "\nexec: %s\n" "$(CC) -c $(CPPFLAGS) $(CFLAGS) .test.c -o .test.o" >>$(BUILD_DETAILS_FILE)
- @{ { { { { $(CC) -c $(CPPFLAGS) $(CFLAGS) .test.c -o .test.o >&2 && \
- echo "found." || { echo "not found."; echo; \
- echo "The following features require libpci: $(NEED_LIBPCI)."; \
- echo "Please install libpci headers or disable all features"; \
- echo "mentioned above by specifying make CONFIG_ENABLE_LIBPCI_PROGRAMMERS=no"; \
- echo "See README for more information."; echo; \
- rm -f .test.c .test.o; exit 1; }; } 2>>$(BUILD_DETAILS_FILE); echo $? >&3 ; } | tee -a $(BUILD_DETAILS_FILE) >&4; } 3>&1;} | { read rc ; exit ${rc}; } } 4>&1
- @printf "Checking version of pci_get_dev... " | tee -a $(BUILD_DETAILS_FILE)
- @echo "$$PCI_GET_DEV_TEST" > .test.c
- @printf "\nexec: %s\n" "$(CC) -c $(CPPFLAGS) $(CFLAGS) .test.c -o .test.o" >>$(BUILD_DETAILS_FILE)
- @ { $(CC) -c $(CPPFLAGS) $(CFLAGS) .test.c -o .test.o >&2 && \
- ( echo "new version (including PCI domain parameter)."; echo "OLD_PCI_GET_DEV := no" >> .libdeps ) || \
- ( echo "old version (without PCI domain parameter)."; echo "OLD_PCI_GET_DEV := yes" >> .libdeps ) } 2>>$(BUILD_DETAILS_FILE) | tee -a $(BUILD_DETAILS_FILE)
- @printf "Checking if libpci is present and sufficient... " | tee -a $(BUILD_DETAILS_FILE)
- @printf "\nexec: %s\n" "$(CC) $(LDFLAGS) .test.o -o .test$(EXEC_SUFFIX) $(LIBS) $(PCILIBS)" >>$(BUILD_DETAILS_FILE)
- @{ { { { $(CC) $(LDFLAGS) .test.o -o .test$(EXEC_SUFFIX) $(LIBS) $(PCILIBS) 2>>$(BUILD_DETAILS_FILE) >&2 && \
- echo "yes." || { echo "no."; \
- printf "Checking if libz+libpci are present and sufficient..." ; \
- { printf "\nexec: %s\n" "$(CC) $(LDFLAGS) .test.o -o .test$(EXEC_SUFFIX) $(LIBS) $(PCILIBS) -lz" >>$(BUILD_DETAILS_FILE) ; \
- $(CC) $(LDFLAGS) .test.o -o .test$(EXEC_SUFFIX) $(LIBS) $(PCILIBS) -lz >&2 && \
- echo "yes." && echo "NEEDLIBZ := yes" > .libdeps } || { echo "no."; echo; \
- echo "The following features require libpci: $(NEED_LIBPCI)."; \
- echo "Please install libpci (package pciutils) and/or libz or disable all features"; \
- echo "mentioned above by specifying make CONFIG_ENABLE_LIBPCI_PROGRAMMERS=no"; \
- echo "See README for more information."; echo; \
- rm -f .test.c .test.o .test$(EXEC_SUFFIX); exit 1; }; }; } 2>>$(BUILD_DETAILS_FILE); echo $? >&3 ; } | tee -a $(BUILD_DETAILS_FILE) >&4; } 3>&1;} | { read rc ; exit ${rc}; } } 4>&1
- @rm -f .test.c .test.o .test$(EXEC_SUFFIX)
-endif
+ @echo Dependency libpci found: $(HAS_LIBPCI)
+ @if [ $(HAS_LIBPCI) = yes ]; then \
+ echo " Checking for old \"pci_get_dev()\": $(HAS_PCI_OLD_GET_DEV)";\
+ echo " CFLAGS: $(CONFIG_LIBPCI_CFLAGS)"; \
+ echo " LDFLAGS: $(CONFIG_LIBPCI_LDFLAGS)"; \
+ fi
@echo Dependency libusb1 found: $(HAS_LIBUSB1)
@if [ $(HAS_LIBUSB1) = yes ]; then \
echo " CFLAGS: $(CONFIG_LIBUSB1_CFLAGS)"; \
diff --git a/Makefile.d/pci_old_get_dev_test.c b/Makefile.d/pci_old_get_dev_test.c
new file mode 100644
index 000000000..322365159
--- /dev/null
+++ b/Makefile.d/pci_old_get_dev_test.c
@@ -0,0 +1,17 @@
+/* Avoid a failing test due to libpci header symbol shadowing breakage */
+#define index shadow_workaround_index
+#if !defined __NetBSD__
+#include <pci/pci.h>
+#else
+#include <pciutils/pci.h>
+#endif
+struct pci_access *pacc;
+struct pci_dev *dev = {0};
+int main(int argc, char **argv)
+{
+ (void) argc;
+ (void) argv;
+ pacc = pci_alloc();
+ dev = pci_get_dev(pacc, dev->bus, dev->dev, 1);
+ return 0;
+}
diff --git a/Makefile.include b/Makefile.include
index 67eec5292..a3abcad81 100644
--- a/Makefile.include
+++ b/Makefile.include
@@ -51,43 +51,3 @@ endef
define dependency_ldflags
$(call debug_shell, $(if $(PKG_CONFIG_LIBDIR),PKG_CONFIG_LIBDIR=$(PKG_CONFIG_LIBDIR),) $(PKG_CONFIG) --libs $1 2>/dev/null)
endef
-
-define LIBPCI_TEST
-/* Avoid a failing test due to libpci header symbol shadowing breakage */
-#define index shadow_workaround_index
-#if !defined __NetBSD__
-#include <pci/pci.h>
-#else
-#include <pciutils/pci.h>
-#endif
-struct pci_access *pacc;
-int main(int argc, char **argv)
-{
- (void) argc;
- (void) argv;
- pacc = pci_alloc();
- return 0;
-}
-endef
-export LIBPCI_TEST
-
-define PCI_GET_DEV_TEST
-/* Avoid a failing test due to libpci header symbol shadowing breakage */
-#define index shadow_workaround_index
-#if !defined __NetBSD__
-#include <pci/pci.h>
-#else
-#include <pciutils/pci.h>
-#endif
-struct pci_access *pacc;
-struct pci_dev *dev = {0};
-int main(int argc, char **argv)
-{
- (void) argc;
- (void) argv;
- pacc = pci_alloc();
- dev = pci_get_dev(pacc, dev->domain, dev->bus, dev->dev, 1);
- return 0;
-}
-endef
-export PCI_GET_DEV_TEST