summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2022-01-22 15:07:26 +0300
committerTom Rini <trini@konsulko.com>2022-02-09 07:07:59 +0300
commit097ff01fb98a6f4ad03eed8cf639a5cc90fb6619 (patch)
treecef60abef94c9ae411f269317745943334b0876d /scripts
parent310bfa737f2cdf6bdcab7637b220a061d2807e99 (diff)
downloadu-boot-097ff01fb98a6f4ad03eed8cf639a5cc90fb6619.tar.xz
kconfig: Add support for conditional values
At present if an optional Kconfig value needs to be used it must be bracketed by #ifdef. For example, with this Kconfig setup: config WIBBLE bool "Support wibbles, the world needs more wibbles" config WIBBLE_ADDR hex "Address of the wibble" depends on WIBBLE then the following code must be used: #ifdef CONFIG_WIBBLE static void handle_wibble(void) { int val = CONFIG_WIBBLE_ADDR; ... } #endif static void init_machine() { ... #ifdef CONFIG_WIBBLE handle_wibble(); #endif } Add a new IF_ENABLED_INT() to help with this. So now it is possible to write, without #ifdefs: static void handle_wibble(void) { int val = IF_ENABLED_INT(CONFIG_WIBBLE, CONFIG_WIBBLE_ADDR); ... } static void init_machine() { ... if (IS_ENABLED(CONFIG_WIBBLE)) handle_wibble(); } The value will be CONFIG_WIBBLE_ADDR if CONFIG_WIBBLE is defined and will produce a build error if not.. This allows us to reduce the use of #ifdef in the code, ensuring that the compiler still checks the code even if it is not ultimately used for a particular build. Add a CONFIG_IF_ENABLED_INT() version as well. If an attempt is made to use a value that does not exist (i.e. when the conditional is not enabled), an error about a non-existing function is generated, e.g.: common/bloblist.c:447: undefined reference to `invalid_use_of_IF_ENABLED_INT' Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/Makefile.autoconf2
1 files changed, 1 insertions, 1 deletions
diff --git a/scripts/Makefile.autoconf b/scripts/Makefile.autoconf
index 5ed9abc8e1..0b3ffa08bf 100644
--- a/scripts/Makefile.autoconf
+++ b/scripts/Makefile.autoconf
@@ -68,7 +68,7 @@ quiet_cmd_u_boot_cfg = CFG $@
cmd_u_boot_cfg = \
$(CPP) $(c_flags) $2 -DDO_DEPS_ONLY -dM $(srctree)/include/common.h > $@.tmp && { \
grep 'define CONFIG_' $@.tmp | \
- sed '/define CONFIG_IS_ENABLED(/d;/define CONFIG_VAL(/d;' > $@; \
+ sed '/define CONFIG_IS_ENABLED(/d;/define CONFIG_IF_ENABLED_INT(/d;/define CONFIG_VAL(/d;' > $@; \
rm $@.tmp; \
} || { \
rm $@.tmp; false; \