]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
[BUILD] Generate include/autoconf.mk from board config files
authorGrant Likely <grant.likely@secretlab.ca>
Mon, 24 Sep 2007 15:05:31 +0000 (09:05 -0600)
committerGrant Likely <grant.likely@secretlab.ca>
Wed, 21 Nov 2007 05:33:38 +0000 (22:33 -0700)
Use cpp and sed to postprocess config.h and import the defined values
into include/autoconf.mk.  autoconf.mk is then included by config.mk to
give 'make' access to the board configuration.

Doing this enables conditional compilation at the Makefile level instead
of by wrapping every .c file with #ifdef/#endif wrappers.

Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Makefile
config.mk
tools/scripts/define2mk.sed [new file with mode: 0644]

index ac4b430d75988fc22f96771590ebc7694dd8a1a3..407b9387002ea427370961f27c3b0a5f96912c38 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -342,6 +342,21 @@ $(obj)System.map:  $(obj)u-boot
                grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | \
                sort > $(obj)System.map
 
+#
+# Auto-generate the autoconf.mk file (which is included by all makefiles)
+#
+# This target actually generates 2 files; autoconf.mk and autoconf.mk.dep.
+# the dep file is only include in this top level makefile to determine when
+# to regenerate the autoconf.mk file.
+$(OBJTREE)/include/autoconf.mk: $(obj)include/config.h
+       @echo Generating include/autoconf.mk
+       @# Generate the dependancies
+       @$(CC) -M $(HOST_CFLAGS) $(CPPFLAGS) -MQ $@ include/common.h > $@.dep
+       @# Extract the config macros
+       @$(CPP) $(CFLAGS) -dM include/common.h | sed -n -f tools/scripts/define2mk.sed >> $@
+
+sinclude $(OBJTREE)/include/autoconf.mk.dep
+
 #########################################################################
 else
 all $(obj)u-boot.hex $(obj)u-boot.srec $(obj)u-boot.bin \
@@ -361,7 +376,8 @@ CHANGELOG:
 
 unconfig:
        @rm -f $(obj)include/config.h $(obj)include/config.mk \
-               $(obj)board/*/config.tmp $(obj)board/*/*/config.tmp
+               $(obj)board/*/config.tmp $(obj)board/*/*/config.tmp \
+               $(obj)include/autoconf.mk $(obj)include/autoconf.mk.dep
 
 #========================================================================
 # PowerPC
index 37d61a0c86844df7e124515b3d63d94a88ebc1ae..79e5a31b72a6599f027eb0b45df9f95e526b563b 100644 (file)
--- a/config.mk
+++ b/config.mk
@@ -87,6 +87,9 @@ ifdef BOARD
 sinclude $(TOPDIR)/board/$(BOARDDIR)/config.mk # include board specific rules
 endif
 
+# Load generated board configuration
+sinclude $(OBJTREE)/include/autoconf.mk
+
 #########################################################################
 
 CONFIG_SHELL   := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
diff --git a/tools/scripts/define2mk.sed b/tools/scripts/define2mk.sed
new file mode 100644 (file)
index 0000000..6464627
--- /dev/null
@@ -0,0 +1,29 @@
+#
+# Sed script to parse CPP macros and generate output usable by make
+#
+# It is expected that this script is fed the output of 'gpp -dM'
+# which preprocesses the common.h header files and outputs the final
+# list of CPP macros (and whitespace is sanitized)
+#
+
+# Only process values prefixed with #define CONFIG_
+/^#define CONFIG_[A-Za-z0-9_]\+/ {
+       # Strip the #define prefix
+       s/#define *//;
+       # Change to form CONFIG_*=VALUE
+       s/ \+/=/;
+       # Drop trailing spaces
+       s/ *$//;
+       # drop quotes around string values
+       s/="\(.*\)"$/=\1/;
+       # Concatenate string values
+       s/" *"//g;
+       # Wrap non-numeral values with quotes
+       s/=\(.*\?[^0-9].*\)$/=\"\1\"/;
+       # Change '1' and empty values to "y" (not perfect, but
+       # supports conditional compilation in the makefiles
+       s/=$/=y/;
+       s/=1$/=y/;
+       # print the line
+       p
+}