From ba275d8bdb1eacd357b942b0aa7df5612f751fc5 Mon Sep 17 00:00:00 2001 From: Thomas Heijligen Date: Tue, 28 Sep 2021 15:22:34 +0200 Subject: Makefile: move determination test for OS to Makefile.d Move the test code for OS detection in a extra directory to split it from the main flashrom code. Change-Id: Id911f17f4100f242e1fde10d23a8459ddf38b369 Signed-off-by: Thomas Heijligen Reviewed-on: https://review.coreboot.org/c/flashrom/+/58015 Tested-by: build bot (Jenkins) Reviewed-by: Nico Huber --- .gitignore | 1 + Makefile | 13 +++----- Makefile.d/os_test.h | 67 ++++++++++++++++++++++++++++++++++++++ Makefile.include | 4 +++ os.h | 65 ------------------------------------ util/ich_descriptors_tool/Makefile | 5 +-- 6 files changed, 79 insertions(+), 76 deletions(-) create mode 100644 Makefile.d/os_test.h delete mode 100644 os.h diff --git a/.gitignore b/.gitignore index 2d621dcd..7c45abac 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.d +!Makefile.d/ *.o /.features /.dependencies diff --git a/Makefile b/Makefile index a94f9f64..f8ff0973 100644 --- a/Makefile +++ b/Makefile @@ -162,14 +162,12 @@ endif # 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 := $(strip $(call debug_shell,$(CC) $(CPPFLAGS) -E os.h 2>/dev/null \ - | tail -1 | cut -f 2 -d'"')) +override TARGET_OS := $(call c_macro_test, Makefile.d/os_test.h) override ARCH := $(strip $(call debug_shell,$(CC) $(CPPFLAGS) -E archtest.c 2>/dev/null \ | tail -1 | cut -f 2 -d'"')) override ENDIAN := $(strip $(call debug_shell,$(CC) $(CPPFLAGS) -E endiantest.c 2>/dev/null \ | tail -1)) - ifeq ($(TARGET_OS), $(filter $(TARGET_OS), FreeBSD OpenBSD DragonFlyBSD)) override CPPFLAGS += -I/usr/local/include override LDFLAGS += -L/usr/local/lib @@ -848,7 +846,7 @@ TAROPTIONS = $(shell LC_ALL=C tar --version|grep -q GNU && echo "--owner=root -- # This includes all frontends and libflashrom. # We don't use EXEC_SUFFIX here because we want to clean everything. clean: - rm -f $(PROGRAM) $(PROGRAM).exe libflashrom.a *.o *.d $(PROGRAM).8 $(PROGRAM).8.html $(BUILD_DETAILS_FILE) + rm -f $(PROGRAM) $(PROGRAM).exe libflashrom.a $(filter-out Makefile.d, $(wildcard *.d *.o)) $(PROGRAM).8 $(PROGRAM).8.html $(BUILD_DETAILS_FILE) @+$(MAKE) -C util/ich_descriptors_tool/ clean distclean: clean @@ -873,11 +871,8 @@ compiler: featuresavailable @echo $(ARCH)|wc -w|grep -q '^[[:blank:]]*1[[:blank:]]*$$' || \ ( echo "unknown (\"$(ARCH)\"). Aborting."; exit 1) @printf "%s\n" '$(ARCH)' - @printf "Target OS is " - @# FreeBSD wc will output extraneous whitespace. - @echo $(TARGET_OS)|wc -w|grep -q '^[[:blank:]]*1[[:blank:]]*$$' || \ - ( echo "unknown (\"$(TARGET_OS)\"). Aborting."; exit 1) - @printf "%s\n" '$(TARGET_OS)' + @echo Target OS is $(TARGET_OS) + @if [ $(TARGET_OS) = unknown ]; then echo Aborting.; exit 1; fi ifeq ($(TARGET_OS), libpayload) @$(CC) --version 2>&1 | grep -q coreboot || \ ( echo "Warning: It seems you are not using coreboot's reference compiler."; \ diff --git a/Makefile.d/os_test.h b/Makefile.d/os_test.h new file mode 100644 index 00000000..17045b25 --- /dev/null +++ b/Makefile.d/os_test.h @@ -0,0 +1,67 @@ +/* + * This file is part of the flashrom project. + * + * Copyright (C) 2011 Carl-Daniel Hailfinger + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +/* + * This file determinate the target os. It should only be used my the Makefile + */ + +// Solaris +#if defined (__sun) && (defined(__i386) || defined(__amd64)) +#define __FLASHROM_OS__ "SunOS" +// OS X +#elif defined(__MACH__) && defined(__APPLE__) +#define __FLASHROM_OS__ "Darwin" +// FreeBSD +#elif defined(__FreeBSD__) +#define __FLASHROM_OS__ "FreeBSD" +// FreeBSD with glibc-based userspace (e.g. Debian/kFreeBSD) +#elif defined(__FreeBSD_kernel__) && defined(__GLIBC__) +#define __FLASHROM_OS__ "FreeBSD-glibc" +// DragonFlyBSD +#elif defined(__DragonFly__) +#define __FLASHROM_OS__ "DragonFlyBSD" +// NetBSD +#elif defined(__NetBSD__) +#define __FLASHROM_OS__ "NetBSD" +// OpenBSD +#elif defined(__OpenBSD__) +#define __FLASHROM_OS__ "OpenBSD" +// DJGPP +#elif defined(__DJGPP__) +#define __FLASHROM_OS__ "DOS" +// MinGW (always has _WIN32 available) +#elif defined(__MINGW32__) +#define __FLASHROM_OS__ "MinGW" +// Cygwin (usually without _WIN32) +#elif defined( __CYGWIN__) +#define __FLASHROM_OS__ "Cygwin" +// libpayload +#elif defined(__LIBPAYLOAD__) +#define __FLASHROM_OS__ "libpayload" +// GNU Hurd +#elif defined(__gnu_hurd__) +#define __FLASHROM_OS__ "Hurd" +// Linux +#elif defined(__linux__) + // There are various flags in use on Android apparently. __ANDROID__ seems to be the most trustworthy. + #if defined(__ANDROID__) + #define __FLASHROM_OS__ "Android" + #else + #define __FLASHROM_OS__ "Linux" + #endif +#else +#define __FLASHROM_OS__ "unknown" +#endif +__FLASHROM_OS__ diff --git a/Makefile.include b/Makefile.include index 36746c80..ca70d051 100644 --- a/Makefile.include +++ b/Makefile.include @@ -31,6 +31,10 @@ $(foreach p,$1, \ $(eval override $(p) := no)) endef +# Run the C Preprocessor with file $1 and return the last line, removing quotes. +define c_macro_test +$(strip $(shell $(CC) -E $1 2>/dev/null | tail -1 | tr -d '"')) +endef define COMPILER_TEST int main(int argc, char **argv) diff --git a/os.h b/os.h deleted file mode 100644 index d6fbfe0b..00000000 --- a/os.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * This file is part of the flashrom project. - * - * Copyright (C) 2011 Carl-Daniel Hailfinger - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - */ - -/* - * Header file for OS checking. - */ - -// Solaris -#if defined (__sun) && (defined(__i386) || defined(__amd64)) -#define __FLASHROM_OS__ "SunOS" -// OS X -#elif defined(__MACH__) && defined(__APPLE__) -#define __FLASHROM_OS__ "Darwin" -// FreeBSD -#elif defined(__FreeBSD__) -#define __FLASHROM_OS__ "FreeBSD" -// FreeBSD with glibc-based userspace (e.g. Debian/kFreeBSD) -#elif defined(__FreeBSD_kernel__) && defined(__GLIBC__) -#define __FLASHROM_OS__ "FreeBSD-glibc" -// DragonFlyBSD -#elif defined(__DragonFly__) -#define __FLASHROM_OS__ "DragonFlyBSD" -// NetBSD -#elif defined(__NetBSD__) -#define __FLASHROM_OS__ "NetBSD" -// OpenBSD -#elif defined(__OpenBSD__) -#define __FLASHROM_OS__ "OpenBSD" -// DJGPP -#elif defined(__DJGPP__) -#define __FLASHROM_OS__ "DOS" -// MinGW (always has _WIN32 available) -#elif defined(__MINGW32__) -#define __FLASHROM_OS__ "MinGW" -// Cygwin (usually without _WIN32) -#elif defined( __CYGWIN__) -#define __FLASHROM_OS__ "Cygwin" -// libpayload -#elif defined(__LIBPAYLOAD__) -#define __FLASHROM_OS__ "libpayload" -// GNU Hurd -#elif defined(__gnu_hurd__) -#define __FLASHROM_OS__ "Hurd" -// Linux -#elif defined(__linux__) - // There are various flags in use on Android apparently. __ANDROID__ seems to be the most trustworthy. - #if defined(__ANDROID__) - #define __FLASHROM_OS__ "Android" - #else - #define __FLASHROM_OS__ "Linux" - #endif -#endif -__FLASHROM_OS__ diff --git a/util/ich_descriptors_tool/Makefile b/util/ich_descriptors_tool/Makefile index 89624312..168220ca 100644 --- a/util/ich_descriptors_tool/Makefile +++ b/util/ich_descriptors_tool/Makefile @@ -4,6 +4,8 @@ # This Makefile works standalone, but it is usually called from the main # Makefile in the flashrom directory. +include ../../Makefile.include + PROGRAM=ich_descriptors_tool EXTRAINCDIRS = ../../ . DEPPATH = .dep @@ -32,8 +34,7 @@ EXEC_SUFFIX := .exe FLASHROM_CFLAGS += -D__USE_MINGW_ANSI_STDIO=1 endif -override TARGET_OS := $(shell $(CC) $(CPPFLAGS) -E $(SHAREDSRCDIR)/os.h | grep -v '^\#' | grep '"' | \ - cut -f 2 -d'"') +override TARGET_OS := $(call c_macro_test, ../../Makefile.d/os_test.h) ifeq ($(TARGET_OS), DOS) EXEC_SUFFIX := .exe -- cgit v1.2.3