Anastasia Klimchuk submitted this change.
Remove dependency on C23 __has_include()
Use build system to check header presence:
* getopt.h (from include/cli_classic.h)
* pciutils/pci.h (from include/platform/pci.h)
Tested with <getopt.h> and <pci/pci.h> using GNU Make 4.1, 4.2.1, 4.4.1
and Meson 0.56.0, 1.2.1 against GCC 13.2.1 and GCC 5.5-, 7.3-compatible
(EDG 4.14-, 5.1-based) on openSuSE Tumbleweed and a custom LFS distro.
Change-Id: Ic544963ffd29626ae0a21bdddb1c78850cc43ec6
Signed-off-by: Anton Samsonov <devel@zxlab.ru>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/77089
Reviewed-by: Alexander Goncharov <chat@joursoir.net>
Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
---
M Makefile
A Makefile.d/getopt_test.c
A Makefile.d/pciutils_test.c
M include/cli_classic.h
M include/platform/pci.h
M meson.build
6 files changed, 38 insertions(+), 4 deletions(-)
diff --git a/Makefile b/Makefile
index bf01d0f..ae37d17 100644
--- a/Makefile
+++ b/Makefile
@@ -242,6 +242,7 @@
HAS_LIBUSB1 := $(call find_dependency, libusb-1.0)
HAS_LIBPCI := $(call find_dependency, libpci)
+HAS_GETOPT := $(call c_compile_test, Makefile.d/getopt_test.c)
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)
@@ -249,6 +250,7 @@
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_PCIUTILS := $(call c_compile_test, Makefile.d/pciutils_test.c)
HAS_SERIAL := $(strip $(if $(filter $(TARGET_OS), DOS libpayload), no, yes))
HAS_SPHINXBUILD := $(shell command -v $(SPHINXBUILD) >/dev/null 2>/dev/null && echo yes || echo no)
EXEC_SUFFIX := $(strip $(if $(filter $(TARGET_OS), DOS MinGW), .exe))
@@ -945,6 +947,14 @@
endif
endif
+ifeq ($(HAS_GETOPT), yes)
+override CFLAGS += -D'HAVE_GETOPT_H=1'
+endif
+
+ifeq ($(HAS_PCIUTILS), yes)
+override CFLAGS += -D'HAVE_PCIUTILS_PCI_H=1'
+endif
+
OBJS = $(CHIP_OBJS) $(PROGRAMMER_OBJS) $(LIB_OBJS)
@@ -994,11 +1004,13 @@
echo " CFLAGS: $(CONFIG_LIBFTDI1_CFLAGS)"; \
echo " LDFLAGS: $(CONFIG_LIBFTDI1_LDFLAGS)"; \
fi
+ @echo "Checking for header \"getopt.h\": $(HAS_GETOPT)"
@echo "Checking for header \"mtd/mtd-user.h\": $(HAS_LINUX_MTD)"
@echo "Checking for header \"linux/spi/spidev.h\": $(HAS_LINUX_SPI)"
@echo "Checking for header \"linux/i2c-dev.h\": $(HAS_LINUX_I2C)"
@echo "Checking for header \"linux/i2c.h\": $(HAS_LINUX_I2C)"
@echo "Checking for header \"sys/utsname.h\": $(HAS_UTSNAME)"
+ @echo "Checking for header \"pciutils/pci.h\": $(HAS_PCIUTILS)"
@echo "Checking for function \"clock_gettime\": $(HAS_CLOCK_GETTIME)"
@echo "Checking for external \"librt\": $(HAS_EXTERN_LIBRT)"
@if ! [ "$(PROGRAMMER_OBJS)" ]; then \
diff --git a/Makefile.d/getopt_test.c b/Makefile.d/getopt_test.c
new file mode 100644
index 0000000..9f72608
--- /dev/null
+++ b/Makefile.d/getopt_test.c
@@ -0,0 +1,8 @@
+#include <getopt.h>
+
+int main(int argc, char **argv)
+{
+ (void)argc;
+ (void)argv;
+ return 0;
+}
diff --git a/Makefile.d/pciutils_test.c b/Makefile.d/pciutils_test.c
new file mode 100644
index 0000000..3d67c29
--- /dev/null
+++ b/Makefile.d/pciutils_test.c
@@ -0,0 +1,8 @@
+#include <pciutils/pci.h>
+
+int main(int argc, char **argv)
+{
+ (void)argc;
+ (void)argv;
+ return 0;
+}
diff --git a/include/cli_classic.h b/include/cli_classic.h
index e651cc6..eb1f0fe 100644
--- a/include/cli_classic.h
+++ b/include/cli_classic.h
@@ -15,7 +15,7 @@
#ifndef CLI_CLASSIC_H
#define CLI_CLASSIC_H
-#if __has_include(<getopt.h>)
+#ifdef HAVE_GETOPT_H
#include <getopt.h>
#else
@@ -39,5 +39,5 @@
int getopt_long_only (int argc, char *const *argv, const char *shortopts,
const struct option *longopts, int *longind);
-#endif /* __has_include() */
+#endif /* HAVE_GETOPT_H */
#endif /* CLI_CLASSIC_H */
diff --git a/include/platform/pci.h b/include/platform/pci.h
index 4ac108f..6abde59 100644
--- a/include/platform/pci.h
+++ b/include/platform/pci.h
@@ -22,10 +22,10 @@
* e.g. NetBSD 9.0 on sparc64 pciutils-3.7.0nb2.
* Other NetBSD platforms and versions uses the default path under pci/pci.h
*/
-#if __has_include(<pciutils/pci.h>)
+#ifdef HAVE_PCIUTILS_PCI_H
#include <pciutils/pci.h>
#else
#include <pci/pci.h>
-#endif
+#endif /* HAVE_PCIUTILS_PCI_H */
#endif /* __PLATFORM_PCI_H__ */
diff --git a/meson.build b/meson.build
index c85fdf4..7c46de4 100644
--- a/meson.build
+++ b/meson.build
@@ -114,6 +114,12 @@
if cc.has_function('strnlen')
add_project_arguments('-DHAVE_STRNLEN=1', language : 'c')
endif
+if cc.check_header('getopt.h')
+ add_project_arguments('-DHAVE_GETOPT_H=1', language : 'c')
+endif
+if cc.check_header('pciutils/pci.h')
+ add_project_arguments('-DHAVE_PCIUTILS_PCI_H=1', language : 'c')
+endif
if cc.check_header('sys/utsname.h')
add_project_arguments('-DHAVE_UTSNAME=1', language : 'c')
endif
To view, visit change 77089. To unsubscribe, or for help writing mail filters, visit settings.