
Hi Rasmus,
On Fri, 12 Jun 2020 at 05:02, Rasmus Villemoes rasmus.villemoes@prevas.dk wrote:
This adds a bunch of preprocessor magic to extend the capabilities of CONFIG_IS_ENABLED. The existing semantics of
CONFIG_IS_ENABLED(FOO)
expanding to a 1 or 0 (depending on build context and the defined-ness or not of the appropriate CONFIG_FOO/CONFIG_SPL_FOO/CONFIG_TPL_FOO) are of course preserved. With this, one is also allowed a two-argument form
CONFIG_IS_ENABLED(FOO, (something))
which expands to something precisely when CONFIG_IS_ENABLED(FOO) would expand to 1, and expands to nothing otherwise. It is, in other words, completely equivalent to the three lines
#if CONFIG_IS_ENABLED(FOO) something #endif
The second argument must be parenthesized in order to allow any tokens, including a trailing comma, to appear - one use case for this is precisely to make it a bit more ergonomic to build an array and only include certain items depending on .config. That should increase both readability and not least "git grep"ability.
A third variant is also introduced,
CONFIG_IS_ENABLED(FOO, (xxx), (yyy))
which corresponds to
#if CONFIG_IS_ENABLED(FOO) xxx #else yyy #endif
Signed-off-by: Rasmus Villemoes rasmus.villemoes@prevas.dk
include/linux/kconfig.h | 48 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org
See also this:
http://patchwork.ozlabs.org/project/uboot/patch/20200522020223.230834-2-sjg@...
but I think your idea is a lot nicer.
Regards, Simon