summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Marek <mmarek@suse.cz>2011-07-20 11:38:57 -0400
committerMichal Marek <mmarek@suse.cz>2011-07-29 15:53:30 -0400
commit2a11c8ea20bf850b3a2c60db8c2e7497d28aba99 (patch)
tree975a44ccb84f5fb182fa1d6d58025b0cde381965
parentbac6aa865b3dc98e9fbc17f11d4d513d6b0bc435 (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>
-rw-r--r--Makefile2
-rw-r--r--include/linux/kconfig.h32
-rw-r--r--scripts/kconfig/confdata.c71
3 files changed, 47 insertions, 58 deletions
diff --git a/Makefile b/Makefile
index afb8e0d26f2c..bd7629bb93da 100644
--- a/Makefile
+++ b/Makefile
@@ -360,7 +360,7 @@ CFLAGS_GCOV = -fprofile-arcs -ftest-coverage
360LINUXINCLUDE := -I$(srctree)/arch/$(hdr-arch)/include \ 360LINUXINCLUDE := -I$(srctree)/arch/$(hdr-arch)/include \
361 -Iarch/$(hdr-arch)/include/generated -Iinclude \ 361 -Iarch/$(hdr-arch)/include/generated -Iinclude \
362 $(if $(KBUILD_SRC), -I$(srctree)/include) \ 362 $(if $(KBUILD_SRC), -I$(srctree)/include) \
363 -include include/generated/autoconf.h 363 -include $(srctree)/include/linux/kconfig.h
364 364
365KBUILD_CPPFLAGS := -D__KERNEL__ 365KBUILD_CPPFLAGS := -D__KERNEL__
366 366
diff --git a/include/linux/kconfig.h b/include/linux/kconfig.h
new file mode 100644
index 000000000000..067eda0e4b32
--- /dev/null
+++ b/include/linux/kconfig.h
@@ -0,0 +1,32 @@
1#ifndef __LINUX_KCONFIG_H
2#define __LINUX_KCONFIG_H
3
4#include <generated/autoconf.h>
5
6/*
7 * Helper macros to use CONFIG_ options in C expressions. Note that
8 * these only work with boolean and tristate options.
9 */
10
11/*
12 * IS_ENABLED(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y' or 'm',
13 * 0 otherwise.
14 *
15 */
16#define IS_ENABLED(option) \
17 (__enabled_ ## option || __enabled_ ## option ## _MODULE)
18
19/*
20 * IS_BUILTIN(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y', 0
21 * otherwise. For boolean options, this is equivalent to
22 * IS_ENABLED(CONFIG_FOO).
23 */
24#define IS_BUILTIN(option) __enabled_ ## option
25
26/*
27 * IS_MODULE(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'm', 0
28 * otherwise.
29 */
30#define IS_MODULE(option) __enabled_ ## option ## _MODULE
31
32#endif /* __LINUX_KCONFIG_H */
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 */
563static void
564header_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
603static 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);