xref: /OK3568_Linux_fs/u-boot/include/linux/kconfig.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun #ifndef __LINUX_KCONFIG_H
2*4882a593Smuzhiyun #define __LINUX_KCONFIG_H
3*4882a593Smuzhiyun 
4*4882a593Smuzhiyun #include <generated/autoconf.h>
5*4882a593Smuzhiyun 
6*4882a593Smuzhiyun /*
7*4882a593Smuzhiyun  * Helper macros to use CONFIG_ options in C/CPP expressions. Note that
8*4882a593Smuzhiyun  * these only work with boolean and tristate options.
9*4882a593Smuzhiyun  */
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun /*
12*4882a593Smuzhiyun  * Getting something that works in C and CPP for an arg that may or may
13*4882a593Smuzhiyun  * not be defined is tricky.  Here, if we have "#define CONFIG_BOOGER 1"
14*4882a593Smuzhiyun  * we match on the placeholder define, insert the "0," for arg1 and generate
15*4882a593Smuzhiyun  * the triplet (0, 1, 0).  Then the last step cherry picks the 2nd arg (a one).
16*4882a593Smuzhiyun  * When CONFIG_BOOGER is not defined, we generate a (... 1, 0) pair, and when
17*4882a593Smuzhiyun  * the last step cherry picks the 2nd arg, we get a zero.
18*4882a593Smuzhiyun  */
19*4882a593Smuzhiyun #define __ARG_PLACEHOLDER_1 0,
20*4882a593Smuzhiyun #define config_enabled(cfg) _config_enabled(cfg)
21*4882a593Smuzhiyun #define _config_enabled(value) __config_enabled(__ARG_PLACEHOLDER_##value)
22*4882a593Smuzhiyun #define __config_enabled(arg1_or_junk) ___config_enabled(arg1_or_junk 1, 0)
23*4882a593Smuzhiyun #define ___config_enabled(__ignored, val, ...) val
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun /*
26*4882a593Smuzhiyun  * IS_ENABLED(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y' or 'm',
27*4882a593Smuzhiyun  * 0 otherwise.
28*4882a593Smuzhiyun  *
29*4882a593Smuzhiyun  */
30*4882a593Smuzhiyun #define IS_ENABLED(option) \
31*4882a593Smuzhiyun 	(config_enabled(option) || config_enabled(option##_MODULE))
32*4882a593Smuzhiyun 
33*4882a593Smuzhiyun /*
34*4882a593Smuzhiyun  * IS_BUILTIN(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y', 0
35*4882a593Smuzhiyun  * otherwise. For boolean options, this is equivalent to
36*4882a593Smuzhiyun  * IS_ENABLED(CONFIG_FOO).
37*4882a593Smuzhiyun  */
38*4882a593Smuzhiyun #define IS_BUILTIN(option) config_enabled(option)
39*4882a593Smuzhiyun 
40*4882a593Smuzhiyun /*
41*4882a593Smuzhiyun  * IS_MODULE(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'm', 0
42*4882a593Smuzhiyun  * otherwise.
43*4882a593Smuzhiyun  */
44*4882a593Smuzhiyun #define IS_MODULE(option) config_enabled(option##_MODULE)
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun /*
47*4882a593Smuzhiyun  * U-Boot add-on: Helper macros to reference to different macros
48*4882a593Smuzhiyun  * (CONFIG_ or CONFIG_SPL_ prefixed), depending on the build context.
49*4882a593Smuzhiyun  */
50*4882a593Smuzhiyun #ifdef CONFIG_SPL_BUILD
51*4882a593Smuzhiyun #define _IS_SPL 1
52*4882a593Smuzhiyun #endif
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun #ifdef CONFIG_TPL_BUILD
55*4882a593Smuzhiyun #define _IS_TPL 1
56*4882a593Smuzhiyun #endif
57*4882a593Smuzhiyun 
58*4882a593Smuzhiyun #if defined(CONFIG_TPL_BUILD)
59*4882a593Smuzhiyun #define config_val(cfg) _config_val(_IS_TPL, cfg)
60*4882a593Smuzhiyun #define _config_val(x, cfg) __config_val(x, cfg)
61*4882a593Smuzhiyun #define __config_val(x, cfg) ___config_val(__ARG_PLACEHOLDER_##x, cfg)
62*4882a593Smuzhiyun #define ___config_val(arg1_or_junk, cfg)  \
63*4882a593Smuzhiyun 	____config_val(arg1_or_junk CONFIG_TPL_##cfg, CONFIG_##cfg)
64*4882a593Smuzhiyun #define ____config_val(__ignored, val, ...) val
65*4882a593Smuzhiyun #else
66*4882a593Smuzhiyun #define config_val(cfg) _config_val(_IS_SPL, cfg)
67*4882a593Smuzhiyun #define _config_val(x, cfg) __config_val(x, cfg)
68*4882a593Smuzhiyun #define __config_val(x, cfg) ___config_val(__ARG_PLACEHOLDER_##x, cfg)
69*4882a593Smuzhiyun #define ___config_val(arg1_or_junk, cfg)  \
70*4882a593Smuzhiyun 	____config_val(arg1_or_junk CONFIG_SPL_##cfg, CONFIG_##cfg)
71*4882a593Smuzhiyun #define ____config_val(__ignored, val, ...) val
72*4882a593Smuzhiyun #endif
73*4882a593Smuzhiyun 
74*4882a593Smuzhiyun /*
75*4882a593Smuzhiyun  * CONFIG_VAL(FOO) evaluates to the value of
76*4882a593Smuzhiyun  *  CONFIG_FOO if CONFIG_SPL_BUILD is undefined,
77*4882a593Smuzhiyun  *  CONFIG_SPL_FOO if CONFIG_SPL_BUILD is defined.
78*4882a593Smuzhiyun  */
79*4882a593Smuzhiyun #define CONFIG_VAL(option)  config_val(option)
80*4882a593Smuzhiyun 
81*4882a593Smuzhiyun /*
82*4882a593Smuzhiyun  * CONFIG_IS_ENABLED(FOO) evaluates to
83*4882a593Smuzhiyun  *  1 if CONFIG_SPL_BUILD is undefined and CONFIG_FOO is set to 'y' or 'm',
84*4882a593Smuzhiyun  *  1 if CONFIG_SPL_BUILD is defined and CONFIG_SPL_FOO is set to 'y' or 'm',
85*4882a593Smuzhiyun  *  0 otherwise.
86*4882a593Smuzhiyun  */
87*4882a593Smuzhiyun #define CONFIG_IS_ENABLED(option) \
88*4882a593Smuzhiyun 	(config_enabled(CONFIG_VAL(option)) ||		\
89*4882a593Smuzhiyun 	 config_enabled(CONFIG_VAL(option##_MODULE)))
90*4882a593Smuzhiyun 
91*4882a593Smuzhiyun /*
92*4882a593Smuzhiyun  * CONFIG_IS_BUILTIN(FOO) evaluates to
93*4882a593Smuzhiyun  *  1 if CONFIG_SPL_BUILD is undefined and CONFIG_FOO is set to 'y',
94*4882a593Smuzhiyun  *  1 if CONFIG_SPL_BUILD is defined and CONFIG_SPL_FOO is set to 'y',
95*4882a593Smuzhiyun  *  0 otherwise.
96*4882a593Smuzhiyun  */
97*4882a593Smuzhiyun #define CONFIG_IS_BUILTIN(option) config_enabled(CONFIG_VAL(option))
98*4882a593Smuzhiyun 
99*4882a593Smuzhiyun /*
100*4882a593Smuzhiyun  * CONFIG_IS_MODULE(FOO) evaluates to
101*4882a593Smuzhiyun  *  1 if CONFIG_SPL_BUILD is undefined and CONFIG_FOO is set to 'm',
102*4882a593Smuzhiyun  *  1 if CONFIG_SPL_BUILD is defined and CONFIG_SPL_FOO is set to 'm',
103*4882a593Smuzhiyun  *  0 otherwise.
104*4882a593Smuzhiyun  */
105*4882a593Smuzhiyun #define CONFIG_IS_MODULE(option) config_enabled(CONFIG_VAL(option##_MODULE))
106*4882a593Smuzhiyun 
107*4882a593Smuzhiyun #endif /* __LINUX_KCONFIG_H */
108