Commit 4062f1a4c030157216dc8932e27131975cf7253c

Authored by Sam Ravnborg
Committed by Michal Marek
1 parent ac1ffde1ba

kconfig: use long options in conf

The list of options supported by conf is growing
and their abbreviation did not resemble anything usefull.

So drop the single letter options in favour of long options.

The long options are named equal to what we know from
the make target.
The internal implmentation was changed to match this,
resulting in much more readable code.

Support for short options is dropped - no one is supposed
to call this program direct anyway.

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Signed-off-by: Michal Marek <mmarek@suse.cz>

Showing 2 changed files with 105 additions and 126 deletions Side-by-side Diff

scripts/kconfig/Makefile
... ... @@ -21,53 +21,47 @@
21 21 $< $(Kconfig)
22 22  
23 23 config: $(obj)/conf
24   - $< $(Kconfig)
  24 + $< --oldaskconfig $(Kconfig)
25 25  
26 26 nconfig: $(obj)/nconf
27 27 $< $(Kconfig)
28 28  
29 29 oldconfig: $(obj)/conf
30   - $< -o $(Kconfig)
  30 + $< --$@ $(Kconfig)
31 31  
32 32 silentoldconfig: $(obj)/conf
33 33 $(Q)mkdir -p include/generated
34   - $< -s $(Kconfig)
  34 + $< --$@ $(Kconfig)
35 35  
36 36 localmodconfig: $(obj)/streamline_config.pl $(obj)/conf
37 37 $(Q)perl $< $(srctree) $(Kconfig) > .tmp.config
38   - $(Q)if [ -f .config ]; then \
39   - cmp -s .tmp.config .config || \
40   - (mv -f .config .config.old.1; \
41   - mv -f .tmp.config .config; \
42   - $(obj)/conf -s $(Kconfig); \
43   - mv -f .config.old.1 .config.old) \
44   - else \
45   - mv -f .tmp.config .config; \
46   - $(obj)/conf -s $(Kconfig); \
  38 + $(Q)if [ -f .config ]; then \
  39 + cmp -s .tmp.config .config || \
  40 + (mv -f .config .config.old.1; \
  41 + mv -f .tmp.config .config; \
  42 + $(obj)/conf --silentoldconfig $(Kconfig); \
  43 + mv -f .config.old.1 .config.old) \
  44 + else \
  45 + mv -f .tmp.config .config; \
  46 + $(obj)/conf --silentoldconfig $(Kconfig); \
47 47 fi
48 48 $(Q)rm -f .tmp.config
49 49  
50 50 localyesconfig: $(obj)/streamline_config.pl $(obj)/conf
51 51 $(Q)perl $< $(srctree) $(Kconfig) > .tmp.config
52 52 $(Q)sed -i s/=m/=y/ .tmp.config
53   - $(Q)if [ -f .config ]; then \
54   - cmp -s .tmp.config .config || \
55   - (mv -f .config .config.old.1; \
56   - mv -f .tmp.config .config; \
57   - $(obj)/conf -s $(Kconfig); \
58   - mv -f .config.old.1 .config.old) \
59   - else \
60   - mv -f .tmp.config .config; \
61   - $(obj)/conf -s $(Kconfig); \
  53 + $(Q)if [ -f .config ]; then \
  54 + cmp -s .tmp.config .config || \
  55 + (mv -f .config .config.old.1; \
  56 + mv -f .tmp.config .config; \
  57 + $(obj)/conf --silentoldconfig $(Kconfig); \
  58 + mv -f .config.old.1 .config.old) \
  59 + else \
  60 + mv -f .tmp.config .config; \
  61 + $(obj)/conf --silentoldconfig $(Kconfig); \
