History

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.

Michal Marek committed 15 years ago

Commit 2a11c8e1 parent bac6aa83 files · +47 −58Browse files

Unified · Split

3 files
  1. Makefile +1 −1
  2. include/linux/kconfig.h +32 −0
  3. scripts/kconfig/confdata.c +14 −57
Makefile+1−1
@@ -360,7 +360,7 @@ CFLAGS_GCOV = -fprofile-arcs -ftest-coverage · 359 unmodified lines
360360 LINUXINCLUDE := -I$(srctree)/arch/$(hdr-arch)/include \
361361 -Iarch/$(hdr-arch)/include/generated -Iinclude \
362362 $(if $(KBUILD_SRC), -I$(srctree)/include) \
363− -include include/generated/autoconf.h
363+ -include $(srctree)/include/linux/kconfig.h
364364
365365 KBUILD_CPPFLAGS := -D__KERNEL__
366366
include/linux/kconfig.h+32−0
@@ -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 */
scripts/kconfig/confdata.c+14−57
@@ -495,15 +495,25 @@ header_print_symbol(FILE *fp, struct symbol *sym, const char *value, void *arg) · 494 unmodified lines
495495
496496 switch (*value) {
497497 case 'n':
498− return;
498+ break;
499499 case 'm':
500500 suffix = "_MODULE";
501501 /* fall through */
502502 default:
503− value = "1";
503+ fprintf(fp, "#define %s%s%s 1\n",
504+ CONFIG_, sym->name, suffix);
504505 }
505− fprintf(fp, "#define %s%s%s %s\n",
506− CONFIG_, sym->name, suffix, value);
506+ /*
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'));
507517 break;
508518 }
509519 case S_HEX: {
@@ -554,58 +564,6 @@ static struct conf_printer header_printer_cb = · 44 unmodified lines
554564 .print_comment = header_print_comment,
555565 };
556566
557−/*
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−
609567 /*
610568 * Tristate printer
611569 *
@@ -997,7 +955,6 @@ int conf_write_autoconf(void) · 385 unmodified lines
997955 conf_write_symbol(tristate, sym, &tristate_printer_cb, (void *)1);
998956
999957 conf_write_symbol(out_h, sym, &header_printer_cb, NULL);
1000− conf_write_symbol(out_h, sym, &header_function_printer_cb, NULL);
1001958 }
1002959 fclose(out);
1003960 fclose(tristate);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t