diff mbox series

[v2,1/8] linux/kconfig.h: simplify logic for choosing CONFIG_{SPL_, TPL_, }*

Message ID 20200703163711.1658000-1-sjg@chromium.org
State Accepted
Delegated to: Bin Meng
Headers show
Series [v2,1/8] linux/kconfig.h: simplify logic for choosing CONFIG_{SPL_, TPL_, }* | expand

Commit Message

Simon Glass July 3, 2020, 4:37 p.m. UTC
From: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

Instead of using the arg1_or_junk trick to pick between two choices,
with a bit of duplication between the branches (and most of the
CONFIG_TPL_BUILD case being redundant, as _IS_TPL is known to be
defined to 1 in that case), simply define a prefix that we inject
between CONFIG_ and the given config symbol.

This only requires one level of indirection (to get the
_CONFIG_PREFIX macro expanded before the token concatenation takes
place), and makes it easy to, say, introduce a CONFIG_HOSTTOOL_
prefix. [I would expect most HOSTTOOL_ symbols to just be def_bool y,
but it would allow us to clean up some of the ifdef HOSTCC mess in the
sources shared between U-Boot and host tools.]

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
---

(no changes since v1)

 include/linux/kconfig.h | 27 ++++++++-------------------
 1 file changed, 8 insertions(+), 19 deletions(-)

Comments

Bin Meng July 7, 2020, 7:17 a.m. UTC | #1
On Sat, Jul 4, 2020 at 12:37 AM Simon Glass <sjg@chromium.org> wrote:
>
> From: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
>
> Instead of using the arg1_or_junk trick to pick between two choices,
> with a bit of duplication between the branches (and most of the
> CONFIG_TPL_BUILD case being redundant, as _IS_TPL is known to be
> defined to 1 in that case), simply define a prefix that we inject
> between CONFIG_ and the given config symbol.
>
> This only requires one level of indirection (to get the
> _CONFIG_PREFIX macro expanded before the token concatenation takes
> place), and makes it easy to, say, introduce a CONFIG_HOSTTOOL_
> prefix. [I would expect most HOSTTOOL_ symbols to just be def_bool y,
> but it would allow us to clean up some of the ifdef HOSTCC mess in the
> sources shared between U-Boot and host tools.]
>
> Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
> Reviewed-by: Simon Glass <sjg@chromium.org>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
> (no changes since v1)
>
>  include/linux/kconfig.h | 27 ++++++++-------------------
>  1 file changed, 8 insertions(+), 19 deletions(-)
>

applied to u-boot-x86, thanks!
diff mbox series

Patch

diff --git a/include/linux/kconfig.h b/include/linux/kconfig.h
index 3a2da738c4..56b8e5d787 100644
--- a/include/linux/kconfig.h
+++ b/include/linux/kconfig.h
@@ -47,30 +47,19 @@ 
  * U-Boot add-on: Helper macros to reference to different macros
  * (CONFIG_ or CONFIG_SPL_ prefixed), depending on the build context.
  */
-#ifdef CONFIG_SPL_BUILD
-#define _IS_SPL 1
-#endif
-
-#ifdef CONFIG_TPL_BUILD
-#define _IS_TPL 1
-#endif
 
 #if defined(CONFIG_TPL_BUILD)
-#define config_val(cfg) _config_val(_IS_TPL, cfg)
-#define _config_val(x, cfg) __config_val(x, cfg)
-#define __config_val(x, cfg) ___config_val(__ARG_PLACEHOLDER_##x, cfg)
-#define ___config_val(arg1_or_junk, cfg)  \
-	____config_val(arg1_or_junk CONFIG_TPL_##cfg, CONFIG_##cfg)
-#define ____config_val(__ignored, val, ...) val
+#define _CONFIG_PREFIX TPL_
+#elif defined(CONFIG_SPL_BUILD)
+#define _CONFIG_PREFIX SPL_
 #else
-#define config_val(cfg) _config_val(_IS_SPL, cfg)
-#define _config_val(x, cfg) __config_val(x, cfg)
-#define __config_val(x, cfg) ___config_val(__ARG_PLACEHOLDER_##x, cfg)
-#define ___config_val(arg1_or_junk, cfg)  \
-	____config_val(arg1_or_junk CONFIG_SPL_##cfg, CONFIG_##cfg)
-#define ____config_val(__ignored, val, ...) val
+#define _CONFIG_PREFIX
 #endif
 
+#define   config_val(cfg)       _config_val(_CONFIG_PREFIX, cfg)
+#define  _config_val(pfx, cfg) __config_val(pfx, cfg)
+#define __config_val(pfx, cfg) CONFIG_ ## pfx ## cfg
+
 /*
  * CONFIG_VAL(FOO) evaluates to the value of
  *  CONFIG_FOO if CONFIG_SPL_BUILD is undefined,