62 62 fi
63 63 $(Q)rm -f .tmp.config
64 64  
65   -nonint_oldconfig: $(obj)/conf
66   - $< -b $(Kconfig)
67   -
68   -loose_nonint_oldconfig: $(obj)/conf
69   - $< -B $(Kconfig)
70   -
71 65 # Create new linux.pot file
72 66 # Adjust charset to UTF-8 in .po file to accept UTF-8 in Kconfig files
73 67 # The symlink is used to repair a deficiency in arch/um
74 68  
75 69  
76 70  
77 71  
78 72  
79 73  
80 74  
... ... @@ -91,30 +85,26 @@
91 85 $(Q)rm -f arch/um/Kconfig.arch
92 86 $(Q)rm -f $(obj)/config.pot
93 87  
94   -PHONY += randconfig allyesconfig allnoconfig allmodconfig defconfig
  88 +PHONY += allnoconfig allyesconfig allmodconfig randconfig
95 89  
96   -randconfig: $(obj)/conf
97   - $< -r $(Kconfig)
  90 +allnoconfig allyesconfig allmodconfig randconfig: $(obj)/conf
  91 + $< --$@ $(Kconfig)
98 92  
99   -allyesconfig: $(obj)/conf
100   - $< -y $(Kconfig)
  93 +PHONY += nonint_oldconfig loose_nonint_oldconfig defconfig
101 94  
102   -allnoconfig: $(obj)/conf
103   - $< -n $(Kconfig)
  95 +nonint_oldconfig loose_nonint_oldconfig: $(obj)/conf
  96 + $< --$@ $(Kconfig)
104 97  
105   -allmodconfig: $(obj)/conf
106   - $< -m $(Kconfig)
107   -
108 98 defconfig: $(obj)/conf
109 99 ifeq ($(KBUILD_DEFCONFIG),)
110   - $< -d $(Kconfig)
  100 + $< --defconfig $(Kconfig)
111 101 else
112 102 @echo "*** Default configuration is based on '$(KBUILD_DEFCONFIG)'"
113   - $(Q)$< -D arch/$(SRCARCH)/configs/$(KBUILD_DEFCONFIG) $(Kconfig)
  103 + $(Q)$< --defconfig=arch/$(SRCARCH)/configs/$(KBUILD_DEFCONFIG) $(Kconfig)
114 104 endif
115 105  
116 106 %_defconfig: $(obj)/conf
117   - $(Q)$< -D arch/$(SRCARCH)/configs/$@ $(Kconfig)
  107 + $(Q)$< --defconfig=arch/$(SRCARCH)/configs/$@ $(Kconfig)
118 108  
119 109 # Help text used by make help
120 110 help:
scripts/kconfig/conf.c
... ... @@ -10,6 +10,7 @@
10 10 #include <string.h>
11 11 #include <time.h>
12 12 #include <unistd.h>
  13 +#include <getopt.h>
13 14 #include <sys/stat.h>
14 15 #include <sys/time.h>
15 16  
... ... @@ -23,18 +24,19 @@
23 24 static void conf(struct menu *menu);
24 25 static void check_conf(struct menu *menu);
25 26  
26   -enum {
27   - ask_all,
28   - ask_new,
29   - ask_silent,
30   - dont_ask,
31   - dont_ask_dont_tell,
32   - set_default,
33   - set_yes,
34   - set_mod,
35   - set_no,
36   - set_random
37   -} input_mode = ask_all;
  27 +enum input_mode {
  28 + oldaskconfig,
  29 + silentoldconfig,
  30 + oldconfig,
  31 + allnoconfig,
  32 + allyesconfig,
  33 + allmodconfig,
  34 + randconfig,
  35 + defconfig,
  36 + nonint_oldconfig,
  37 + loose_nonint_oldconfig,
  38 +} input_mode = oldaskconfig;
  39 +
