History

kconfig: environment symbol support

Add the possibility to import a value from the environment into kconfig via the option syntax. Beside flexibility this has the advantage providing proper dependencies. Documented the options syntax.

Roman Zippel committed 18 years ago

Commit 93449081 parent 7a962929 files · +129 −35Browse files

Unified · Split

9 files
  1. Documentation/kbuild/kconfig-language.txt +21 −0
  2. scripts/kconfig/expr.h +2 −1
  3. scripts/kconfig/lkc.h +5 −0
  4. scripts/kconfig/menu.c +4 −1
  5. scripts/kconfig/qconf.cc +5 −11
  6. scripts/kconfig/symbol.c +45 −0
  7. scripts/kconfig/util.c +21 −2
  8. scripts/kconfig/zconf.gperf +1 −0
  9. scripts/kconfig/zconf.hash.c_shipped +25 −20
Documentation/kbuild/kconfig-language.txt+21−0
@@ -127,6 +127,27 @@ applicable everywhere (see syntax). · 126 unmodified lines
127127 used to help visually separate configuration logic from help within
128128 the file as an aid to developers.
129129
130+- misc options: "option" <symbol>[=<value>]
131+ Various less common options can be defined via this option syntax,
132+ which can modify the behaviour of the menu entry and its config
133+ symbol. These options are currently possible:
134+
135+ - "defconfig_list"
136+ This declares a list of default entries which can be used when
137+ looking for the default configuration (which is used when the main
138+ .config doesn't exists yet.)
139+
140+ - "modules"
141+ This declares the symbol to be used as the MODULES symbol, which
142+ enables the third modular state for all config symbols.
143+
144+ - "env"=<value>
145+ This imports the environment variable into Kconfig. It behaves like
146+ a default, except that the value comes from the environment, this
147+ also means that the behaviour when mixing it with normal defaults is
148+ undefined at this point. The symbol is currently not exported back
149+ to the build environment (if this is desired, it can be done via
150+ another symbol).
130151
131152 Menu dependencies
132153 -----------------
scripts/kconfig/expr.h+2−1
@@ -106,7 +106,8 @@ struct symbol { · 105 unmodified lines
106106 #define SYMBOL_HASHMASK 0xff
107107
108108 enum prop_type {
109− P_UNKNOWN, P_PROMPT, P_COMMENT, P_MENU, P_DEFAULT, P_CHOICE, P_SELECT, P_RANGE
109+ P_UNKNOWN, P_PROMPT, P_COMMENT, P_MENU, P_DEFAULT, P_CHOICE,
110+ P_SELECT, P_RANGE, P_ENV
110111 };
111112
112113 struct property {
scripts/kconfig/lkc.h+5−0
@@ -44,6 +44,7 @@ extern "C" { · 43 unmodified lines
4444
4545 #define T_OPT_MODULES 1
4646 #define T_OPT_DEFCONFIG_LIST 2
47+#define T_OPT_ENV 3
4748
4849 struct kconf_id {
4950 int name;
@@ -74,6 +75,7 @@ void kconfig_load(void); · 24 unmodified lines
7475
7576 /* menu.c */
7677 void menu_init(void);
78+void menu_warn(struct menu *menu, const char *fmt, ...);
7779 struct menu *menu_add_menu(void);
7880 void menu_end_menu(void);
7981 void menu_add_entry(struct symbol *sym);
@@ -103,6 +105,8 @@ void str_printf(struct gstr *gs, const char *fmt, ...); · 23 unmodified lines
103105 const char *str_get(struct gstr *gs);
104106
105107 /* symbol.c */
108+extern struct expr *sym_env_list;
109+
106110 void sym_init(void);
107111 void sym_clear_all_valid(void);
108112 void sym_set_all_changed(void);
@@ -110,6 +114,7 @@ void sym_set_changed(struct symbol *sym); · 1 unmodified line
110114 struct symbol *sym_check_deps(struct symbol *sym);
111115 struct property *prop_alloc(enum prop_type type, struct symbol *sym);
112116 struct symbol *prop_get_symbol(struct property *prop);
117+struct property *sym_get_env_prop(struct symbol *sym);
113118
114119 static inline tristate sym_get_tristate_value(struct symbol *sym)
115120 {
scripts/kconfig/menu.c+4−1
@@ -15,7 +15,7 @@ static struct menu **last_entry_ptr; · 14 unmodified lines
1515 struct file *file_list;
1616 struct file *current_file;
1717
18−static void menu_warn(struct menu *menu, const char *fmt, ...)
18+void menu_warn(struct menu *menu, const char *fmt, ...)
1919 {
2020 va_list ap;
2121 va_start(ap, fmt);
@@ -172,6 +172,9 @@ void menu_add_option(int token, char *arg) · 150 unmodified lines
172172 else if (sym_defconfig_list != current_entry->sym)
173173 zconf_error("trying to redefine defconfig symbol");
174174 break;
175+ case T_OPT_ENV:
176+ prop_add_env(arg);
177+ break;
175178 }
176179 }
177180
scripts/kconfig/qconf.cc+5−11
@@ -1088,7 +1088,11 @@ QString ConfigInfoView::debug_info(struct symbol *sym) · 1087 unmodified lines
10881088 debug += "</a><br>";
10891089 break;
10901090 case P_DEFAULT:
1091− debug += "default: ";
1091+ case P_SELECT:
1092+ case P_RANGE:
1093+ case P_ENV:
1094+ debug += prop_get_type_name(prop->type);
1095+ debug += ": ";
10921096 expr_print(prop->expr, expr_print_help, &debug, E_NONE);
10931097 debug += "<br>";
10941098 break;
@@ -1099,16 +1103,6 @@ QString ConfigInfoView::debug_info(struct symbol *sym) · 4 unmodified lines
10991103 debug += "<br>";
11001104 }
11011105 break;
1102− case P_SELECT:
1103− debug += "select: ";
1104− expr_print(prop->expr, expr_print_help, &debug, E_NONE);
1105− debug += "<br>";
1106− break;
1107− case P_RANGE:
1108− debug += "range: ";
1109− expr_print(prop->expr, expr_print_help, &debug, E_NONE);
1110− debug += "<br>";
1111− break;
11121106 default:
11131107 debug += "unknown property: ";
11141108 debug += prop_get_type_name(prop->type);
scripts/kconfig/symbol.c+45−0
@@ -34,6 +34,8 @@ struct symbol *sym_defconfig_list; · 33 unmodified lines
3434 struct symbol *modules_sym;
3535 tristate modules_val;
3636
37+struct expr *sym_env_list;
38+
3739 void sym_add_default(struct symbol *sym, const char *def)
3840 {
3941 struct property *prop = prop_alloc(P_DEFAULT, sym);
@@ -117,6 +119,15 @@ struct property *sym_get_choice_prop(struct symbol *sym) · 77 unmodified lines
117119 return NULL;
118120 }
119121
122+struct property *sym_get_env_prop(struct symbol *sym)
123+{
124+ struct property *prop;
125+
126+ for_all_properties(sym, prop, P_ENV)
127+ return prop;
128+ return NULL;
129+}
130+
120131 struct property *sym_get_default_prop(struct symbol *sym)
121132 {
122133 struct property *prop;
@@ -346,6 +357,9 @@ void sym_calc_value(struct symbol *sym) · 223 unmodified lines
346357 ;
347358 }
348359
360+ if (sym->flags & SYMBOL_AUTO)
361+ sym->flags &= ~SYMBOL_WRITE;
362+
349363 sym->curr = newval;
350364 if (sym_is_choice(sym) && newval.tri == yes)
351365 sym->curr.val = sym_calc_choice(sym);
@@ -860,6 +874,8 @@ const char *prop_get_type_name(enum prop_type type) · 508 unmodified lines
860874 switch (type) {
861875 case P_PROMPT:
862876 return "prompt";
877+ case P_ENV:
878+ return "env";
863879 case P_COMMENT:
864880 return "comment";
865881 case P_MENU:
@@ -877,3 +893,32 @@ const char *prop_get_type_name(enum prop_type type) · 11 unmodified lines
877893 }
878894 return "unknown";
879895 }
896+
897+void prop_add_env(const char *env)
898+{
899+ struct symbol *sym, *sym2;
900+ struct property *prop;
901+ char *p;
902+
903+ sym = current_entry->sym;
904+ sym->flags |= SYMBOL_AUTO;
905+ for_all_properties(sym, prop, P_ENV) {
906+ sym2 = prop_get_symbol(prop);
907+ if (strcmp(sym2->name, env))
908+ menu_warn(current_entry, "redefining environment symbol from %s",
909+ sym2->name);
910+ return;
911+ }
912+
913+ prop = prop_alloc(P_ENV, sym);
914+ prop->expr = expr_alloc_symbol(sym_lookup(env, 1));
915+
916+ sym_env_list = expr_alloc_one(E_LIST, sym_env_list);
917+ sym_env_list->right.sym = sym;
918+
919+ p = getenv(env);
920+ if (p)
921+ sym_add_default(sym, p);
922+ else
923+ menu_warn(current_entry, "environment variable %s undefined", env);
924+}
scripts/kconfig/util.c+21−2
@@ -29,6 +29,8 @@ struct file *file_lookup(const char *name) · 28 unmodified lines
2929 /* write a dependency file as used by kbuild to track dependencies */
3030 int file_write_dep(const char *name)
3131 {
32+ struct symbol *sym, *env_sym;
33+ struct expr *e;
3234 struct file *file;
3335 FILE *out;
3436
@@ -45,8 +47,25 @@ int file_write_dep(const char *name) · 10 unmodified lines
4547 fprintf(out, "\t%s\n", file->name);
4648 }
4749 fprintf(out, "\ninclude/config/auto.conf: \\\n"
48− "\t$(deps_config)\n\n"
49− "$(deps_config): ;\n");
50+ "\t$(deps_config)\n\n");
51+
52+ expr_list_for_each_sym(sym_env_list, e, sym) {
53+ struct property *prop;
54+ const char *value;
55+
56+ prop = sym_get_env_prop(sym);
57+ env_sym = prop_get_symbol(prop);
58+ if (!env_sym)
59+ continue;
60+ value = getenv(env_sym->name);
61+ if (!value)
62+ value = "";
63+ fprintf(out, "ifneq \"$(%s)\" \"%s\"\n", env_sym->name, value);
64+ fprintf(out, "include/config/auto.conf: FORCE\n");
65+ fprintf(out, "endif\n");
66+ }
67+
68+ fprintf(out, "\n$(deps_config): ;\n");
5069 fclose(out);
5170 rename("..config.tmp", name);
5271 return 0;
scripts/kconfig/zconf.gperf+1−0
@@ -41,4 +41,5 @@ option, T_OPTION, TF_COMMAND · 40 unmodified lines
4141 on, T_ON, TF_PARAM
4242 modules, T_OPT_MODULES, TF_OPTION
4343 defconfig_list, T_OPT_DEFCONFIG_LIST,TF_OPTION
44+env, T_OPT_ENV, TF_OPTION
4445 %%
scripts/kconfig/zconf.hash.c_shipped+25−20
@@ -53,10 +53,10 @@ kconf_id_hash (register const char *str, register unsigned int len) · 52 unmodified lines
5353 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
5454 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
5555 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
56− 49, 49, 49, 49, 49, 49, 49, 18, 11, 5,
56+ 49, 49, 49, 49, 49, 49, 49, 35, 35, 5,
5757 0, 0, 5, 49, 5, 20, 49, 49, 5, 20,
58− 5, 0, 30, 49, 0, 15, 0, 10, 49, 49,
59− 25, 49, 49, 49, 49, 49, 49, 49, 49, 49,
58+ 5, 0, 30, 49, 0, 15, 0, 10, 0, 49,
59+ 10, 49, 49, 49, 49, 49, 49, 49, 49, 49,
6060 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
6161 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
6262 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
@@ -89,6 +89,7 @@ kconf_id_hash (register const char *str, register unsigned int len) · 26 unmodified lines
8989 struct kconf_id_strings_t
9090 {
9191 char kconf_id_strings_str2[sizeof("on")];
92+ char kconf_id_strings_str3[sizeof("env")];
9293 char kconf_id_strings_str5[sizeof("endif")];
9394 char kconf_id_strings_str6[sizeof("option")];
9495 char kconf_id_strings_str7[sizeof("endmenu")];
@@ -99,30 +100,31 @@ struct kconf_id_strings_t · 4 unmodified lines
99100 char kconf_id_strings_str12[sizeof("default")];
100101 char kconf_id_strings_str13[sizeof("def_bool")];
101102 char kconf_id_strings_str14[sizeof("help")];
102− char kconf_id_strings_str15[sizeof("bool")];
103103 char kconf_id_strings_str16[sizeof("config")];
104104 char kconf_id_strings_str17[sizeof("def_tristate")];
105− char kconf_id_strings_str18[sizeof("boolean")];
105+ char kconf_id_strings_str18[sizeof("hex")];
106106 char kconf_id_strings_str19[sizeof("defconfig_list")];
107107 char kconf_id_strings_str21[sizeof("string")];
108108 char kconf_id_strings_str22[sizeof("if")];
109109 char kconf_id_strings_str23[sizeof("int")];
110− char kconf_id_strings_str24[sizeof("enable")];
111110 char kconf_id_strings_str26[sizeof("select")];
112111 char kconf_id_strings_str27[sizeof("modules")];
113112 char kconf_id_strings_str28[sizeof("tristate")];
114113 char kconf_id_strings_str29[sizeof("menu")];
115114 char kconf_id_strings_str31[sizeof("source")];
116115 char kconf_id_strings_str32[sizeof("comment")];
117− char kconf_id_strings_str33[sizeof("hex")];
118116 char kconf_id_strings_str35[sizeof("menuconfig")];
119117 char kconf_id_strings_str36[sizeof("prompt")];
120118 char kconf_id_strings_str37[sizeof("depends")];
119+ char kconf_id_strings_str39[sizeof("bool")];
120+ char kconf_id_strings_str41[sizeof("enable")];
121+ char kconf_id_strings_str42[sizeof("boolean")];
121122 char kconf_id_strings_str48[sizeof("mainmenu")];
122123 };
123124 static struct kconf_id_strings_t kconf_id_strings_contents =
124125 {
125126 "on",
127+ "env",
126128 "endif",
127129 "option",
128130 "endmenu",
@@ -133,25 +135,25 @@ static struct kconf_id_strings_t kconf_id_strings_contents = · 4 unmodified lines
133135 "default",
134136 "def_bool",
135137 "help",
136− "bool",
137138 "config",
138139 "def_tristate",
139− "boolean",
140+ "hex",
140141 "defconfig_list",
141142 "string",
142143 "if",
143144 "int",
144− "enable",
145145 "select",
146146 "modules",
147147 "tristate",
148148 "menu",
149149 "source",
150150 "comment",
151− "hex",
152151 "menuconfig",
153152 "prompt",
154153 "depends",
154+ "bool",
155+ "enable",
156+ "boolean",
155157 "mainmenu"
156158 };
157159 #define kconf_id_strings ((const char *) &kconf_id_strings_contents)
@@ -163,7 +165,7 @@ kconf_id_lookup (register const char *str, register unsigned int len) · 5 unmodified lines
163165 {
164166 enum
165167 {
166− TOTAL_KEYWORDS = 31,
168+ TOTAL_KEYWORDS = 32,
167169 MIN_WORD_LENGTH = 2,
168170 MAX_WORD_LENGTH = 14,
169171 MIN_HASH_VALUE = 2,
@@ -174,7 +176,8 @@ kconf_id_lookup (register const char *str, register unsigned int len) · 4 unmodified lines
174176 {
175177 {-1}, {-1},
176178 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str2, T_ON, TF_PARAM},
177− {-1}, {-1},
179+ {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str3, T_OPT_ENV, TF_OPTION},
180+ {-1},
178181 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str5, T_ENDIF, TF_COMMAND},
179182 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str6, T_OPTION, TF_COMMAND},
180183 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str7, T_ENDMENU, TF_COMMAND},
@@ -185,17 +188,16 @@ kconf_id_lookup (register const char *str, register unsigned int len) · 4 unmodified lines
185188 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str12, T_DEFAULT, TF_COMMAND, S_UNKNOWN},
186189 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str13, T_DEFAULT, TF_COMMAND, S_BOOLEAN},
187190 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str14, T_HELP, TF_COMMAND},
188− {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str15, T_TYPE, TF_COMMAND, S_BOOLEAN},
191+ {-1},
189192 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str16, T_CONFIG, TF_COMMAND},
190193 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str17, T_DEFAULT, TF_COMMAND, S_TRISTATE},
191− {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str18, T_TYPE, TF_COMMAND, S_BOOLEAN},
194+ {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str18, T_TYPE, TF_COMMAND, S_HEX},
192195 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str19, T_OPT_DEFCONFIG_LIST,TF_OPTION},
193196 {-1},
194197 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str21, T_TYPE, TF_COMMAND, S_STRING},
195198 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str22, T_IF, TF_COMMAND|TF_PARAM},
196199 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str23, T_TYPE, TF_COMMAND, S_INT},
197− {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str24, T_SELECT, TF_COMMAND},
198− {-1},
200+ {-1}, {-1},
199201 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str26, T_SELECT, TF_COMMAND},
200202 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str27, T_OPT_MODULES, TF_OPTION},
201203 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str28, T_TYPE, TF_COMMAND, S_TRISTATE},
@@ -203,13 +205,16 @@ kconf_id_lookup (register const char *str, register unsigned int len) · 1 unmodified line
203205 {-1},
204206 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str31, T_SOURCE, TF_COMMAND},
205207 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str32, T_COMMENT, TF_COMMAND},
206− {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str33, T_TYPE, TF_COMMAND, S_HEX},
207− {-1},
208+ {-1}, {-1},
208209 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str35, T_MENUCONFIG, TF_COMMAND},
209210 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str36, T_PROMPT, TF_COMMAND},
210211 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str37, T_DEPENDS, TF_COMMAND},
211− {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
212212 {-1},
213+ {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str39, T_TYPE, TF_COMMAND, S_BOOLEAN},
214+ {-1},
215+ {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str41, T_SELECT, TF_COMMAND},
216+ {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str42, T_TYPE, TF_COMMAND, S_BOOLEAN},
217+ {-1}, {-1}, {-1}, {-1}, {-1},
213218 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str48, T_MAINMENU, TF_COMMAND}
214219 };
215220

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