Back to home page

OSCL-LXR

 
 

    


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