38 40 char *defconfig_file;
39 41  
40 42 static int indent = 1;
41 43  
... ... @@ -100,14 +102,14 @@
100 102 }
101 103  
102 104 switch (input_mode) {
103   - case ask_new:
104   - case ask_silent:
  105 + case oldconfig:
  106 + case silentoldconfig:
105 107 if (sym_has_value(sym)) {
106 108 printf("%s\n", def);
107 109 return 0;
108 110 }
109 111 check_stdin();
110   - case ask_all:
  112 + case oldaskconfig:
111 113 fflush(stdout);
112 114 fgets(line, 128, stdin);
113 115 return 1;
114 116  
... ... @@ -297,15 +299,15 @@
297 299 printf("?");
298 300 printf("]: ");
299 301 switch (input_mode) {
300   - case ask_new:
301   - case ask_silent:
  302 + case oldconfig:
  303 + case silentoldconfig:
302 304 if (!is_new) {
303 305 cnt = def;
304 306 printf("%d\n", cnt);
305 307 break;
306 308 }
307 309 check_stdin();
308   - case ask_all:
  310 + case oldaskconfig:
309 311 fflush(stdout);
310 312 fgets(line, 128, stdin);
311 313 strip(line);
... ... @@ -363,9 +365,9 @@
363 365  
364 366 switch (prop->type) {
365 367 case P_MENU:
366   - if ((input_mode == ask_silent ||
367   - input_mode == dont_ask ||
368   - input_mode == dont_ask_dont_tell) &&
  368 + if ((input_mode == silentoldconfig ||
  369 + input_mode == nonint_oldconfig ||
  370 + input_mode == loose_nonint_oldconfig) &&
369 371 rootEntry != menu) {
370 372 check_conf(menu);
371 373 return;
... ... @@ -424,9 +426,9 @@
424 426 if (sym && !sym_has_value(sym)) {
425 427 if (sym_is_changable(sym) ||
426 428 (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)) {
427   - if (input_mode == dont_ask ||
428   - input_mode == dont_ask_dont_tell) {
429   - if (input_mode == dont_ask &&
  429 + if (input_mode == nonint_oldconfig ||
  430 + input_mode == loose_nonint_oldconfig) {
  431 + if (input_mode == nonint_oldconfig &&
430 432 sym->name && !sym_is_choice_value(sym)) {
431 433 if (!unset_variables)
432 434 fprintf(stderr, "The following"
... ... @@ -448,6 +450,20 @@
448 450 check_conf(child);
449 451 }
450 452  
  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 + {"loose_nonint_oldconfig", no_argument, NULL, loose_nonint_oldconfig},
  464 + {NULL, 0, NULL, 0}
  465 +};
  466 +
451 467 int main(int ac, char **av)
452 468 {
453 469 int opt;
454 470  
455 471  
456 472  
... ... @@ -458,38 +474,16 @@
458 474 bindtextdomain(PACKAGE, LOCALEDIR);
459 475 textdomain(PACKAGE);
460 476  
461   - while ((opt = getopt(ac, av, "osbBdD:nmyrh")) != -1) {
  477 + while ((opt = getopt_long_only(ac, av, "", long_opts, NULL)) != -1) {
  478 + input_mode = (enum input_mode)opt;
462 479 switch (opt) {
463   - case 'o':
464   - input_mode = ask_silent;
465   - break;
466   - case 's':
467   - input_mode = ask_silent;
  480 + case silentoldconfig:
468 481 sync_kconfig = 1;
469 482 break;
470   - case 'b':
471   - input_mode = dont_ask;
472   - break;
473   - case 'B':
474   - input_mode = dont_ask_dont_tell;
475   - break;
476   - case 'd':
477   - input_mode = set_default;
478   - break;
479   - case 'D':
480   - input_mode = set_default;
  483 + case defconfig:
481 484 defconfig_file = optarg;
482 485 break;
483   - case 'n':
484   - input_mode = set_no;
485   - break;
486   - case 'm':
487   - input_mode = set_mod;
488   - break;
489   - case 'y':
490   - input_mode = set_yes;
491   - break;
492   - case 'r':
  486 + case randconfig:
493 487 {
494 488 struct timeval now;
495 489 unsigned int seed;
496 490  
497 491  
... ... @@ -502,17 +496,12 @@
502 496  
503 497 seed = (unsigned int)((now.tv_sec + 1) * (now.tv_usec + 1));
504 498 srand(seed);
505   -
506   - input_mode = set_random;
507 499 break;
508 500 }
509   - case 'h':
510   - printf(_("See README for usage info\n"));
511   - exit(0);
512   - break;
513   - default:
  501 + case '?':
514 502 fprintf(stderr, _("See README for usage info\n"));
515 503 exit(1);
  504 + break;
516 505 }
517 506 }
518 507 if (ac == optind) {
... ... @@ -537,7 +526,7 @@
537 526 }
538 527  
539 528 switch (input_mode) {
540   - case set_default:
  529 + case defconfig:
541 530 if (!defconfig_file)
542 531 defconfig_file = conf_get_default_confname();
543 532 if (conf_read(defconfig_file)) {
544 533  
545 534  
... ... @@ -547,27 +536,27 @@
547 536 exit(1);
548 537 }
549 538 break;
550   - case ask_silent:
551   - case ask_all:
552   - case ask_new:
553   - case dont_ask:
554   - case dont_ask_dont_tell:
  539 + case silentoldconfig:
  540 + case oldaskconfig:
  541 + case oldconfig:
  542 + case nonint_oldconfig:
  543 + case loose_nonint_oldconfig:
555 544 conf_read(NULL);
556 545 break;
557   - case set_no:
558   - case set_mod:
559   - case set_yes:
560   - case set_random:
  546 + case allnoconfig:
  547 + case allyesconfig:
  548 + case allmodconfig:
  549 + case randconfig:
561 550 name = getenv("KCONFIG_ALLCONFIG");
562 551 if (name && !stat(name, &tmpstat)) {
563 552 conf_read_simple(name, S_DEF_USER);
564 553 break;
565 554 }
566 555 switch (input_mode) {
567   - case set_no: name = "allno.config"; break;
568   - case set_mod: name = "allmod.config"; break;
569   - case set_yes: name = "allyes.config"; break;
570   - case set_random: name = "allrandom.config"; break;
  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;
571 560 default: break;
572 561 }
573 562 if (!stat(name, &tmpstat))
574 563  
575 564  
576 565  
577 566  
578 567  
579 568  
580 569  
581 570  
... ... @@ -592,37 +581,37 @@
592 581 }
593 582  
594 583 switch (input_mode) {
595   - case set_no:
  584 + case allnoconfig:
596 585 conf_set_all_new_symbols(def_no);
597 586 break;
598   - case set_yes:
  587 + case allyesconfig:
599 588 conf_set_all_new_symbols(def_yes);
600 589 break;
601   - case set_mod:
  590 + case allmodconfig:
602 591 conf_set_all_new_symbols(def_mod);
603 592 break;
604   - case set_random:
  593 + case randconfig:
605 594 conf_set_all_new_symbols(def_random);
606 595 break;
607   - case set_default:
  596 + case defconfig:
608 597 conf_set_all_new_symbols(def_default);
609 598 break;
610   - case ask_new:
611   - case ask_all:
  599 + case oldconfig:
  600 + case oldaskconfig:
612 601 rootEntry = &rootmenu;
613 602 conf(&rootmenu);
614   - input_mode = ask_silent;
  603 + input_mode = silentoldconfig;
615 604 /* fall through */
616   - case dont_ask:
617   - case dont_ask_dont_tell:
618   - case ask_silent:
  605 + case nonint_oldconfig:
  606 + case loose_nonint_oldconfig:
  607 + case silentoldconfig:
619 608 /* Update until a loop caused no more changes */
620 609 do {
621 610 conf_cnt = 0;
622 611 check_conf(&rootmenu);
623 612 } while (conf_cnt &&
624   - (input_mode != dont_ask &&
625   - input_mode != dont_ask_dont_tell));
  613 + (input_mode != nonint_oldconfig &&
  614 + input_mode != loose_nonint_oldconfig));
626 615 break;
627 616 }
628 617  
... ... @@ -638,7 +627,7 @@
638 627 fprintf(stderr, _("\n*** Error during update of the kernel configuration.\n\n"));
639 628 return 1;
640 629 }
641   - } else if (!unset_variables || input_mode != dont_ask) {
  630 + } else if (!unset_variables || input_mode != nonint_oldconfig) {
642 631 if (conf_write(NULL)) {
643 632 fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n"));
644 633 exit(1);