From c801cb29d64764fa8082ec2ab17dd12f74b3143f Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Tue, 19 Aug 2014 16:17:25 +0100 Subject: [PATCH] [build] Allow for named configurations at build time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allow named configurations to be specified via the CONFIG=... build parameter. For headers in config/*.h which support named configurations, the following files will be included when building with CONFIG=: - config/defaults/.h (e.g. config/defaults/pcbios.h) - config/
.h - config//
.h (only if the directory config/ exists) - config/local/
.h (autocreated if necessary) - config/local//
.h (autocreated if necessary) This mechanism allows for predefined named configurations to be checked in to the source tree, as a directory config/ containing all of the required header files. The mechanism also allows for users to define multiple local configurations, by creating header files in the directory config/local/. Note that the config/*.h files which are used only to configure internal iPXE APIs (e.g. config/ioapi.h) cannot be modified via a named configuration. This avoids rebuilding the entire iPXE codebase whenever switching to a different named configuration. Inspired-by: Robin Smidsrød Tested-by: Robin Smidsrød Signed-off-by: Michael Brown --- src/Makefile.housekeeping | 40 +++++++++++++++++++++++++++++++++++++-- src/config/colour.h | 3 +++ src/config/console.h | 3 +++ src/config/crypto.h | 3 +++ src/config/general.h | 3 +++ src/config/named.h | 26 +++++++++++++++++++++++++ src/config/serial.h | 3 +++ src/config/settings.h | 3 +++ src/config/sideband.h | 3 +++ 9 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 src/config/named.h diff --git a/src/Makefile.housekeeping b/src/Makefile.housekeeping index 0dce8d06f..b07a8d967 100644 --- a/src/Makefile.housekeeping +++ b/src/Makefile.housekeeping @@ -689,6 +689,34 @@ privkey_DEPS += $(PRIVKEY_LIST) CFLAGS_privkey += $(if $(PRIVKEY),-DPRIVATE_KEY="\"$(PRIVKEY_INC)\"") +# (Single-element) list of named configurations +# +CONFIG_LIST := $(BIN)/.config.list +ifeq ($(wildcard $(CONFIG_LIST)),) +CONFIG_OLD := +else +CONFIG_OLD := $(shell cat $(CONFIG_LIST)) +endif +ifneq ($(CONFIG_OLD),$(CONFIG)) +$(shell $(ECHO) "$(CONFIG)" > $(CONFIG_LIST)) +endif + +$(CONFIG_LIST) : $(MAKEDEPS) + +VERYCLEANUP += $(CONFIG_LIST) + +# Named configurations +# +ifneq ($(CONFIG),) +ifneq ($(wildcard config/$(CONFIG)),) +CFLAGS += -DCONFIG=$(CONFIG) +endif +CFLAGS += -DLOCAL_CONFIG=$(CONFIG) +endif + +config/named.h : $(CONFIG_LIST) + $(Q)$(TOUCH) $@ + # These files use .incbin inline assembly to include a binary file. # Unfortunately ccache does not detect this dependency and caches # builds even when the binary file has changed. @@ -1260,8 +1288,16 @@ CLEANUP += $(EINFO) # # Local configs # -config/local/%.h : - $(Q)touch $@ +CONFIG_HEADERS := $(patsubst config/%,%,$(wildcard config/*.h)) + +$(foreach HEADER,$(CONFIG_HEADERS),config/local/$(HEADER)) : + $(Q)$(TOUCH) $@ + +ifneq ($(CONFIG),) +$(foreach HEADER,$(CONFIG_HEADERS),config/local/$(CONFIG)/$(HEADER)) : + $(Q)$(MKDIR) -p $(dir $@) + $(Q)$(TOUCH) $@ +endif ############################################################################### # diff --git a/src/config/colour.h b/src/config/colour.h index c75f65e6d..57d20c1db 100644 --- a/src/config/colour.h +++ b/src/config/colour.h @@ -30,6 +30,9 @@ FILE_LICENCE ( GPL2_OR_LATER ); #define COLOR_PXE_FG COLOR_BLACK #define COLOR_PXE_BG COLOR_WHITE +#include +#include NAMED_CONFIG(colour.h) #include +#include LOCAL_NAMED_CONFIG(colour.h) #endif /* CONFIG_COLOUR_H */ diff --git a/src/config/console.h b/src/config/console.h index 5d2cc1dce..908ec5a0b 100644 --- a/src/config/console.h +++ b/src/config/console.h @@ -28,6 +28,9 @@ FILE_LICENCE ( GPL2_OR_LATER ); #define LOG_LEVEL LOG_NONE +#include +#include NAMED_CONFIG(console.h) #include +#include LOCAL_NAMED_CONFIG(console.h) #endif /* CONFIG_CONSOLE_H */ diff --git a/src/config/crypto.h b/src/config/crypto.h index 95c73d477..1e021b0fb 100644 --- a/src/config/crypto.h +++ b/src/config/crypto.h @@ -17,6 +17,9 @@ FILE_LICENCE ( GPL2_OR_LATER ); */ #define TIMESTAMP_ERROR_MARGIN ( ( 12 * 60 + 30 ) * 60 ) +#include +#include NAMED_CONFIG(crypto.h) #include +#include LOCAL_NAMED_CONFIG(crypto.h) #endif /* CONFIG_CRYPTO_H */ diff --git a/src/config/general.h b/src/config/general.h index 72cfc3b86..539203457 100644 --- a/src/config/general.h +++ b/src/config/general.h @@ -182,6 +182,9 @@ FILE_LICENCE ( GPL2_OR_LATER ); #undef GDBUDP /* Remote GDB debugging over UDP * (both may be set) */ +#include +#include NAMED_CONFIG(general.h) #include +#include LOCAL_NAMED_CONFIG(general.h) #endif /* CONFIG_GENERAL_H */ diff --git a/src/config/named.h b/src/config/named.h new file mode 100644 index 000000000..36efdabdd --- /dev/null +++ b/src/config/named.h @@ -0,0 +1,26 @@ +#ifndef CONFIG_NAMED_H +#define CONFIG_NAMED_H + +/** @file + * + * Named configurations + * + */ + +FILE_LICENCE ( GPL2_OR_LATER ); + +/* config//
.h */ +#ifdef CONFIG +#define NAMED_CONFIG(_header) +#else +#define NAMED_CONFIG(_header) +#endif + +/* config/local//
.h */ +#ifdef LOCAL_CONFIG +#define LOCAL_NAMED_CONFIG(_header) +#else +#define LOCAL_NAMED_CONFIG(_header) +#endif + +#endif /* CONFIG_NAMED_H */ diff --git a/src/config/serial.h b/src/config/serial.h index 8bb9311f1..08368efdb 100644 --- a/src/config/serial.h +++ b/src/config/serial.h @@ -32,6 +32,9 @@ FILE_LICENCE ( GPL2_OR_LATER ); #define COMSTOP 1 /* Stop bits */ #endif +#include +#include NAMED_CONFIG(serial.h) #include +#include LOCAL_NAMED_CONFIG(serial.h) #endif /* CONFIG_SERIAL_H */ diff --git a/src/config/settings.h b/src/config/settings.h index b06f2901b..42fe9cc81 100644 --- a/src/config/settings.h +++ b/src/config/settings.h @@ -14,6 +14,9 @@ FILE_LICENCE ( GPL2_OR_LATER ); //#define MEMMAP_SETTINGS /* Memory map settings */ //#define VMWARE_SETTINGS /* VMware GuestInfo settings */ +#include +#include NAMED_CONFIG(settings.h) #include +#include LOCAL_NAMED_CONFIG(settings.h) #endif /* CONFIG_SETTINGS_H */ diff --git a/src/config/sideband.h b/src/config/sideband.h index 2e2a8d419..039bb5d09 100644 --- a/src/config/sideband.h +++ b/src/config/sideband.h @@ -11,6 +11,9 @@ FILE_LICENCE ( GPL2_OR_LATER ); //#define CONFIG_BOFM /* IBM's BladeCenter Open Fabric Manager */ +#include +#include NAMED_CONFIG(sideband.h) #include +#include LOCAL_NAMED_CONFIG(sideband.h) #endif /* CONFIG_SIDEBAND_H */