2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
17 #define LKC_DIRECT_LINK
21 #define EUNSETOPT 2 /* if -B and -b are used and unset config
22 * options were found */
24 static void conf(struct menu *menu);
25 static void check_conf(struct menu *menu);
38 } input_mode = oldaskconfig;
42 static int indent = 1;
43 static int valid_stdin = 1;
44 static int sync_kconfig;
46 static char line[128];
47 static struct menu *rootEntry;
48 static int unset_variables;
50 static void print_help(struct menu *menu)
52 struct gstr help = str_new();
54 menu_get_ext_help(menu, &help);
56 printf("\n%s\n", str_get(&help));
60 static void strip(char *str)
69 memmove(str, p, l + 1);
77 static void check_stdin(void)
80 printf(_("aborted!\n\n"));
81 printf(_("Console input/output is redirected. "));
82 printf(_("Run 'make oldconfig' to update configuration.\n\n"));
87 static int conf_askvalue(struct symbol *sym, const char *def)
89 enum symbol_type type = sym_get_type(sym);
91 if (!sym_has_value(sym))
97 if (!sym_is_changable(sym)) {
104 switch (input_mode) {
106 case silentoldconfig:
107 if (sym_has_value(sym)) {
114 fgets(line, 128, stdin);
133 static int conf_string(struct menu *menu)
135 struct symbol *sym = menu->sym;
139 printf("%*s%s ", indent - 1, "", _(menu->prompt->text));
140 printf("(%s) ", sym->name);
141 def = sym_get_string_value(sym);
142 if (sym_get_string_value(sym))
143 printf("[%s] ", def);
144 if (!conf_askvalue(sym, def))
151 if (line[1] == '\n') {
157 line[strlen(line)-1] = 0;
160 if (def && sym_set_string_value(sym, def))
165 static int conf_sym(struct menu *menu)
167 struct symbol *sym = menu->sym;
168 tristate oldval, newval;
171 printf("%*s%s ", indent - 1, "", _(menu->prompt->text));
173 printf("(%s) ", sym->name);
175 oldval = sym_get_tristate_value(sym);
187 if (oldval != no && sym_tristate_within_range(sym, no))
189 if (oldval != mod && sym_tristate_within_range(sym, mod))
191 if (oldval != yes && sym_tristate_within_range(sym, yes))
193 if (menu_has_help(menu))
196 if (!conf_askvalue(sym, sym_get_string_value(sym)))
204 if (!line[1] || !strcmp(&line[1], "o"))
216 if (!line[1] || !strcmp(&line[1], "es"))
227 if (sym_set_tristate_value(sym, newval))
234 static int conf_choice(struct menu *menu)
236 struct symbol *sym, *def_sym;
241 is_new = !sym_has_value(sym);
242 if (sym_is_changable(sym)) {
245 switch (sym_get_tristate_value(sym)) {
254 switch (sym_get_tristate_value(sym)) {
258 printf("%*s%s\n", indent - 1, "", _(menu_get_prompt(menu)));
268 printf("%*s%s\n", indent - 1, "", _(menu_get_prompt(menu)));
269 def_sym = sym_get_choice_value(sym);
272 for (child = menu->list; child; child = child->next) {
273 if (!menu_is_visible(child))
276 printf("%*c %s\n", indent, '*', _(menu_get_prompt(child)));
280 if (child->sym == def_sym) {
282 printf("%*c", indent, '>');
284 printf("%*c", indent, ' ');
285 printf(" %d. %s", cnt, _(menu_get_prompt(child)));
286 if (child->sym->name)
287 printf(" (%s)", child->sym->name);
288 if (!sym_has_value(child->sym))
292 printf(_("%*schoice"), indent - 1, "");
297 printf("[1-%d", cnt);
298 if (menu_has_help(menu))
301 switch (input_mode) {
303 case silentoldconfig:
312 fgets(line, 128, stdin);
314 if (line[0] == '?') {
320 else if (isdigit(line[0]))
330 for (child = menu->list; child; child = child->next) {
331 if (!child->sym || !menu_is_visible(child))
338 if (line[strlen(line) - 1] == '?') {
342 sym_set_choice_value(sym, child->sym);
343 for (child = child->list; child; child = child->next) {
352 static void conf(struct menu *menu)
355 struct property *prop;
358 if (!menu_is_visible(menu))
366 switch (prop->type) {
368 if ((input_mode == silentoldconfig ||
369 input_mode == nonint_oldconfig ||
370 input_mode == oldnoconfig) &&
376 prompt = menu_get_prompt(menu);
378 printf("%*c\n%*c %s\n%*c\n",
380 indent, '*', _(prompt),
390 if (sym_is_choice(sym)) {
392 if (sym->curr.tri != mod)
411 for (child = menu->list; child; child = child->next)
417 static void check_conf(struct menu *menu)
422 if (!menu_is_visible(menu))
426 if (sym && !sym_has_value(sym)) {
427 if (sym_is_changable(sym) ||
428 (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)) {
429 if (input_mode == nonint_oldconfig ||
430 input_mode == oldnoconfig) {
431 if (input_mode == nonint_oldconfig &&
432 sym->name && !sym_is_choice_value(sym)) {
433 if (!unset_variables)
434 fprintf(stderr, "The following"
435 " variables are not set:\n");
436 fprintf(stderr, "CONFIG_%s\n",
442 printf(_("*\n* Restart config...\n*\n"));
443 rootEntry = menu_get_parent_menu(menu);
449 for (child = menu->list; child; child = child->next)
453 static struct option long_opts[] = {
454 {"oldaskconfig", no_argument, NULL, oldaskconfig},
455 {"oldconfig", no_argument, NULL, oldconfig},
456 {"silentoldconfig", no_argument, NULL, silentoldconfig},
457 {"defconfig", optional_argument, NULL, defconfig},
458 {"allnoconfig", no_argument, NULL, allnoconfig},
459 {"allyesconfig", no_argument, NULL, allyesconfig},
460 {"allmodconfig", no_argument, NULL, allmodconfig},
461 {"randconfig", no_argument, NULL, randconfig},
462 {"nonint_oldconfig", no_argument, NULL, nonint_oldconfig},
463 {"oldnoconfig", no_argument, NULL, oldnoconfig},
467 int main(int ac, char **av)
473 setlocale(LC_ALL, "");
474 bindtextdomain(PACKAGE, LOCALEDIR);
477 while ((opt = getopt_long_only(ac, av, "", long_opts, NULL)) != -1) {
478 input_mode = (enum input_mode)opt;
480 case silentoldconfig:
484 defconfig_file = optarg;
492 * Use microseconds derived seed,
493 * compensate for systems where it may be zero
495 gettimeofday(&now, NULL);
497 seed = (unsigned int)((now.tv_sec + 1) * (now.tv_usec + 1));
502 fprintf(stderr, _("See README for usage info\n"));
508 printf(_("%s: Kconfig file missing\n"), av[0]);
515 name = conf_get_configname();
516 if (stat(name, &tmpstat)) {
517 fprintf(stderr, _("***\n"
518 "*** You have not yet configured your kernel!\n"
519 "*** (missing kernel config file \"%s\")\n"
521 "*** Please run some configurator (e.g. \"make oldconfig\" or\n"
522 "*** \"make menuconfig\" or \"make xconfig\").\n"
528 switch (input_mode) {
531 defconfig_file = conf_get_default_confname();
532 if (conf_read(defconfig_file)) {
534 "*** Can't find default configuration \"%s\"!\n"
535 "***\n"), defconfig_file);
539 case silentoldconfig:
542 case nonint_oldconfig:
550 name = getenv("KCONFIG_ALLCONFIG");
551 if (name && !stat(name, &tmpstat)) {
552 conf_read_simple(name, S_DEF_USER);
555 switch (input_mode) {
556 case allnoconfig: name = "allno.config"; break;
557 case allyesconfig: name = "allyes.config"; break;
558 case allmodconfig: name = "allmod.config"; break;
559 case randconfig: name = "allrandom.config"; break;
562 if (!stat(name, &tmpstat))
563 conf_read_simple(name, S_DEF_USER);
564 else if (!stat("all.config", &tmpstat))
565 conf_read_simple("all.config", S_DEF_USER);
572 if (conf_get_changed()) {
573 name = getenv("KCONFIG_NOSILENTUPDATE");
576 _("\n*** Kernel configuration requires explicit update.\n\n"));
580 valid_stdin = isatty(0) && isatty(1) && isatty(2);
583 switch (input_mode) {
585 conf_set_all_new_symbols(def_no);
588 conf_set_all_new_symbols(def_yes);
591 conf_set_all_new_symbols(def_mod);
594 conf_set_all_new_symbols(def_random);
597 conf_set_all_new_symbols(def_default);
601 rootEntry = &rootmenu;
603 input_mode = silentoldconfig;
605 case nonint_oldconfig:
607 case silentoldconfig:
608 /* Update until a loop caused no more changes */
611 check_conf(&rootmenu);
613 (input_mode != nonint_oldconfig &&
614 input_mode != oldnoconfig));
619 /* silentoldconfig is used during the build so we shall update autoconf.
620 * All other commands are only used to generate a config.
622 if (conf_get_changed() && conf_write(NULL)) {
623 fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n"));
626 if (conf_write_autoconf()) {
627 fprintf(stderr, _("\n*** Error during update of the kernel configuration.\n\n"));
630 } else if (!unset_variables || input_mode != nonint_oldconfig) {
631 if (conf_write(NULL)) {
632 fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n"));
636 return unset_variables ? EUNSETOPT : 0;