Attention is currently required from: Edward O'Callaghan, Anastasia Klimchuk.
1 comment:
File tests/init_shutdown.c:
#if CONFIG_DUMMY == 1
void dummy_init_and_shutdown_test_success(void **state)
{
run_lifecycle(state, PROGRAMMER_DUMMY, "bus=parallel+lpc+fwh+spi");
}
#endif /* CONFIG_DUMMY */
"yes"/"no" is only used on the user end. Both Meson and the Makefile always use
`=1` for the `-D` arguments. However, what is rather unfortunate, they only ever
provide `1` and never `0`. So the only way to use it is useful is indeed with #if.
:-/
I forgot that we had the same problem with Kconfig in coreboot. It was solved long
ago by a complex macro. It's quite nice, so we should add that to flashrom at some
point:
/*
* 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 1"
* 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_1 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
#define CONFIG(option) config_enabled(CONFIG_##option)
How does it work? well, that's a riddle even with the comment ^^ (hint: the
comment is not accounting for the last `, 0` which is only necessary to be
C compatible where one always needs at least one variadic argument).
How is it used?
CONFIG(DUMMY)
would expand to 1 iff CONFIG_DUMMY == 1, otherwise (even if CONFIG_DUMMY
is not defined) it expands to 0.
To view, visit change 55295. To unsubscribe, or for help writing mail filters, visit settings.