xref: /OK3568_Linux_fs/kernel/include/linux/kconfig.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun #ifndef __LINUX_KCONFIG_H
3*4882a593Smuzhiyun #define __LINUX_KCONFIG_H
4*4882a593Smuzhiyun 
5*4882a593Smuzhiyun /* CONFIG_CC_VERSION_TEXT (Do not delete this comment. See help in Kconfig) */
6*4882a593Smuzhiyun 
7*4882a593Smuzhiyun #include <generated/autoconf.h>
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #ifdef CONFIG_CPU_BIG_ENDIAN
10*4882a593Smuzhiyun #define __BIG_ENDIAN 4321
11*4882a593Smuzhiyun #else
12*4882a593Smuzhiyun #define __LITTLE_ENDIAN 1234
13*4882a593Smuzhiyun #endif
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun #define __ARG_PLACEHOLDER_1 0,
16*4882a593Smuzhiyun #define __take_second_arg(__ignored, val, ...) val
17*4882a593Smuzhiyun 
18*4882a593Smuzhiyun /*
19*4882a593Smuzhiyun  * The use of "&&" / "||" is limited in certain expressions.
20*4882a593Smuzhiyun  * The following enable to calculate "and" / "or" with macro expansion only.
21*4882a593Smuzhiyun  */
22*4882a593Smuzhiyun #define __and(x, y)			___and(x, y)
23*4882a593Smuzhiyun #define ___and(x, y)			____and(__ARG_PLACEHOLDER_##x, y)
24*4882a593Smuzhiyun #define ____and(arg1_or_junk, y)	__take_second_arg(arg1_or_junk y, 0)
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun #define __or(x, y)			___or(x, y)
27*4882a593Smuzhiyun #define ___or(x, y)			____or(__ARG_PLACEHOLDER_##x, y)
28*4882a593Smuzhiyun #define ____or(arg1_or_junk, y)		__take_second_arg(arg1_or_junk 1, y)
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun /*
31*4882a593Smuzhiyun  * Helper macros to use CONFIG_ options in C/CPP expressions. Note that
32*4882a593Smuzhiyun  * these only work with boolean and tristate options.
33*4882a593Smuzhiyun  */
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun /*
36*4882a593Smuzhiyun  * Getting something that works in C and CPP for an arg that may or may
37*4882a593Smuzhiyun  * not be defined is tricky.  Here, if we have "#define CONFIG_BOOGER 1"
38*4882a593Smuzhiyun  * we match on the placeholder define, insert the "0," for arg1 and generate
39*4882a593Smuzhiyun  * the triplet (0, 1, 0).  Then the last step cherry picks the 2nd arg (a one).
40*4882a593Smuzhiyun  * When CONFIG_BOOGER is not defined, we generate a (... 1, 0) pair, and when
41*4882a593Smuzhiyun  * the last step cherry picks the 2nd arg, we get a zero.
42*4882a593Smuzhiyun  */
43*4882a593Smuzhiyun #define __is_defined(x)			___is_defined(x)
44*4882a593Smuzhiyun #define ___is_defined(val)		____is_defined(__ARG_PLACEHOLDER_##val)
45*4882a593Smuzhiyun #define ____is_defined(arg1_or_junk)	__take_second_arg(arg1_or_junk 1, 0)
46*4882a593Smuzhiyun 
47*4882a593Smuzhiyun /*
48*4882a593Smuzhiyun  * IS_BUILTIN(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y', 0
49*4882a593Smuzhiyun  * otherwise. For boolean options, this is equivalent to
50*4882a593Smuzhiyun  * IS_ENABLED(CONFIG_FOO).
51*4882a593Smuzhiyun  */
52*4882a593Smuzhiyun #define IS_BUILTIN(option) __is_defined(option)
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun /*
55*4882a593Smuzhiyun  * IS_MODULE(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'm', 0
56*4882a593Smuzhiyun  * otherwise.
57*4882a593Smuzhiyun  */
58*4882a593Smuzhiyun #define IS_MODULE(option) __is_defined(option##_MODULE)
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun /*
61*4882a593Smuzhiyun  * IS_REACHABLE(CONFIG_FOO) evaluates to 1 if the currently compiled
62*4882a593Smuzhiyun  * code can call a function defined in code compiled based on CONFIG_FOO.
63*4882a593Smuzhiyun  * This is similar to IS_ENABLED(), but returns false when invoked from
64*4882a593Smuzhiyun  * built-in code when CONFIG_FOO is set to 'm'.
65*4882a593Smuzhiyun  */
66*4882a593Smuzhiyun #define IS_REACHABLE(option) __or(IS_BUILTIN(option), \
67*4882a593Smuzhiyun 				__and(IS_MODULE(option), __is_defined(MODULE)))
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun /*
70*4882a593Smuzhiyun  * IS_ENABLED(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y' or 'm',
71*4882a593Smuzhiyun  * 0 otherwise.
72*4882a593Smuzhiyun  */
73*4882a593Smuzhiyun #define IS_ENABLED(option) __or(IS_BUILTIN(option), IS_MODULE(option))
74*4882a593Smuzhiyun 
75*4882a593Smuzhiyun #endif /* __LINUX_KCONFIG_H */
76