aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/kconfig/conf.c
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/kconfig/conf.c')
-rw-r--r--scripts/kconfig/conf.c207
1 files changed, 123 insertions, 84 deletions
diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c
index 9960d1c303f8..5459a38be866 100644
--- a/scripts/kconfig/conf.c
+++ b/scripts/kconfig/conf.c
@@ -10,6 +10,7 @@
10#include <string.h> 10#include <string.h>
11#include <time.h> 11#include <time.h>
12#include <unistd.h> 12#include <unistd.h>
13#include <getopt.h>
13#include <sys/stat.h> 14#include <sys/stat.h>
14#include <sys/time.h> 15#include <sys/time.h>
15 16
@@ -19,16 +20,21 @@
19static void conf(struct menu *menu); 20static void conf(struct menu *menu);
20static void check_conf(struct menu *menu); 21static void check_conf(struct menu *menu);
21 22
22enum { 23enum input_mode {
23 ask_all, 24 oldaskconfig,
24 ask_new, 25 silentoldconfig,
25 ask_silent, 26 oldconfig,
26 set_default, 27 allnoconfig,
27 set_yes, 28 allyesconfig,
28 set_mod, 29 allmodconfig,
29 set_no, 30 alldefconfig,
30 set_random 31 randconfig,
31} input_mode = ask_all; 32 defconfig,
33 savedefconfig,
34 listnewconfig,
35 oldnoconfig,
36} input_mode = oldaskconfig;
37
32char *defconfig_file; 38char *defconfig_file;
33 39
34static int indent = 1; 40static int indent = 1;
@@ -93,16 +99,16 @@ static int conf_askvalue(struct symbol *sym, const char *def)
93 } 99 }
94 100
95 switch (input_mode) { 101 switch (input_mode) {
96 case ask_new: 102 case oldconfig:
97 case ask_silent: 103 case silentoldconfig:
98 if (sym_has_value(sym)) { 104 if (sym_has_value(sym)) {
99 printf("%s\n", def); 105 printf("%s\n", def);
100 return 0; 106 return 0;
101 } 107 }
102 check_stdin(); 108 check_stdin();
103 case ask_all: 109 case oldaskconfig:
104 fflush(stdout); 110 fflush(stdout);
105 fgets(line, 128, stdin); 111 xfgets(line, 128, stdin);
106 return 1; 112 return 1;
107 default: 113 default:
108 break; 114 break;
@@ -156,14 +162,12 @@ static int conf_string(struct menu *menu)
156static int conf_sym(struct menu *menu) 162static int conf_sym(struct menu *menu)
157{ 163{
158 struct symbol *sym = menu->sym; 164 struct symbol *sym = menu->sym;
159 int type;
160 tristate oldval, newval; 165 tristate oldval, newval;
161 166
162 while (1) { 167 while (1) {
163 printf("%*s%s ", indent - 1, "", _(menu->prompt->text)); 168 printf("%*s%s ", indent - 1, "", _(menu->prompt->text));
164 if (sym->name) 169 if (sym->name)
165 printf("(%s) ", sym->name); 170 printf("(%s) ", sym->name);
166 type = sym_get_type(sym);
167 putchar('['); 171 putchar('[');
168 oldval = sym_get_tristate_value(sym); 172 oldval = sym_get_tristate_value(sym);
169 switch (oldval) { 173 switch (oldval) {
@@ -228,11 +232,9 @@ static int conf_choice(struct menu *menu)
228{ 232{
229 struct symbol *sym, *def_sym; 233 struct symbol *sym, *def_sym;
230 struct menu *child; 234 struct menu *child;
231 int type;
232 bool is_new; 235 bool is_new;
233 236
234 sym = menu->sym; 237 sym = menu->sym;
235 type = sym_get_type(sym);
236 is_new = !sym_has_value(sym); 238 is_new = !sym_has_value(sym);
237 if (sym_is_changable(sym)) { 239 if (sym_is_changable(sym)) {
238 conf_sym(menu); 240 conf_sym(menu);
@@ -294,17 +296,17 @@ static int conf_choice(struct menu *menu)
294 printf("?"); 296 printf("?");
295 printf("]: "); 297 printf("]: ");
296 switch (input_mode) { 298 switch (input_mode) {
297 case ask_new: 299 case oldconfig:
298 case ask_silent: 300 case silentoldconfig:
299 if (!is_new) { 301 if (!is_new) {
300 cnt = def; 302 cnt = def;
301 printf("%d\n", cnt); 303 printf("%d\n", cnt);
302 break; 304 break;
303 } 305 }
304 check_stdin(); 306 check_stdin();
305 case ask_all: 307 case oldaskconfig:
306 fflush(stdout); 308 fflush(stdout);
307 fgets(line, 128, stdin); 309 xfgets(line, 128, stdin);
308 strip(line); 310 strip(line);
309 if (line[0] == '?') { 311 if (line[0] == '?') {
310 print_help(menu); 312 print_help(menu);
@@ -360,7 +362,10 @@ static void conf(struct menu *menu)
360 362
361 switch (prop->type) { 363 switch (prop->type) {
362 case P_MENU: 364 case P_MENU:
363 if (input_mode == ask_silent && rootEntry != menu) { 365 if ((input_mode == silentoldconfig ||
366 input_mode == listnewconfig ||
367 input_mode == oldnoconfig) &&
368 rootEntry != menu) {
364 check_conf(menu); 369 check_conf(menu);
365 return; 370 return;
366 } 371 }
@@ -418,10 +423,16 @@ static void check_conf(struct menu *menu)
418 if (sym && !sym_has_value(sym)) { 423 if (sym && !sym_has_value(sym)) {
419 if (sym_is_changable(sym) || 424 if (sym_is_changable(sym) ||
420 (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)) { 425 (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)) {
421 if (!conf_cnt++) 426 if (input_mode == listnewconfig) {
422 printf(_("*\n* Restart config...\n*\n")); 427 if (sym->name && !sym_is_choice_value(sym)) {
423 rootEntry = menu_get_parent_menu(menu); 428 printf("%s%s\n", CONFIG_, sym->name);
424 conf(rootEntry); 429 }
430 } else if (input_mode != oldnoconfig) {
431 if (!conf_cnt++)
432 printf(_("*\n* Restart config...\n*\n"));
433 rootEntry = menu_get_parent_menu(menu);
434 conf(rootEntry);
435 }
425 } 436 }
426 } 437 }
427 438
@@ -429,6 +440,22 @@ static void check_conf(struct menu *menu)
429 check_conf(child); 440 check_conf(child);
430} 441}
431 442
443static struct option long_opts[] = {
444 {"oldaskconfig", no_argument, NULL, oldaskconfig},
445 {"oldconfig", no_argument, NULL, oldconfig},
446 {"silentoldconfig", no_argument, NULL, silentoldconfig},
447 {"defconfig", optional_argument, NULL, defconfig},
448 {"savedefconfig", required_argument, NULL, savedefconfig},
449 {"allnoconfig", no_argument, NULL, allnoconfig},
450 {"allyesconfig", no_argument, NULL, allyesconfig},
451 {"allmodconfig", no_argument, NULL, allmodconfig},
452 {"alldefconfig", no_argument, NULL, alldefconfig},
453 {"randconfig", no_argument, NULL, randconfig},
454 {"listnewconfig", no_argument, NULL, listnewconfig},
455 {"oldnoconfig", no_argument, NULL, oldnoconfig},
456 {NULL, 0, NULL, 0}
457};
458
432int main(int ac, char **av) 459int main(int ac, char **av)
433{ 460{
434 int opt; 461 int opt;
@@ -439,32 +466,17 @@ int main(int ac, char **av)
439 bindtextdomain(PACKAGE, LOCALEDIR); 466 bindtextdomain(PACKAGE, LOCALEDIR);
440 textdomain(PACKAGE); 467 textdomain(PACKAGE);
441 468
442 while ((opt = getopt(ac, av, "osdD:nmyrh")) != -1) { 469 while ((opt = getopt_long(ac, av, "", long_opts, NULL)) != -1) {
470 input_mode = (enum input_mode)opt;
443 switch (opt) { 471 switch (opt) {
444 case 'o': 472 case silentoldconfig:
445 input_mode = ask_silent;
446 break;
447 case 's':
448 input_mode = ask_silent;
449 sync_kconfig = 1; 473 sync_kconfig = 1;
450 break; 474 break;
451 case 'd': 475 case defconfig:
452 input_mode = set_default; 476 case savedefconfig:
453 break;
454 case 'D':
455 input_mode = set_default;
456 defconfig_file = optarg; 477 defconfig_file = optarg;
457 break; 478 break;
458 case 'n': 479 case randconfig:
459 input_mode = set_no;
460 break;
461 case 'm':
462 input_mode = set_mod;
463 break;
464 case 'y':
465 input_mode = set_yes;
466 break;
467 case 'r':
468 { 480 {
469 struct timeval now; 481 struct timeval now;
470 unsigned int seed; 482 unsigned int seed;
@@ -477,17 +489,12 @@ int main(int ac, char **av)
477 489
478 seed = (unsigned int)((now.tv_sec + 1) * (now.tv_usec + 1)); 490 seed = (unsigned int)((now.tv_sec + 1) * (now.tv_usec + 1));
479 srand(seed); 491 srand(seed);
480
481 input_mode = set_random;
482 break; 492 break;
483 } 493 }
484 case 'h': 494 case '?':
485 printf(_("See README for usage info\n"));
486 exit(0);
487 break;
488 default:
489 fprintf(stderr, _("See README for usage info\n")); 495 fprintf(stderr, _("See README for usage info\n"));
490 exit(1); 496 exit(1);
497 break;
491 } 498 }
492 } 499 }
493 if (ac == optind) { 500 if (ac == optind) {
@@ -501,8 +508,7 @@ int main(int ac, char **av)
501 name = conf_get_configname(); 508 name = conf_get_configname();
502 if (stat(name, &tmpstat)) { 509 if (stat(name, &tmpstat)) {
503 fprintf(stderr, _("***\n" 510 fprintf(stderr, _("***\n"
504 "*** You have not yet configured your kernel!\n" 511 "*** Configuration file \"%s\" not found!\n"
505 "*** (missing kernel config file \"%s\")\n"
506 "***\n" 512 "***\n"
507 "*** Please run some configurator (e.g. \"make oldconfig\" or\n" 513 "*** Please run some configurator (e.g. \"make oldconfig\" or\n"
508 "*** \"make menuconfig\" or \"make xconfig\").\n" 514 "*** \"make menuconfig\" or \"make xconfig\").\n"
@@ -512,7 +518,7 @@ int main(int ac, char **av)
512 } 518 }
513 519
514 switch (input_mode) { 520 switch (input_mode) {
515 case set_default: 521 case defconfig:
516 if (!defconfig_file) 522 if (!defconfig_file)
517 defconfig_file = conf_get_default_confname(); 523 defconfig_file = conf_get_default_confname();
518 if (conf_read(defconfig_file)) { 524 if (conf_read(defconfig_file)) {
@@ -522,25 +528,32 @@ int main(int ac, char **av)
522 exit(1); 528 exit(1);
523 } 529 }
524 break; 530 break;
525 case ask_silent: 531 case savedefconfig:
526 case ask_all: 532 conf_read(NULL);
527 case ask_new: 533 break;
534 case silentoldconfig:
535 case oldaskconfig:
536 case oldconfig:
537 case listnewconfig:
538 case oldnoconfig:
528 conf_read(NULL); 539 conf_read(NULL);
529 break; 540 break;
530 case set_no: 541 case allnoconfig:
531 case set_mod: 542 case allyesconfig:
532 case set_yes: 543 case allmodconfig:
533 case set_random: 544 case alldefconfig:
545 case randconfig:
534 name = getenv("KCONFIG_ALLCONFIG"); 546 name = getenv("KCONFIG_ALLCONFIG");
535 if (name && !stat(name, &tmpstat)) { 547 if (name && !stat(name, &tmpstat)) {
536 conf_read_simple(name, S_DEF_USER); 548 conf_read_simple(name, S_DEF_USER);
537 break; 549 break;
538 } 550 }
539 switch (input_mode) { 551 switch (input_mode) {
540 case set_no: name = "allno.config"; break; 552 case allnoconfig: name = "allno.config"; break;
541 case set_mod: name = "allmod.config"; break; 553 case allyesconfig: name = "allyes.config"; break;
542 case set_yes: name = "allyes.config"; break; 554 case allmodconfig: name = "allmod.config"; break;
543 case set_random: name = "allrandom.config"; break; 555 case alldefconfig: name = "alldef.config"; break;
556 case randconfig: name = "allrandom.config"; break;
544 default: break; 557 default: break;
545 } 558 }
546 if (!stat(name, &tmpstat)) 559 if (!stat(name, &tmpstat))
@@ -557,7 +570,7 @@ int main(int ac, char **av)
557 name = getenv("KCONFIG_NOSILENTUPDATE"); 570 name = getenv("KCONFIG_NOSILENTUPDATE");
558 if (name && *name) { 571 if (name && *name) {
559 fprintf(stderr, 572 fprintf(stderr,
560 _("\n*** Kernel configuration requires explicit update.\n\n")); 573 _("\n*** The configuration requires explicit update.\n\n"));
561 return 1; 574 return 1;
562 } 575 }
563 } 576 }
@@ -565,33 +578,42 @@ int main(int ac, char **av)
565 } 578 }
566 579
567 switch (input_mode) { 580 switch (input_mode) {
568 case set_no: 581 case allnoconfig:
569 conf_set_all_new_symbols(def_no); 582 conf_set_all_new_symbols(def_no);
570 break; 583 break;
571 case set_yes: 584 case allyesconfig:
572 conf_set_all_new_symbols(def_yes); 585 conf_set_all_new_symbols(def_yes);
573 break; 586 break;
574 case set_mod: 587 case allmodconfig:
575 conf_set_all_new_symbols(def_mod); 588 conf_set_all_new_symbols(def_mod);
576 break; 589 break;
577 case set_random: 590 case alldefconfig:
591 conf_set_all_new_symbols(def_default);
592 break;
593 case randconfig:
578 conf_set_all_new_symbols(def_random); 594 conf_set_all_new_symbols(def_random);
579 break; 595 break;
580 case set_default: 596 case defconfig:
581 conf_set_all_new_symbols(def_default); 597 conf_set_all_new_symbols(def_default);
582 break; 598 break;
583 case ask_new: 599 case savedefconfig:
584 case ask_all: 600 break;
601 case oldaskconfig:
585 rootEntry = &rootmenu; 602 rootEntry = &rootmenu;
586 conf(&rootmenu); 603 conf(&rootmenu);
587 input_mode = ask_silent; 604 input_mode = silentoldconfig;
588 /* fall through */ 605 /* fall through */
589 case ask_silent: 606 case oldconfig:
607 case listnewconfig:
608 case oldnoconfig:
609 case silentoldconfig:
590 /* Update until a loop caused no more changes */ 610 /* Update until a loop caused no more changes */
591 do { 611 do {
592 conf_cnt = 0; 612 conf_cnt = 0;
593 check_conf(&rootmenu); 613 check_conf(&rootmenu);
594 } while (conf_cnt); 614 } while (conf_cnt &&
615 (input_mode != listnewconfig &&
616 input_mode != oldnoconfig));
595 break; 617 break;
596 } 618 }
597 619
@@ -600,18 +622,35 @@ int main(int ac, char **av)
600 * All other commands are only used to generate a config. 622 * All other commands are only used to generate a config.
601 */ 623 */
602 if (conf_get_changed() && conf_write(NULL)) { 624 if (conf_get_changed() && conf_write(NULL)) {
603 fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n")); 625 fprintf(stderr, _("\n*** Error during writing of the configuration.\n\n"));
604 exit(1); 626 exit(1);
605 } 627 }
606 if (conf_write_autoconf()) { 628 if (conf_write_autoconf()) {
607 fprintf(stderr, _("\n*** Error during update of the kernel configuration.\n\n")); 629 fprintf(stderr, _("\n*** Error during update of the configuration.\n\n"));
608 return 1; 630 return 1;
609 } 631 }
610 } else { 632 } else if (input_mode == savedefconfig) {
633 if (conf_write_defconfig(defconfig_file)) {
634 fprintf(stderr, _("n*** Error while saving defconfig to: %s\n\n"),
635 defconfig_file);
636 return 1;
637 }
638 } else if (input_mode != listnewconfig) {
611 if (conf_write(NULL)) { 639 if (conf_write(NULL)) {
612 fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n")); 640 fprintf(stderr, _("\n*** Error during writing of the configuration.\n\n"));
613 exit(1); 641 exit(1);
614 } 642 }
615 } 643 }
616 return 0; 644 return 0;
617} 645}
646/*
647 * Helper function to facilitate fgets() by Jean Sacren.
648 */
649void xfgets(str, size, in)
650 char *str;
651 int size;
652 FILE *in;
653{
654 if (fgets(str, size, in) == NULL)
655 fprintf(stderr, "\nError in reading or end of file.\n");
656}