Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef __LINUX_KCONFIG_H
0003 #define __LINUX_KCONFIG_H
0004 
0005 #include <generated/autoconf.h>
0006 
0007 #ifdef CONFIG_CPU_BIG_ENDIAN
0008 #define __BIG_ENDIAN 4321
0009 #else
0010 #define __LITTLE_ENDIAN 1234
0011 #endif
0012 
0013 #define __ARG_PLACEHOLDER_1 0,
0014 #define __take_second_arg(__ignored, val, ...) val
0015 
0016 /*
0017  * The use of "&&" / "||" is limited in certain expressions.
0018  * The following enable to calculate "and" / "or" with macro expansion only.
0019  */
0020 #define __and(x, y)         ___and(x, y)
0021 #define ___and(x, y)            ____and(__ARG_PLACEHOLDER_##x, y)
0022 #define ____and(arg1_or_junk, y)    __take_second_arg(arg1_or_junk y, 0)
0023 
0024 #define __or(x, y)          ___or(x, y)
0025 #define ___or(x, y)         ____or(__ARG_PLACEHOLDER_##x, y)
0026 #define ____or(arg1_or_junk, y)     __take_second_arg(arg1_or_junk 1, y)
0027 
0028 /*
0029  * Helper macros to use CONFIG_ options in C/CPP expressions. Note that
0030  * these only work with boolean and tristate options.
0031  */
0032 
0033 /*
0034  * Getting something that works in C and CPP for an arg that may or may
0035  * not be defined is tricky.  Here, if we have "#define CONFIG_BOOGER 1"
0036  * we match on the placeholder define, insert the "0," for arg1 and generate
0037  * the triplet (0, 1, 0).  Then the last step cherry picks the 2nd arg (a one).
0038  * When CONFIG_BOOGER is not defined, we generate a (... 1, 0) pair, and when
0039  * the last step cherry picks the 2nd arg, we get a zero.
0040  */
0041 #define __is_defined(x)         ___is_defined(x)
0042 #define ___is_defined(val)      ____is_defined(__ARG_PLACEHOLDER_##val)
0043 #define ____is_defined(arg1_or_junk)    __take_second_arg(arg1_or_junk 1, 0)
0044 
0045 /*
0046  * IS_BUILTIN(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y', 0
0047  * otherwise. For boolean options, this is equivalent to
0048  * IS_ENABLED(CONFIG_FOO).
0049  */
0050 #define IS_BUILTIN(option) __is_defined(option)
0051 
0052 /*
0053  * IS_MODULE(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'm', 0
0054  * otherwise.  CONFIG_FOO=m results in "#define CONFIG_FOO_MODULE 1" in
0055  * autoconf.h.
0056  */
0057 #define IS_MODULE(option) __is_defined(option##_MODULE)
0058 
0059 /*
0060  * IS_REACHABLE(CONFIG_FOO) evaluates to 1 if the currently compiled
0061  * code can call a function defined in code compiled based on CONFIG_FOO.
0062  * This is similar to IS_ENABLED(), but returns false when invoked from
0063  * built-in code when CONFIG_FOO is set to 'm'.
0064  */
0065 #define IS_REACHABLE(option) __or(IS_BUILTIN(option), \
0066                 __and(IS_MODULE(option), __is_defined(MODULE)))
0067 
0068 /*
0069  * IS_ENABLED(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y' or 'm',
0070  * 0 otherwise.  Note that CONFIG_FOO=y results in "#define CONFIG_FOO 1" in
0071  * autoconf.h, while CONFIG_FOO=m results in "#define CONFIG_FOO_MODULE 1".
0072  */
0073 #define IS_ENABLED(option) __or(IS_BUILTIN(option), IS_MODULE(option))
0074 
0075 #endif /* __LINUX_KCONFIG_H */