summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Samsonov <Anton.V.Samsonov@mcst.ru>2023-11-24 15:03:51 +0300
committerAnastasia Klimchuk <aklm@chromium.org>2023-11-28 23:26:01 +0000
commit8efe4fb7083b06650821bb6d4b700365bc46eeac (patch)
tree453d4e09720283594cbfb3ac1e142acb07639791
parentbda8361453077a6db2f895eccd345f17bfabfb94 (diff)
downloadflashrom-8efe4fb7083b06650821bb6d4b700365bc46eeac.tar.gz
flashrom-8efe4fb7083b06650821bb6d4b700365bc46eeac.tar.bz2
flashrom-8efe4fb7083b06650821bb6d4b700365bc46eeac.zip
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>
-rw-r--r--Makefile12
-rw-r--r--Makefile.d/getopt_test.c8
-rw-r--r--Makefile.d/pciutils_test.c8
-rw-r--r--include/cli_classic.h4
-rw-r--r--include/platform/pci.h4
-rw-r--r--meson.build6
6 files changed, 38 insertions, 4 deletions
diff --git a/Makefile b/Makefile
index bf01d0f8c..ae37d17a9 100644
--- a/Makefile
+++ b/Makefile
@@ -242,6 +242,7 @@ HAS_LIBJAYLINK := $(call find_dependency, libjaylink)
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_EXTERN_LIBRT := $(call c_link_test, Makefile.d/clock_gettime_test.c, , -l
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 @@ override LDFLAGS += -lrt
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 @@ config:
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 000000000..9f726080b
--- /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 000000000..3d67c292f
--- /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 e651cc636..eb1f0fe95 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 (int argc, char *const *argv, const char *shortopts,
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 4ac108f26..6abde5923 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 c85fdf4d0..7c46de4b9 100644
--- a/meson.build
+++ b/meson.build
@@ -114,6 +114,12 @@ endif
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