[U-Boot] [RFC PATCH v2 01/15] Implement autoconf header file

Joe Hershberger joe.hershberger at gmail.com
Sun Feb 24 20:50:38 CET 2013


Hi Simon,

On Sun, Feb 24, 2013 at 11:25 AM, Simon Glass <sjg at chromium.org> wrote:
> 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
>
> you can do:
>
>         if (autoconf_version_variable())
>                 setenv("ver", version_string);  /* set version variable */

You are changing the meaning between these two examples.  The old code
was #ifDEF, which means the new example needs to be autoconf_HAS_*.
Is there a reason to muddy the waters by recommending people use this
automatic value of 0 instead of using the "has" function?  Any more
than without this patch we should go change most all the #ifdef to
#if?

> The compiler will ensure that the dead code is eliminated, so the result
> is the same.
>
> Where the value of the CONFIG define is 0, you can use the autoconf_has...()
> form. For example CONFIG_BOOTDELAY can be -ve, 0 or +ve, but if it is
> defined at all, it affects behaviour:
>
>  #if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0)
>         s = getenv ("bootdelay");
>  #endif
>
> So we use:
>
>         if (autoconf_has_bootdelay() && autoconf_bootdelay() >= 0)
>                 s = getenv ("bootdelay");
>
> This later form should only be used for such 'difficult' defines where a
> zero value still means that the CONFIG should be considered to be defined.
>
> Signed-off-by: Simon Glass <sjg at chromium.org>
> ---
> Changes in v2:
> - Split out changes to main.c into separate patches
> - Fix up a few errors and comments in the original RFC
> - Use autoconf_...() instead of config_...()
> - Use autoconf_has_...() instead of config_..._enabled()
> - Add a grep to the sed/sort pipe to speed up processing
>
>  Makefile                      | 42 ++++++++++++++++++++-
>  README                        | 87 +++++++++++++++++++++++++++++++++++++++++--
>  include/common.h              |  3 ++
>  include/config_drop.h         | 17 +++++++++
>  tools/scripts/define2conf.sed | 37 ++++++++++++++++++
>  tools/scripts/define2list.sed | 31 +++++++++++++++
>  6 files changed, 213 insertions(+), 4 deletions(-)
>  create mode 100644 include/config_drop.h
>  create mode 100644 tools/scripts/define2conf.sed
>  create mode 100644 tools/scripts/define2list.sed
>
> diff --git a/Makefile b/Makefile
> index fc18dd4..9f4f55d 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -614,6 +614,7 @@ updater:
>  # parallel sub-makes creating .depend files simultaneously.
>  depend dep:    $(TIMESTAMP_FILE) $(VERSION_FILE) \
>                 $(obj)include/autoconf.mk \
> +               $(obj)include/generated/autoconf.h \
>                 $(obj)include/generated/generic-asm-offsets.h \
>                 $(obj)include/generated/asm-offsets.h
>                 for dir in $(SUBDIRS) $(CPUDIR) $(LDSCRIPT_MAKEFILE_DIR) ; do \
> @@ -688,6 +689,44 @@ $(obj)include/autoconf.mk: $(obj)include/config.h
>                 sed -n -f tools/scripts/define2mk.sed > $@.tmp && \
>         mv $@.tmp $@
>
> +# Create a C header file where every '#define CONFIG_XXX value' becomes
> +# '#define config_xxx() value', or '#define config_xxx() 0' where the CONFIG
> +# is not used by this board configuration. This allows C code to do things
> +# like 'if (config_xxx())' and have the compiler remove the dead code,
> +# instead of using '#ifdef CONFIG_XXX...#endif'. Note that in most cases
> +# if the config_...() returns 0 then the option is not enabled. In some rare
> +# cases such as CONFIG_BOOTDELAY, the config can be enabled but still have a
> +# a value of 0. So in addition we a #define config_xxx_enabled(), setting the

You forgot to update this comment when changing to autoconf_has.  Grep perhaps?

> +# value to 0 if the option is disabled, 1 if enabled. This last feature will
> +# hopefully be deprecated soon.
> +# 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/define2conf.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/define2list.sed \
> +               ) | sort | uniq > $@-all.tmp; \
> +       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/define2list.sed | sort > $@-enabled.tmp; \



More information about the U-Boot mailing list