xref: /openbmc/linux/tools/include/tools/config.h (revision 6b416ebc)
16b416ebcSJiri Olsa /* SPDX-License-Identifier: GPL-2.0 */
26b416ebcSJiri Olsa #ifndef _TOOLS_CONFIG_H
36b416ebcSJiri Olsa #define _TOOLS_CONFIG_H
46b416ebcSJiri Olsa 
56b416ebcSJiri Olsa /* Subset of include/linux/kconfig.h */
66b416ebcSJiri Olsa 
76b416ebcSJiri Olsa #define __ARG_PLACEHOLDER_1 0,
86b416ebcSJiri Olsa #define __take_second_arg(__ignored, val, ...) val
96b416ebcSJiri Olsa 
106b416ebcSJiri Olsa /*
116b416ebcSJiri Olsa  * Helper macros to use CONFIG_ options in C/CPP expressions. Note that
126b416ebcSJiri Olsa  * these only work with boolean and tristate options.
136b416ebcSJiri Olsa  */
146b416ebcSJiri Olsa 
156b416ebcSJiri Olsa /*
166b416ebcSJiri Olsa  * Getting something that works in C and CPP for an arg that may or may
176b416ebcSJiri Olsa  * not be defined is tricky.  Here, if we have "#define CONFIG_BOOGER 1"
186b416ebcSJiri Olsa  * we match on the placeholder define, insert the "0," for arg1 and generate
196b416ebcSJiri Olsa  * the triplet (0, 1, 0).  Then the last step cherry picks the 2nd arg (a one).
206b416ebcSJiri Olsa  * When CONFIG_BOOGER is not defined, we generate a (... 1, 0) pair, and when
216b416ebcSJiri Olsa  * the last step cherry picks the 2nd arg, we get a zero.
226b416ebcSJiri Olsa  */
236b416ebcSJiri Olsa #define __is_defined(x)			___is_defined(x)
246b416ebcSJiri Olsa #define ___is_defined(val)		____is_defined(__ARG_PLACEHOLDER_##val)
256b416ebcSJiri Olsa #define ____is_defined(arg1_or_junk)	__take_second_arg(arg1_or_junk 1, 0)
266b416ebcSJiri Olsa 
276b416ebcSJiri Olsa /*
286b416ebcSJiri Olsa  * IS_BUILTIN(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y', 0
296b416ebcSJiri Olsa  * otherwise. For boolean options, this is equivalent to
306b416ebcSJiri Olsa  * IS_ENABLED(CONFIG_FOO).
316b416ebcSJiri Olsa  */
326b416ebcSJiri Olsa #define IS_BUILTIN(option) __is_defined(option)
336b416ebcSJiri Olsa 
346b416ebcSJiri Olsa #endif /* _TOOLS_CONFIG_H */
35