diff options
-rw-r--r-- | include/common.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/include/common.h b/include/common.h index dac0bf2f00..c7a2d94460 100644 --- a/include/common.h +++ b/include/common.h @@ -218,4 +218,31 @@ enum ec_error_list { /* find the most significant bit. Not defined in n == 0. */ #define __fls(n) (31 - __builtin_clz(n)) +/* + * Getting something that works in C and CPP for an arg that may or may + * not be defined is tricky. Here, if we have "#define CONFIG_BOOGER" + * we match on the placeholder define, insert the "0," for arg1 and generate + * the triplet (0, 1, 0). Then the last step cherry picks the 2nd arg (a one). + * When CONFIG_BOOGER is not defined, we generate a (... 1, 0) pair, and when + * the last step cherry picks the 2nd arg, we get a zero. + */ +#define __ARG_PLACEHOLDER_ 0, +#define config_enabled(cfg) _config_enabled(cfg) +#define _config_enabled(value) __config_enabled(__ARG_PLACEHOLDER_##value) +#define __config_enabled(arg1_or_junk) ___config_enabled(arg1_or_junk 1, 0, 0) +#define ___config_enabled(__ignored, val, ...) val + +/** + * Checks if a config option is defined to an empty value. + * + * IS_ENABLED(CONFIG_MY_OPTION) will return 1 in the following case: + * #define CONFIG_MY_OPTION + * + * Otherwise if the option has not been defined or defined with a value, it will + * return 0. + * + * @param CONFIG_OPTION + */ +#define IS_ENABLED(option) config_enabled(option) + #endif /* __CROS_EC_COMMON_H */ |