diff options
author | Michal Marek <mmarek@suse.cz> | 2011-07-20 11:38:57 -0400 |
---|---|---|
committer | Michal Marek <mmarek@suse.cz> | 2011-07-29 15:53:30 -0400 |
commit | 2a11c8ea20bf850b3a2c60db8c2e7497d28aba99 (patch) | |
tree | 975a44ccb84f5fb182fa1d6d58025b0cde381965 /scripts/kconfig/confdata.c | |
parent | bac6aa865b3dc98e9fbc17f11d4d513d6b0bc435 (diff) |
kconfig: Introduce IS_ENABLED(), IS_BUILTIN() and IS_MODULE()
Replace the config_is_*() macros with a variant that allows for grepping
for usage of CONFIG_* options in the code. Usage:
if (IS_ENABLED(CONFIG_NUMA))
or
#if IS_ENABLED(CONFIG_NUMA)
The IS_ENABLED() macro evaluates to 1 if the argument is set (to either 'y'
or 'm'), IS_BUILTIN() tests if the option is 'y' and IS_MODULE() test if
the option is 'm'. Only boolean and tristate options are supported.
Reviewed-by: Arnaud Lacombe <lacombar@gmail.com>
Acked-by: Randy Dunlap <rdunlap@xenotime.net>
Signed-off-by: Michal Marek <mmarek@suse.cz>
Diffstat (limited to 'scripts/kconfig/confdata.c')
-rw-r--r-- | scripts/kconfig/confdata.c | 71 |
1 files changed, 14 insertions, 57 deletions
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index df629ecb4fdf..59b667cae5f3 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c | |||
@@ -495,15 +495,25 @@ header_print_symbol(FILE *fp, struct symbol *sym, const char *value, void *arg) | |||
495 | 495 | ||
496 | switch (*value) { | 496 | switch (*value) { |
497 | case 'n': | 497 | case 'n': |
498 | return; | 498 | break; |
499 | case 'm': | 499 | case 'm': |
500 | suffix = "_MODULE"; | 500 | suffix = "_MODULE"; |
501 | /* fall through */ | 501 | /* fall through */ |
502 | default: | 502 | default: |
503 | value = "1"; | 503 | fprintf(fp, "#define %s%s%s 1\n", |
504 | CONFIG_, sym->name, suffix); | ||
504 | } | 505 | } |
505 | fprintf(fp, "#define %s%s%s %s\n", | 506 | /* |
506 | CONFIG_, sym->name, suffix, value); | 507 | * Generate the __enabled_CONFIG_* and |
508 | * __enabled_CONFIG_*_MODULE macros for use by the | ||
509 | * IS_{ENABLED,BUILTIN,MODULE} macros. The _MODULE variant is | ||
510 | * generated even for booleans so that the IS_ENABLED() macro | ||
511 | * works. | ||
512 | */ | ||
513 | fprintf(fp, "#define __enabled_" CONFIG_ "%s %d\n", | ||
514 | sym->name, (*value == 'y')); | ||
515 | fprintf(fp, "#define __enabled_" CONFIG_ "%s_MODULE %d\n", | ||
516 | sym->name, (*value == 'm')); | ||
507 | break; | 517 | break; |
508 | } | 518 | } |
509 | case S_HEX: { | 519 | case S_HEX: { |
@@ -555,58 +565,6 @@ static struct conf_printer header_printer_cb = | |||
555 | }; | 565 | }; |
556 | 566 | ||
557 | /* | 567 | /* |
558 | * Function-style header printer | ||
559 | * | ||
560 | * This printer is used to generate the config_is_xxx() function-style macros | ||
561 | * in `include/generated/autoconf.h' | ||
562 | */ | ||
563 | static void | ||
564 | header_function_print_symbol(FILE *fp, struct symbol *sym, const char *value, void *arg) | ||
565 | { | ||
566 | int val = 0; | ||
567 | char c; | ||
568 | char *tmp, *d; | ||
569 | |||
570 | switch (sym->type) { | ||
571 | case S_BOOLEAN: | ||
572 | case S_TRISTATE: | ||
573 | break; | ||
574 | default: | ||
575 | return; | ||
576 | } | ||
577 | if (*value == 'm') | ||
578 | val = 2; | ||
579 | else if (*value == 'y') | ||
580 | val = 1; | ||
581 | |||
582 | d = strdup(CONFIG_); | ||
583 | tmp = d; | ||
584 | while ((c = *d)) { | ||
585 | *d = tolower(c); | ||
586 | d++; | ||
587 | } | ||
588 | |||
589 | fprintf(fp, "#define %sis_", tmp); | ||
590 | free(tmp); | ||
591 | |||
592 | d = strdup(sym->name); | ||
593 | tmp = d; | ||
594 | while ((c = *d)) { | ||
595 | *d = tolower(c); | ||
596 | d++; | ||
597 | } | ||
598 | fprintf(fp, "%s%s() %d\n", tmp, (val > 1) ? "_module" : "", | ||
599 | val ? 1 : 0); | ||
600 | free(tmp); | ||
601 | } | ||
602 | |||
603 | static struct conf_printer header_function_printer_cb = | ||
604 | { | ||
605 | .print_symbol = header_function_print_symbol, | ||
606 | }; | ||
607 | |||
608 | |||
609 | /* | ||
610 | * Tristate printer | 568 | * Tristate printer |
611 | * | 569 | * |
612 | * This printer is used when generating the `include/config/tristate.conf' file. | 570 | * This printer is used when generating the `include/config/tristate.conf' file. |
@@ -997,7 +955,6 @@ int conf_write_autoconf(void) | |||
997 | conf_write_symbol(tristate, sym, &tristate_printer_cb, (void *)1); | 955 | conf_write_symbol(tristate, sym, &tristate_printer_cb, (void *)1); |
998 | 956 | ||
999 | conf_write_symbol(out_h, sym, &header_printer_cb, NULL); | 957 | conf_write_symbol(out_h, sym, &header_printer_cb, NULL); |
1000 | conf_write_symbol(out_h, sym, &header_function_printer_cb, NULL); | ||
1001 | } | 958 | } |
1002 | fclose(out); | 959 | fclose(out); |
1003 | fclose(tristate); | 960 | fclose(tristate); |