978abebe654555ecf1ad4ef7cc81e75f75f963f7
[openwrt/staging/stintel.git] / scripts / config / conf.c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
4 */
5
6 #include <ctype.h>
7 #include <limits.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <time.h>
12 #include <unistd.h>
13 #include <getopt.h>
14 #include <sys/time.h>
15 #include <errno.h>
16
17 #include "lkc.h"
18
19 static void conf(struct menu *menu);
20 static void check_conf(struct menu *menu);
21
22 enum input_mode {
23 oldaskconfig,
24 syncconfig,
25 oldconfig,
26 allnoconfig,
27 allyesconfig,
28 allmodconfig,
29 alldefconfig,
30 randconfig,
31 defconfig,
32 savedefconfig,
33 listnewconfig,
34 helpnewconfig,
35 olddefconfig,
36 yes2modconfig,
37 mod2yesconfig,
38 fatalrecursive,
39 };
40 static enum input_mode input_mode = oldaskconfig;
41 static int input_mode_opt;
42 static int indent = 1;
43 static int tty_stdio;
44 static int sync_kconfig;
45 static int conf_cnt;
46 static char line[PATH_MAX];
47 static struct menu *rootEntry;
48
49 static void print_help(struct menu *menu)
50 {
51 struct gstr help = str_new();
52
53 menu_get_ext_help(menu, &help);
54
55 printf("\n%s\n", str_get(&help));
56 str_free(&help);
57 }
58
59 static void strip(char *str)
60 {
61 char *p = str;
62 int l;
63
64 while ((isspace(*p)))
65 p++;
66 l = strlen(p);
67 if (p != str)
68 memmove(str, p, l + 1);
69 if (!l)
70 return;
71 p = str + l - 1;
72 while ((isspace(*p)))
73 *p-- = 0;
74 }
75
76 /* Helper function to facilitate fgets() by Jean Sacren. */
77 static void xfgets(char *str, int size, FILE *in)
78 {
79 if (!fgets(str, size, in))
80 fprintf(stderr, "\nError in reading or end of file.\n");
81
82 if (!tty_stdio)
83 printf("%s", str);
84 }
85
86 static void set_randconfig_seed(void)
87 {
88 unsigned int seed;
89 char *env;
90 bool seed_set = false;
91
92 env = getenv("KCONFIG_SEED");
93 if (env && *env) {
94 char *endp;
95
96 seed = strtol(env, &endp, 0);
97 if (*endp == '\0')
98 seed_set = true;
99 }
100
101 if (!seed_set) {
102 struct timeval now;
103
104 /*
105 * Use microseconds derived seed, compensate for systems where it may
106 * be zero.
107 */
108 gettimeofday(&now, NULL);
109 seed = (now.tv_sec + 1) * (now.tv_usec + 1);
110 }
111
112 printf("KCONFIG_SEED=0x%X\n", seed);
113 srand(seed);
114 }
115
116 static bool randomize_choice_values(struct symbol *csym)
117 {
118 struct property *prop;
119 struct symbol *sym;
120 struct expr *e;
121 int cnt, def;
122
123 /*
124 * If choice is mod then we may have more items selected
125 * and if no then no-one.
126 * In both cases stop.
127 */
128 if (csym->curr.tri != yes)
129 return false;
130
131 prop = sym_get_choice_prop(csym);
132
133 /* count entries in choice block */
134 cnt = 0;
135 expr_list_for_each_sym(prop->expr, e, sym)
136 cnt++;
137
138 /*
139 * find a random value and set it to yes,
140 * set the rest to no so we have only one set
141 */
142 def = rand() % cnt;
143
144 cnt = 0;
145 expr_list_for_each_sym(prop->expr, e, sym) {
146 if (def == cnt++) {
147 sym->def[S_DEF_USER].tri = yes;
148 csym->def[S_DEF_USER].val = sym;
149 } else {
150 sym->def[S_DEF_USER].tri = no;
151 }
152 sym->flags |= SYMBOL_DEF_USER;
153 /* clear VALID to get value calculated */
154 sym->flags &= ~SYMBOL_VALID;
155 }
156 csym->flags |= SYMBOL_DEF_USER;
157 /* clear VALID to get value calculated */
158 csym->flags &= ~SYMBOL_VALID;
159
160 return true;
161 }
162
163 enum conf_def_mode {
164 def_default,
165 def_yes,
166 def_mod,
167 def_y2m,
168 def_m2y,
169 def_no,
170 def_random
171 };
172
173 static bool conf_set_all_new_symbols(enum conf_def_mode mode)
174 {
175 struct symbol *sym, *csym;
176 int i, cnt;
177 /*
178 * can't go as the default in switch-case below, otherwise gcc whines
179 * about -Wmaybe-uninitialized
180 */
181 int pby = 50; /* probability of bool = y */
182 int pty = 33; /* probability of tristate = y */
183 int ptm = 33; /* probability of tristate = m */
184 bool has_changed = false;
185
186 if (mode == def_random) {
187 int n, p[3];
188 char *env = getenv("KCONFIG_PROBABILITY");
189
190 n = 0;
191 while (env && *env) {
192 char *endp;
193 int tmp = strtol(env, &endp, 10);
194
195 if (tmp >= 0 && tmp <= 100) {
196 p[n++] = tmp;
197 } else {
198 errno = ERANGE;
199 perror("KCONFIG_PROBABILITY");
200 exit(1);
201 }
202 env = (*endp == ':') ? endp + 1 : endp;
203 if (n >= 3)
204 break;
205 }
206 switch (n) {
207 case 1:
208 pby = p[0];
209 ptm = pby / 2;
210 pty = pby - ptm;
211 break;
212 case 2:
213 pty = p[0];
214 ptm = p[1];
215 pby = pty + ptm;
216 break;
217 case 3:
218 pby = p[0];
219 pty = p[1];
220 ptm = p[2];
221 break;
222 }
223
224 if (pty + ptm > 100) {
225 errno = ERANGE;
226 perror("KCONFIG_PROBABILITY");
227 exit(1);
228 }
229 }
230
231 sym_clear_all_valid();
232
233 for_all_symbols(i, sym) {
234 if (sym_has_value(sym) || sym->flags & SYMBOL_VALID)
235 continue;
236 switch (sym_get_type(sym)) {
237 case S_BOOLEAN:
238 case S_TRISTATE:
239 has_changed = true;
240 switch (mode) {
241 case def_yes:
242 sym->def[S_DEF_USER].tri = yes;
243 break;
244 case def_mod:
245 sym->def[S_DEF_USER].tri = mod;
246 break;
247 case def_no:
248 sym->def[S_DEF_USER].tri = no;
249 break;
250 case def_random:
251 sym->def[S_DEF_USER].tri = no;
252 cnt = rand() % 100;
253 if (sym->type == S_TRISTATE) {
254 if (cnt < pty)
255 sym->def[S_DEF_USER].tri = yes;
256 else if (cnt < pty + ptm)
257 sym->def[S_DEF_USER].tri = mod;
258 } else if (cnt < pby)
259 sym->def[S_DEF_USER].tri = yes;
260 break;
261 default:
262 continue;
263 }
264 if (!(sym_is_choice(sym) && mode == def_random))
265 sym->flags |= SYMBOL_DEF_USER;
266 break;
267 default:
268 break;
269 }
270
271 }
272
273 /*
274 * We have different type of choice blocks.
275 * If curr.tri equals to mod then we can select several
276 * choice symbols in one block.
277 * In this case we do nothing.
278 * If curr.tri equals yes then only one symbol can be
279 * selected in a choice block and we set it to yes,
280 * and the rest to no.
281 */
282 if (mode != def_random) {
283 for_all_symbols(i, csym) {
284 if ((sym_is_choice(csym) && !sym_has_value(csym)) ||
285 sym_is_choice_value(csym))
286 csym->flags |= SYMBOL_NEED_SET_CHOICE_VALUES;
287 }
288 }
289
290 for_all_symbols(i, csym) {
291 if (sym_has_value(csym) || !sym_is_choice(csym))
292 continue;
293
294 sym_calc_value(csym);
295 if (mode == def_random)
296 has_changed |= randomize_choice_values(csym);
297 else {
298 set_all_choice_values(csym);
299 has_changed = true;
300 }
301 }
302
303 return has_changed;
304 }
305
306 static void conf_rewrite_mod_or_yes(enum conf_def_mode mode)
307 {
308 struct symbol *sym;
309 int i;
310 tristate old_val = (mode == def_y2m) ? yes : mod;
311 tristate new_val = (mode == def_y2m) ? mod : yes;
312
313 for_all_symbols(i, sym) {
314 if (sym_get_type(sym) == S_TRISTATE &&
315 sym->def[S_DEF_USER].tri == old_val)
316 sym->def[S_DEF_USER].tri = new_val;
317 }
318 sym_clear_all_valid();
319 }
320
321 static int conf_askvalue(struct symbol *sym, const char *def)
322 {
323 if (!sym_has_value(sym))
324 printf("(NEW) ");
325
326 line[0] = '\n';
327 line[1] = 0;
328
329 if (!sym_is_changeable(sym)) {
330 printf("%s\n", def);
331 line[0] = '\n';
332 line[1] = 0;
333 return 0;
334 }
335
336 switch (input_mode) {
337 case oldconfig:
338 case syncconfig:
339 if (sym_has_value(sym)) {
340 printf("%s\n", def);
341 return 0;
342 }
343 /* fall through */
344 default:
345 fflush(stdout);
346 xfgets(line, sizeof(line), stdin);
347 break;
348 }
349
350 return 1;
351 }
352
353 static int conf_string(struct menu *menu)
354 {
355 struct symbol *sym = menu->sym;
356 const char *def;
357
358 while (1) {
359 printf("%*s%s ", indent - 1, "", menu->prompt->text);
360 printf("(%s) ", sym->name);
361 def = sym_get_string_value(sym);
362 if (def)
363 printf("[%s] ", def);
364 if (!conf_askvalue(sym, def))
365 return 0;
366 switch (line[0]) {
367 case '\n':
368 break;
369 case '?':
370 /* print help */
371 if (line[1] == '\n') {
372 print_help(menu);
373 def = NULL;
374 break;
375 }
376 /* fall through */
377 default:
378 line[strlen(line)-1] = 0;
379 def = line;
380 }
381 if (def && sym_set_string_value(sym, def))
382 return 0;
383 }
384 }
385
386 static int conf_sym(struct menu *menu)
387 {
388 struct symbol *sym = menu->sym;
389 tristate oldval, newval;
390
391 while (1) {
392 printf("%*s%s ", indent - 1, "", menu->prompt->text);
393 if (sym->name)
394 printf("(%s) ", sym->name);
395 putchar('[');
396 oldval = sym_get_tristate_value(sym);
397 switch (oldval) {
398 case no:
399 putchar('N');
400 break;
401 case mod:
402 putchar('M');
403 break;
404 case yes:
405 putchar('Y');
406 break;
407 }
408 if (oldval != no && sym_tristate_within_range(sym, no))
409 printf("/n");
410 if (oldval != mod && sym_tristate_within_range(sym, mod))
411 printf("/m");
412 if (oldval != yes && sym_tristate_within_range(sym, yes))
413 printf("/y");
414 printf("/?] ");
415 if (!conf_askvalue(sym, sym_get_string_value(sym)))
416 return 0;
417 strip(line);
418
419 switch (line[0]) {
420 case 'n':
421 case 'N':
422 newval = no;
423 if (!line[1] || !strcmp(&line[1], "o"))
424 break;
425 continue;
426 case 'm':
427 case 'M':
428 newval = mod;
429 if (!line[1])
430 break;
431 continue;
432 case 'y':
433 case 'Y':
434 newval = yes;
435 if (!line[1] || !strcmp(&line[1], "es"))
436 break;
437 continue;
438 case 0:
439 newval = oldval;
440 break;
441 case '?':
442 goto help;
443 default:
444 continue;
445 }
446 if (sym_set_tristate_value(sym, newval))
447 return 0;
448 help:
449 print_help(menu);
450 }
451 }
452
453 static int conf_choice(struct menu *menu)
454 {
455 struct symbol *sym, *def_sym;
456 struct menu *child;
457 bool is_new;
458
459 sym = menu->sym;
460 is_new = !sym_has_value(sym);
461 if (sym_is_changeable(sym)) {
462 conf_sym(menu);
463 sym_calc_value(sym);
464 switch (sym_get_tristate_value(sym)) {
465 case no:
466 return 1;
467 case mod:
468 return 0;
469 case yes:
470 break;
471 }
472 } else {
473 switch (sym_get_tristate_value(sym)) {
474 case no:
475 return 1;
476 case mod:
477 printf("%*s%s\n", indent - 1, "", menu_get_prompt(menu));
478 return 0;
479 case yes:
480 break;
481 }
482 }
483
484 while (1) {
485 int cnt, def;
486
487 printf("%*s%s\n", indent - 1, "", menu_get_prompt(menu));
488 def_sym = sym_get_choice_value(sym);
489 cnt = def = 0;
490 line[0] = 0;
491 for (child = menu->list; child; child = child->next) {
492 if (!menu_is_visible(child))
493 continue;
494 if (!child->sym) {
495 printf("%*c %s\n", indent, '*', menu_get_prompt(child));
496 continue;
497 }
498 cnt++;
499 if (child->sym == def_sym) {
500 def = cnt;
501 printf("%*c", indent, '>');
502 } else
503 printf("%*c", indent, ' ');
504 printf(" %d. %s", cnt, menu_get_prompt(child));
505 if (child->sym->name)
506 printf(" (%s)", child->sym->name);
507 if (!sym_has_value(child->sym))
508 printf(" (NEW)");
509 printf("\n");
510 }
511 printf("%*schoice", indent - 1, "");
512 if (cnt == 1) {
513 printf("[1]: 1\n");
514 goto conf_childs;
515 }
516 printf("[1-%d?]: ", cnt);
517 switch (input_mode) {
518 case oldconfig:
519 case syncconfig:
520 if (!is_new) {
521 cnt = def;
522 printf("%d\n", cnt);
523 break;
524 }
525 /* fall through */
526 case oldaskconfig:
527 fflush(stdout);
528 xfgets(line, sizeof(line), stdin);
529 strip(line);
530 if (line[0] == '?') {
531 print_help(menu);
532 continue;
533 }
534 if (!line[0])
535 cnt = def;
536 else if (isdigit(line[0]))
537 cnt = atoi(line);
538 else
539 continue;
540 break;
541 default:
542 break;
543 }
544
545 conf_childs:
546 for (child = menu->list; child; child = child->next) {
547 if (!child->sym || !menu_is_visible(child))
548 continue;
549 if (!--cnt)
550 break;
551 }
552 if (!child)
553 continue;
554 if (line[0] && line[strlen(line) - 1] == '?') {
555 print_help(child);
556 continue;
557 }
558 sym_set_choice_value(sym, child->sym);
559 for (child = child->list; child; child = child->next) {
560 indent += 2;
561 conf(child);
562 indent -= 2;
563 }
564 return 1;
565 }
566 }
567
568 static void conf(struct menu *menu)
569 {
570 struct symbol *sym;
571 struct property *prop;
572 struct menu *child;
573
574 if (!menu_is_visible(menu))
575 return;
576
577 sym = menu->sym;
578 prop = menu->prompt;
579 if (prop) {
580 const char *prompt;
581
582 switch (prop->type) {
583 case P_MENU:
584 /*
585 * Except in oldaskconfig mode, we show only menus that
586 * contain new symbols.
587 */
588 if (input_mode != oldaskconfig && rootEntry != menu) {
589 check_conf(menu);
590 return;
591 }
592 /* fall through */
593 case P_COMMENT:
594 prompt = menu_get_prompt(menu);
595 if (prompt)
596 printf("%*c\n%*c %s\n%*c\n",
597 indent, '*',
598 indent, '*', prompt,
599 indent, '*');
600 default:
601 ;
602 }
603 }
604
605 if (!sym)
606 goto conf_childs;
607
608 if (sym_is_choice(sym)) {
609 conf_choice(menu);
610 if (sym->curr.tri != mod)
611 return;
612 goto conf_childs;
613 }
614
615 switch (sym->type) {
616 case S_INT:
617 case S_HEX:
618 case S_STRING:
619 conf_string(menu);
620 break;
621 default:
622 conf_sym(menu);
623 break;
624 }
625
626 conf_childs:
627 if (sym)
628 indent += 2;
629 for (child = menu->list; child; child = child->next)
630 conf(child);
631 if (sym)
632 indent -= 2;
633 }
634
635 static void check_conf(struct menu *menu)
636 {
637 struct symbol *sym;
638 struct menu *child;
639
640 if (!menu_is_visible(menu))
641 return;
642
643 sym = menu->sym;
644 if (sym && !sym_has_value(sym) &&
645 (sym_is_changeable(sym) ||
646 (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes))) {
647
648 switch (input_mode) {
649 case listnewconfig:
650 if (sym->name) {
651 const char *str;
652
653 if (sym->type == S_STRING) {
654 str = sym_get_string_value(sym);
655 str = sym_escape_string_value(str);
656 printf("%s%s=%s\n", CONFIG_, sym->name, str);
657 free((void *)str);
658 } else {
659 str = sym_get_string_value(sym);
660 printf("%s%s=%s\n", CONFIG_, sym->name, str);
661 }
662 }
663 break;
664 case helpnewconfig:
665 printf("-----\n");
666 print_help(menu);
667 printf("-----\n");
668 break;
669 default:
670 if (!conf_cnt++)
671 printf("*\n* Restart config...\n*\n");
672 rootEntry = menu_get_parent_menu(menu);
673 conf(rootEntry);
674 break;
675 }
676 }
677
678 for (child = menu->list; child; child = child->next)
679 check_conf(child);
680 }
681
682 static const struct option long_opts[] = {
683 {"help", no_argument, NULL, 'h'},
684 {"silent", no_argument, NULL, 's'},
685 {"oldaskconfig", no_argument, &input_mode_opt, oldaskconfig},
686 {"oldconfig", no_argument, &input_mode_opt, oldconfig},
687 {"syncconfig", no_argument, &input_mode_opt, syncconfig},
688 {"defconfig", required_argument, &input_mode_opt, defconfig},
689 {"savedefconfig", required_argument, &input_mode_opt, savedefconfig},
690 {"allnoconfig", no_argument, &input_mode_opt, allnoconfig},
691 {"allyesconfig", no_argument, &input_mode_opt, allyesconfig},
692 {"allmodconfig", no_argument, &input_mode_opt, allmodconfig},
693 {"alldefconfig", no_argument, &input_mode_opt, alldefconfig},
694 {"randconfig", no_argument, &input_mode_opt, randconfig},
695 {"listnewconfig", no_argument, &input_mode_opt, listnewconfig},
696 {"helpnewconfig", no_argument, &input_mode_opt, helpnewconfig},
697 {"olddefconfig", no_argument, &input_mode_opt, olddefconfig},
698 {"yes2modconfig", no_argument, &input_mode_opt, yes2modconfig},
699 {"mod2yesconfig", no_argument, &input_mode_opt, mod2yesconfig},
700 {"fatalrecursive",no_argument, NULL, fatalrecursive},
701 {NULL, 0, NULL, 0}
702 };
703
704 static void conf_usage(const char *progname)
705 {
706 printf("Usage: %s [options] <kconfig-file>\n", progname);
707 printf("\n");
708 printf("Generic options:\n");
709 printf(" -h, --help Print this message and exit.\n");
710 printf(" -s, --silent Do not print log.\n");
711 printf(" --fatalrecursive Treat recursive depenendencies as a fatal error\n");
712 printf("\n");
713 printf("Mode options:\n");
714 printf(" --listnewconfig List new options\n");
715 printf(" --helpnewconfig List new options and help text\n");
716 printf(" --oldaskconfig Start a new configuration using a line-oriented program\n");
717 printf(" --oldconfig Update a configuration using a provided .config as base\n");
718 printf(" --syncconfig Similar to oldconfig but generates configuration in\n"
719 " include/{generated/,config/}\n");
720 printf(" --olddefconfig Same as oldconfig but sets new symbols to their default value\n");
721 printf(" --defconfig <file> New config with default defined in <file>\n");
722 printf(" --savedefconfig <file> Save the minimal current configuration to <file>\n");
723 printf(" --allnoconfig New config where all options are answered with no\n");
724 printf(" --allyesconfig New config where all options are answered with yes\n");
725 printf(" --allmodconfig New config where all options are answered with mod\n");
726 printf(" --alldefconfig New config with all symbols set to default\n");
727 printf(" --randconfig New config with random answer to all options\n");
728 printf(" --yes2modconfig Change answers from yes to mod if possible\n");
729 printf(" --mod2yesconfig Change answers from mod to yes if possible\n");
730 printf(" (If none of the above is given, --oldaskconfig is the default)\n");
731 }
732
733 int main(int ac, char **av)
734 {
735 const char *progname = av[0];
736 int opt;
737 const char *name, *defconfig_file = NULL /* gcc uninit */;
738 const char *input_file = NULL, *output_file = NULL;
739 int no_conf_write = 0;
740
741 tty_stdio = isatty(0) && isatty(1);
742
743 while ((opt = getopt_long(ac, av, "hr:sw:", long_opts, NULL)) != -1) {
744 switch (opt) {
745 case 'h':
746 conf_usage(progname);
747 exit(1);
748 break;
749 case 's':
750 conf_set_message_callback(NULL);
751 break;
752 case fatalrecursive:
753 recursive_is_error = 1;
754 continue;
755 case 'r':
756 input_file = optarg;
757 break;
758 case 'w':
759 output_file = optarg;
760 break;
761 case 0:
762 input_mode = input_mode_opt;
763 switch (input_mode) {
764 case syncconfig:
765 /*
766 * syncconfig is invoked during the build stage.
767 * Suppress distracting
768 * "configuration written to ..."
769 */
770 conf_set_message_callback(NULL);
771 sync_kconfig = 1;
772 break;
773 case defconfig:
774 case savedefconfig:
775 defconfig_file = optarg;
776 break;
777 case randconfig:
778 set_randconfig_seed();
779 break;
780 default:
781 break;
782 }
783 default:
784 break;
785 }
786 }
787 if (ac == optind) {
788 fprintf(stderr, "%s: Kconfig file missing\n", av[0]);
789 conf_usage(progname);
790 exit(1);
791 }
792 conf_parse(av[optind]);
793 //zconfdump(stdout);
794
795 switch (input_mode) {
796 case defconfig:
797 if (conf_read(defconfig_file)) {
798 fprintf(stderr,
799 "***\n"
800 "*** Can't find default configuration \"%s\"!\n"
801 "***\n",
802 defconfig_file);
803 exit(1);
804 }
805 break;
806 case savedefconfig:
807 case syncconfig:
808 case oldaskconfig:
809 case oldconfig:
810 case listnewconfig:
811 case helpnewconfig:
812 case olddefconfig:
813 case yes2modconfig:
814 case mod2yesconfig:
815 case allnoconfig:
816 case allyesconfig:
817 case allmodconfig:
818 case alldefconfig:
819 case randconfig:
820 conf_read(input_file);
821 break;
822 default:
823 break;
824 }
825
826 if (sync_kconfig) {
827 name = getenv("KCONFIG_NOSILENTUPDATE");
828 if (name && *name) {
829 if (conf_get_changed()) {
830 fprintf(stderr,
831 "\n*** The configuration requires explicit update.\n\n");
832 return 1;
833 }
834 no_conf_write = 1;
835 }
836 }
837
838 switch (input_mode) {
839 case allnoconfig:
840 conf_set_all_new_symbols(def_no);
841 break;
842 case allyesconfig:
843 conf_set_all_new_symbols(def_yes);
844 break;
845 case allmodconfig:
846 conf_set_all_new_symbols(def_mod);
847 break;
848 case alldefconfig:
849 conf_set_all_new_symbols(def_default);
850 break;
851 case randconfig:
852 /* Really nothing to do in this loop */
853 while (conf_set_all_new_symbols(def_random)) ;
854 break;
855 case defconfig:
856 conf_set_all_new_symbols(def_default);
857 break;
858 case savedefconfig:
859 break;
860 case yes2modconfig:
861 conf_rewrite_mod_or_yes(def_y2m);
862 break;
863 case mod2yesconfig:
864 conf_rewrite_mod_or_yes(def_m2y);
865 break;
866 case oldaskconfig:
867 rootEntry = &rootmenu;
868 conf(&rootmenu);
869 input_mode = oldconfig;
870 /* fall through */
871 case oldconfig:
872 case listnewconfig:
873 case helpnewconfig:
874 case syncconfig:
875 /* Update until a loop caused no more changes */
876 do {
877 conf_cnt = 0;
878 check_conf(&rootmenu);
879 } while (conf_cnt);
880 break;
881 case olddefconfig:
882 default:
883 break;
884 }
885
886 if (input_mode == savedefconfig) {
887 if (conf_write_defconfig(defconfig_file)) {
888 fprintf(stderr, "n*** Error while saving defconfig to: %s\n\n",
889 defconfig_file);
890 return 1;
891 }
892 } else if (input_mode != listnewconfig && input_mode != helpnewconfig) {
893 if ((output_file || !no_conf_write) &&
894 conf_write(output_file)) {
895 fprintf(stderr, "\n*** Error during writing of the configuration.\n\n");
896 exit(1);
897 }
898
899 /*
900 * Create auto.conf if it does not exist.
901 * This prevents GNU Make 4.1 or older from emitting
902 * "include/config/auto.conf: No such file or directory"
903 * in the top-level Makefile
904 *
905 * syncconfig always creates or updates auto.conf because it is
906 * used during the build.
907 */
908 if (conf_write_autoconf(sync_kconfig) && sync_kconfig) {
909 fprintf(stderr,
910 "\n*** Error during sync of the configuration.\n\n");
911 return 1;
912 }
913 }
914 return 0;
915 }