[U-Boot] [PATCH v4 1/8] Implement autoconf header file
Marek Vasut
marex at denx.de
Sun Nov 10 20:47:17 CET 2013
Dear Simon Glass,
> Add support for generating an autoconf.h header file that can be used in
> the source instead of #ifdef.
>
> For example, instead of:
>
> #ifdef CONFIG_VERSION_VARIABLE
> setenv("ver", version_string); /* set version variable */
> #endif
I hope this has nothing to do with autoconf(1) .
[...]
> +# The file is regenerated when any U-Boot header file changes.
> +$(obj)include/generated/autoconf.h: $(obj)include/config.h
> + @$(XECHO) Generating $@ ; \
> + set -e ; \
> + : Extract the config macros to a C header file ; \
> + $(CPP) $(CFLAGS) -DDO_DEPS_ONLY -dM include/common.h | \
> + sed -n -f tools/scripts/define2value.sed > $@.tmp; \
> + : Regenerate our list of all config macros if neeed ; \
> + if [ ! -f $@-all.tmp ] || \
> + find $(src) -name '*.h' -type f -newer $@-all.tmp | \
> + egrep -qv 'include/(autoconf.h|generated|config.h)'; \
> + then \
> + : Extract all config macros from all C header files ; \
> + : We can grep for CONFIG since the value will be dropped ; \
> + ( \
> + find ${src} -name "*.h" -type f | xargs \
> + cat | grep CONFIG | \
> + sed -n -f tools/scripts/define2zero.sed \
Won't "find ... -exec grep CONFIG \; | sed ..." work here and drop some extra
overhead ?
> + ) | sort | uniq > $@-all.tmp; \
"sort -u" maybe ?
> + fi; \
> + : Extract the enabled config macros to a C header file ; \
> + $(CPP) $(CFLAGS) -DDO_DEPS_ONLY -dM include/common.h | \
> + sed -n -f tools/scripts/define2zero.sed | \
> + sort > $@-enabled.tmp; \
> + set -e ; \
> + : Find CONFIGs that are not enabled ; \
> + comm -13 $@-enabled.tmp $@-all.tmp >>$@.tmp && \
> + mv $@.tmp $@
[...]
> diff --git a/tools/scripts/define2value.sed
> b/tools/scripts/define2value.sed new file mode 100644
> index 0000000..205f9fe
> --- /dev/null
> +++ b/tools/scripts/define2value.sed
> @@ -0,0 +1,37 @@
> +#
> +# Sed script to parse CPP macros and generate a list of CONFIG macros
> +#
> +# This converts:
> +# #define CONFIG_XXX value
> +#into:
> +# #define autoconf_xxx() value
> +# #define autoconf_has_xxx() 1
> +
> +# Macros with parameters are ignored.
> +# (Note we avoid + since it doesn't appear to work)
> +/^#define CONFIG_[A-Za-z0-9_][A-Za-z0-9_]*(/ {
> + d
> +}
> +
> +# Only process values prefixed with #define CONFIG_
> +/^#define CONFIG_[A-Za-z0-9_][A-Za-z0-9_]*/ {
You might want to adjust it this way:
/^[[:blank:]]\+#define[[:blank:]]\+[[:alnum:]_]\+/
This will pick "#define"s prefixed and suffixed with arbitrary amount of
whitespace.
> + # Strip the #define prefix
> + s/#define[ \t]*CONFIG_/autoconf_/;
This will pick #defineCONFIG . Maybe "#define[[:blank:]]\+"
> + # Change to form CONFIG_*=VALUE
> + s/[\t ][\t ]*/=/;
> + # Handle lines with no value
> + s/^\([^=]*\)$/\1=/;
I wonder, how will this handle lines like:
include/configs/yucca.h:#define CONFIG_SYS_FLASH_WORD_SIZE unsigned char
or
include/configs/at91sam9m10g45ek.h:#define CONFIG_SYS_PROMPT "U-Boot>
"
or
#define CONFIG_FOO \
value_is_bar \
another_value_quux
?
> + # Drop trailing spaces
> + s/ *$//;
> + # Change empty values to '1'
> + s/=$/=1/;
> + # Add #define at the start
> + s/^\([^=]*\)=/#define \L\1() /
> + # print the line
> + p
> + # Create autoconf_has_...(), value 1
> + s/().*/() 1/
> + s/\(autoconf_\)/\1has_/
> + # print the line
> + p
> +}
I'm tempted to rework this as a one-liner, but please stop me if you consider
that worthless.
[...]
More information about the U-Boot
mailing list