2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
9 #define LKC_DIRECT_LINK
14 /* CONFIG_MIPS_BRCM Begin Broadcom changed code. */
15 /* These variables must be moved higher to zconf.tab.c_shipped to make
16 * GCC4.0 happy. See CRDDB00016084.
17 struct menu *current_menu, *current_entry;
19 /* CONFIG_MIPS_BRCM end Broadcom changed code. */
21 static struct menu **last_entry_ptr;
23 struct file *file_list;
24 struct file *current_file;
26 static void menu_warn(struct menu *menu, const char *fmt, ...)
30 fprintf(stderr, "%s:%d:warning: ", menu->file->name, menu->lineno);
31 vfprintf(stderr, fmt, ap);
32 fprintf(stderr, "\n");
36 static void prop_warn(struct property *prop, const char *fmt, ...)
40 fprintf(stderr, "%s:%d:warning: ", prop->file->name, prop->lineno);
41 vfprintf(stderr, fmt, ap);
42 fprintf(stderr, "\n");
48 current_entry = current_menu = &rootmenu;
49 last_entry_ptr = &rootmenu.list;
52 void menu_add_entry(struct symbol *sym)
56 menu = malloc(sizeof(*menu));
57 memset(menu, 0, sizeof(*menu));
59 menu->parent = current_menu;
60 menu->file = current_file;
61 menu->lineno = zconf_lineno();
63 *last_entry_ptr = menu;
64 last_entry_ptr = &menu->next;
68 void menu_end_entry(void)
72 void menu_add_menu(void)
74 current_menu = current_entry;
75 last_entry_ptr = ¤t_entry->list;
78 void menu_end_menu(void)
80 last_entry_ptr = ¤t_menu->next;
81 current_menu = current_menu->parent;
84 struct expr *menu_check_dep(struct expr *e)
91 e->left.expr = menu_check_dep(e->left.expr);
95 e->left.expr = menu_check_dep(e->left.expr);
96 e->right.expr = menu_check_dep(e->right.expr);
99 /* change 'm' into 'm' && MODULES */
100 if (e->left.sym == &symbol_mod)
101 return expr_alloc_and(e, expr_alloc_symbol(modules_sym));
109 void menu_add_dep(struct expr *dep)
111 current_entry->dep = expr_alloc_and(current_entry->dep, menu_check_dep(dep));
114 void menu_set_type(int type)
116 struct symbol *sym = current_entry->sym;
118 if (sym->type == type)
120 if (sym->type == S_UNKNOWN) {
124 menu_warn(current_entry, "type of '%s' redefined from '%s' to '%s'\n",
125 sym->name ? sym->name : "<choice>",
126 sym_type_name(sym->type), sym_type_name(type));
129 struct property *menu_add_prop(enum prop_type type, char *prompt, struct expr *expr, struct expr *dep)
131 struct property *prop = prop_alloc(type, current_entry->sym);
133 prop->menu = current_entry;
136 prop->visible.expr = menu_check_dep(dep);
139 if (current_entry->prompt)
140 menu_warn(current_entry, "prompt redefined\n");
141 current_entry->prompt = prop;
147 void menu_add_prompt(enum prop_type type, char *prompt, struct expr *dep)
149 menu_add_prop(type, prompt, NULL, dep);
152 void menu_add_expr(enum prop_type type, struct expr *expr, struct expr *dep)
154 menu_add_prop(type, NULL, expr, dep);
157 void menu_add_symbol(enum prop_type type, struct symbol *sym, struct expr *dep)
159 menu_add_prop(type, NULL, expr_alloc_symbol(sym), dep);
162 void sym_check_prop(struct symbol *sym)
164 struct property *prop;
166 for (prop = sym->prop; prop; prop = prop->next) {
167 switch (prop->type) {
169 if ((sym->type == S_STRING || sym->type == S_INT || sym->type == S_HEX) &&
170 prop->expr->type != E_SYMBOL)
172 "default for config symbol '%'"
173 " must be a single symbol", sym->name);
176 sym2 = prop_get_symbol(prop);
177 if (sym->type != S_BOOLEAN && sym->type != S_TRISTATE)
179 "config symbol '%s' uses select, but is "
180 "not boolean or tristate", sym->name);
181 else if (sym2->type == S_UNKNOWN)
183 "'select' used by config symbol '%s' "
184 "refer to undefined symbol '%s'",
185 sym->name, sym2->name);
186 else if (sym2->type != S_BOOLEAN && sym2->type != S_TRISTATE)
188 "'%s' has wrong type. 'select' only "
189 "accept arguments of boolean and "
190 "tristate type", sym2->name);
193 if (sym->type != S_INT && sym->type != S_HEX)
194 prop_warn(prop, "range is only allowed "
195 "for int or hex symbols");
196 if (!sym_string_valid(sym, prop->expr->left.sym->name) ||
197 !sym_string_valid(sym, prop->expr->right.sym->name))
198 prop_warn(prop, "range is invalid");
206 void menu_finalize(struct menu *parent)
208 struct menu *menu, *last_menu;
210 struct property *prop;
211 struct expr *parentdep, *basedep, *dep, *dep2, **ep;
215 if (sym && sym_is_choice(sym)) {
216 /* find the first choice value and find out choice type */
217 for (menu = parent->list; menu; menu = menu->next) {
219 current_entry = parent;
220 menu_set_type(menu->sym->type);
221 current_entry = menu;
222 menu_set_type(sym->type);
226 parentdep = expr_alloc_symbol(sym);
227 } else if (parent->prompt)
228 parentdep = parent->prompt->visible.expr;
230 parentdep = parent->dep;
232 for (menu = parent->list; menu; menu = menu->next) {
233 basedep = expr_transform(menu->dep);
234 basedep = expr_alloc_and(expr_copy(parentdep), basedep);
235 basedep = expr_eliminate_dups(basedep);
238 prop = menu->sym->prop;
241 for (; prop; prop = prop->next) {
242 if (prop->menu != menu)
244 dep = expr_transform(prop->visible.expr);
245 dep = expr_alloc_and(expr_copy(basedep), dep);
246 dep = expr_eliminate_dups(dep);
247 if (menu->sym && menu->sym->type != S_TRISTATE)
248 dep = expr_trans_bool(dep);
249 prop->visible.expr = dep;
250 if (prop->type == P_SELECT) {
251 struct symbol *es = prop_get_symbol(prop);
252 es->rev_dep.expr = expr_alloc_or(es->rev_dep.expr,
253 expr_alloc_and(expr_alloc_symbol(menu->sym), expr_copy(dep)));
257 for (menu = parent->list; menu; menu = menu->next)
260 basedep = parent->prompt ? parent->prompt->visible.expr : NULL;
261 basedep = expr_trans_compare(basedep, E_UNEQUAL, &symbol_no);
262 basedep = expr_eliminate_dups(expr_transform(basedep));
264 for (menu = parent->next; menu; menu = menu->next) {
265 dep = menu->prompt ? menu->prompt->visible.expr : menu->dep;
266 if (!expr_contains_symbol(dep, sym))
268 if (expr_depends_symbol(dep, sym))
270 dep = expr_trans_compare(dep, E_UNEQUAL, &symbol_no);
271 dep = expr_eliminate_dups(expr_transform(dep));
272 dep2 = expr_copy(basedep);
273 expr_eliminate_eq(&dep, &dep2);
275 if (!expr_is_yes(dep2)) {
282 menu->parent = parent;
286 parent->list = parent->next;
287 parent->next = last_menu->next;
288 last_menu->next = NULL;
291 for (menu = parent->list; menu; menu = menu->next) {
292 if (sym && sym_is_choice(sym) && menu->sym) {
293 menu->sym->flags |= SYMBOL_CHOICEVAL;
295 menu_warn(menu, "choice value must have a prompt");
296 for (prop = menu->sym->prop; prop; prop = prop->next) {
297 if (prop->type == P_PROMPT && prop->menu != menu) {
298 prop_warn(prop, "choice values "
299 "currently only support a "
302 if (prop->type == P_DEFAULT)
303 prop_warn(prop, "defaults for choice "
304 "values not supported");
306 current_entry = menu;
307 menu_set_type(sym->type);
308 menu_add_symbol(P_CHOICE, sym, NULL);
309 prop = sym_get_choice_prop(sym);
310 for (ep = &prop->expr; *ep; ep = &(*ep)->left.expr)
312 *ep = expr_alloc_one(E_CHOICE, NULL);
313 (*ep)->right.sym = menu->sym;
315 if (menu->list && (!menu->prompt || !menu->prompt->text)) {
316 for (last_menu = menu->list; ; last_menu = last_menu->next) {
317 last_menu->parent = parent;
318 if (!last_menu->next)
321 last_menu->next = menu->next;
322 menu->next = menu->list;
327 if (sym && !(sym->flags & SYMBOL_WARNED)) {
328 if (sym->type == S_UNKNOWN)
329 menu_warn(parent, "config symbol defined "
332 if (sym_is_choice(sym) && !parent->prompt)
333 menu_warn(parent, "choice must have a prompt\n");
335 /* Check properties connected to this symbol */
337 sym->flags |= SYMBOL_WARNED;
340 if (sym && !sym_is_optional(sym) && parent->prompt) {
341 sym->rev_dep.expr = expr_alloc_or(sym->rev_dep.expr,
342 expr_alloc_and(parent->prompt->visible.expr,
343 expr_alloc_symbol(&symbol_mod)));
347 bool menu_is_visible(struct menu *menu)
358 visible = menu->prompt->visible.tri;
360 visible = menu->prompt->visible.tri = expr_calc_value(menu->prompt->visible.expr);
364 if (!sym || sym_get_tristate_value(menu->sym) == no)
367 for (child = menu->list; child; child = child->next)
368 if (menu_is_visible(child))
373 const char *menu_get_prompt(struct menu *menu)
376 return menu->prompt->text;
378 return menu->sym->name;
382 struct menu *menu_get_root_menu(struct menu *menu)
387 struct menu *menu_get_parent_menu(struct menu *menu)
391 for (; menu != &rootmenu; menu = menu->parent) {
392 type = menu->prompt ? menu->prompt->type : 0;
399 struct file *file_lookup(const char *name)
403 for (file = file_list; file; file = file->next) {
404 if (!strcmp(name, file->name))
408 file = malloc(sizeof(*file));
409 memset(file, 0, sizeof(*file));
410 file->name = strdup(name);
411 file->next = file_list;
416 int file_write_dep(const char *name)
422 name = ".config.cmd";
423 out = fopen("..config.tmp", "w");
426 fprintf(out, "deps_config := \\\n");
427 for (file = file_list; file; file = file->next) {
429 fprintf(out, "\t%s \\\n", file->name);
431 fprintf(out, "\t%s\n", file->name);
433 fprintf(out, "\n.config include/linux/autoconf.h: $(deps_config)\n\n$(deps_config):\n");
435 rename("..config.tmp", name);