blob: 3fa4abf3b084a372847a005df2060292a92451ce [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
4 */
5
EGRY Gabor534a4502008-01-11 23:44:39 +01006#include <locale.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include <ctype.h>
Randy Dunlap9dfb5632006-04-18 22:21:53 -07008#include <stdio.h>
Ladislav Michl75ff4302008-01-09 16:36:19 +01009#include <stdlib.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <string.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <time.h>
Ladislav Michl75ff4302008-01-09 16:36:19 +010012#include <unistd.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <sys/stat.h>
Ingo Molnarb0fe5512009-03-12 15:15:31 +010014#include <sys/time.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
16#define LKC_DIRECT_LINK
17#include "lkc.h"
18
Aristeu Rozanskif0778c82010-05-06 12:48:34 -040019/* Return codes */
20#define EUNSETOPT 2 /* if -B and -b are used and unset config
21 * options were found */
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023static void conf(struct menu *menu);
24static void check_conf(struct menu *menu);
25
26enum {
27 ask_all,
28 ask_new,
29 ask_silent,
Aristeu Rozanskif0778c82010-05-06 12:48:34 -040030 dont_ask,
31 dont_ask_dont_tell,
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 set_default,
33 set_yes,
34 set_mod,
35 set_no,
36 set_random
37} input_mode = ask_all;
38char *defconfig_file;
39
40static int indent = 1;
41static int valid_stdin = 1;
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +020042static int sync_kconfig;
Linus Torvalds1da177e2005-04-16 15:20:36 -070043static int conf_cnt;
J.A. Magallon48b9d032005-06-25 14:59:22 -070044static char line[128];
Linus Torvalds1da177e2005-04-16 15:20:36 -070045static struct menu *rootEntry;
Aristeu Rozanskif0778c82010-05-06 12:48:34 -040046static int unset_variables;
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Cheng Renquan66c4bd82009-07-12 16:11:48 +080048static void print_help(struct menu *menu)
Sam Ravnborg03d29122007-07-21 00:00:36 +020049{
Cheng Renquan66c4bd82009-07-12 16:11:48 +080050 struct gstr help = str_new();
51
52 menu_get_ext_help(menu, &help);
53
54 printf("\n%s\n", str_get(&help));
55 str_free(&help);
Sam Ravnborg03d29122007-07-21 00:00:36 +020056}
57
J.A. Magallon48b9d032005-06-25 14:59:22 -070058static void strip(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -070059{
J.A. Magallon48b9d032005-06-25 14:59:22 -070060 char *p = str;
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 int l;
62
63 while ((isspace(*p)))
64 p++;
65 l = strlen(p);
66 if (p != str)
67 memmove(str, p, l + 1);
68 if (!l)
69 return;
70 p = str + l - 1;
71 while ((isspace(*p)))
72 *p-- = 0;
73}
74
75static void check_stdin(void)
76{
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +020077 if (!valid_stdin) {
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070078 printf(_("aborted!\n\n"));
79 printf(_("Console input/output is redirected. "));
80 printf(_("Run 'make oldconfig' to update configuration.\n\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 exit(1);
82 }
83}
84
Roman Zippelf82f3f92007-08-30 05:06:17 +020085static int conf_askvalue(struct symbol *sym, const char *def)
Linus Torvalds1da177e2005-04-16 15:20:36 -070086{
87 enum symbol_type type = sym_get_type(sym);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
89 if (!sym_has_value(sym))
EGRY Gabor534a4502008-01-11 23:44:39 +010090 printf(_("(NEW) "));
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92 line[0] = '\n';
93 line[1] = 0;
94
95 if (!sym_is_changable(sym)) {
96 printf("%s\n", def);
97 line[0] = '\n';
98 line[1] = 0;
Roman Zippelf82f3f92007-08-30 05:06:17 +020099 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 }
101
102 switch (input_mode) {
103 case ask_new:
104 case ask_silent:
105 if (sym_has_value(sym)) {
106 printf("%s\n", def);
Roman Zippelf82f3f92007-08-30 05:06:17 +0200107 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 }
109 check_stdin();
110 case ask_all:
111 fflush(stdout);
Roman Zippel59c6a3f2006-04-09 17:26:50 +0200112 fgets(line, 128, stdin);
Roman Zippelf82f3f92007-08-30 05:06:17 +0200113 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 default:
115 break;
116 }
117
118 switch (type) {
119 case S_INT:
120 case S_HEX:
121 case S_STRING:
122 printf("%s\n", def);
Roman Zippelf82f3f92007-08-30 05:06:17 +0200123 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 default:
125 ;
126 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 printf("%s", line);
Roman Zippelf82f3f92007-08-30 05:06:17 +0200128 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129}
130
Trevor Keith4356f482009-09-18 12:49:23 -0700131static int conf_string(struct menu *menu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132{
133 struct symbol *sym = menu->sym;
Sam Ravnborg03d29122007-07-21 00:00:36 +0200134 const char *def;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
136 while (1) {
EGRY Gabor534a4502008-01-11 23:44:39 +0100137 printf("%*s%s ", indent - 1, "", _(menu->prompt->text));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 printf("(%s) ", sym->name);
139 def = sym_get_string_value(sym);
140 if (sym_get_string_value(sym))
141 printf("[%s] ", def);
Roman Zippelf82f3f92007-08-30 05:06:17 +0200142 if (!conf_askvalue(sym, def))
143 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 switch (line[0]) {
145 case '\n':
146 break;
147 case '?':
148 /* print help */
149 if (line[1] == '\n') {
Cheng Renquan66c4bd82009-07-12 16:11:48 +0800150 print_help(menu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 def = NULL;
152 break;
153 }
154 default:
155 line[strlen(line)-1] = 0;
156 def = line;
157 }
158 if (def && sym_set_string_value(sym, def))
159 return 0;
160 }
161}
162
163static int conf_sym(struct menu *menu)
164{
165 struct symbol *sym = menu->sym;
166 int type;
167 tristate oldval, newval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
169 while (1) {
EGRY Gabor534a4502008-01-11 23:44:39 +0100170 printf("%*s%s ", indent - 1, "", _(menu->prompt->text));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 if (sym->name)
172 printf("(%s) ", sym->name);
173 type = sym_get_type(sym);
174 putchar('[');
175 oldval = sym_get_tristate_value(sym);
176 switch (oldval) {
177 case no:
178 putchar('N');
179 break;
180 case mod:
181 putchar('M');
182 break;
183 case yes:
184 putchar('Y');
185 break;
186 }
187 if (oldval != no && sym_tristate_within_range(sym, no))
188 printf("/n");
189 if (oldval != mod && sym_tristate_within_range(sym, mod))
190 printf("/m");
191 if (oldval != yes && sym_tristate_within_range(sym, yes))
192 printf("/y");
Sam Ravnborg03d29122007-07-21 00:00:36 +0200193 if (menu_has_help(menu))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 printf("/?");
195 printf("] ");
Roman Zippelf82f3f92007-08-30 05:06:17 +0200196 if (!conf_askvalue(sym, sym_get_string_value(sym)))
197 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 strip(line);
199
200 switch (line[0]) {
201 case 'n':
202 case 'N':
203 newval = no;
204 if (!line[1] || !strcmp(&line[1], "o"))
205 break;
206 continue;
207 case 'm':
208 case 'M':
209 newval = mod;
210 if (!line[1])
211 break;
212 continue;
213 case 'y':
214 case 'Y':
215 newval = yes;
216 if (!line[1] || !strcmp(&line[1], "es"))
217 break;
218 continue;
219 case 0:
220 newval = oldval;
221 break;
222 case '?':
223 goto help;
224 default:
225 continue;
226 }
227 if (sym_set_tristate_value(sym, newval))
228 return 0;
229help:
Cheng Renquan66c4bd82009-07-12 16:11:48 +0800230 print_help(menu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 }
232}
233
234static int conf_choice(struct menu *menu)
235{
236 struct symbol *sym, *def_sym;
237 struct menu *child;
238 int type;
239 bool is_new;
240
241 sym = menu->sym;
242 type = sym_get_type(sym);
243 is_new = !sym_has_value(sym);
244 if (sym_is_changable(sym)) {
245 conf_sym(menu);
246 sym_calc_value(sym);
247 switch (sym_get_tristate_value(sym)) {
248 case no:
249 return 1;
250 case mod:
251 return 0;
252 case yes:
253 break;
254 }
255 } else {
256 switch (sym_get_tristate_value(sym)) {
257 case no:
258 return 1;
259 case mod:
EGRY Gabor534a4502008-01-11 23:44:39 +0100260 printf("%*s%s\n", indent - 1, "", _(menu_get_prompt(menu)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 return 0;
262 case yes:
263 break;
264 }
265 }
266
267 while (1) {
268 int cnt, def;
269
EGRY Gabor534a4502008-01-11 23:44:39 +0100270 printf("%*s%s\n", indent - 1, "", _(menu_get_prompt(menu)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 def_sym = sym_get_choice_value(sym);
272 cnt = def = 0;
Roman Zippel40aee722006-04-09 17:26:39 +0200273 line[0] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 for (child = menu->list; child; child = child->next) {
275 if (!menu_is_visible(child))
276 continue;
277 if (!child->sym) {
EGRY Gabor534a4502008-01-11 23:44:39 +0100278 printf("%*c %s\n", indent, '*', _(menu_get_prompt(child)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 continue;
280 }
281 cnt++;
282 if (child->sym == def_sym) {
283 def = cnt;
284 printf("%*c", indent, '>');
285 } else
286 printf("%*c", indent, ' ');
EGRY Gabor534a4502008-01-11 23:44:39 +0100287 printf(" %d. %s", cnt, _(menu_get_prompt(child)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 if (child->sym->name)
289 printf(" (%s)", child->sym->name);
290 if (!sym_has_value(child->sym))
EGRY Gabor534a4502008-01-11 23:44:39 +0100291 printf(_(" (NEW)"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 printf("\n");
293 }
EGRY Gabor534a4502008-01-11 23:44:39 +0100294 printf(_("%*schoice"), indent - 1, "");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 if (cnt == 1) {
296 printf("[1]: 1\n");
297 goto conf_childs;
298 }
299 printf("[1-%d", cnt);
Sam Ravnborg03d29122007-07-21 00:00:36 +0200300 if (menu_has_help(menu))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 printf("?");
302 printf("]: ");
303 switch (input_mode) {
304 case ask_new:
305 case ask_silent:
306 if (!is_new) {
307 cnt = def;
308 printf("%d\n", cnt);
309 break;
310 }
311 check_stdin();
312 case ask_all:
313 fflush(stdout);
Roman Zippel59c6a3f2006-04-09 17:26:50 +0200314 fgets(line, 128, stdin);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 strip(line);
316 if (line[0] == '?') {
Cheng Renquan66c4bd82009-07-12 16:11:48 +0800317 print_help(menu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 continue;
319 }
320 if (!line[0])
321 cnt = def;
322 else if (isdigit(line[0]))
323 cnt = atoi(line);
324 else
325 continue;
326 break;
Sam Ravnborgf443d2e2008-06-30 22:45:38 +0200327 default:
328 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 }
330
331 conf_childs:
332 for (child = menu->list; child; child = child->next) {
333 if (!child->sym || !menu_is_visible(child))
334 continue;
335 if (!--cnt)
336 break;
337 }
338 if (!child)
339 continue;
340 if (line[strlen(line) - 1] == '?') {
Cheng Renquan66c4bd82009-07-12 16:11:48 +0800341 print_help(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 continue;
343 }
344 sym_set_choice_value(sym, child->sym);
Jan Beulichf5eaa322008-01-24 11:54:23 +0000345 for (child = child->list; child; child = child->next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 indent += 2;
Jan Beulichf5eaa322008-01-24 11:54:23 +0000347 conf(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 indent -= 2;
349 }
350 return 1;
351 }
352}
353
354static void conf(struct menu *menu)
355{
356 struct symbol *sym;
357 struct property *prop;
358 struct menu *child;
359
360 if (!menu_is_visible(menu))
361 return;
362
363 sym = menu->sym;
364 prop = menu->prompt;
365 if (prop) {
366 const char *prompt;
367
368 switch (prop->type) {
369 case P_MENU:
Aristeu Rozanskif0778c82010-05-06 12:48:34 -0400370 if ((input_mode == ask_silent ||
371 input_mode == dont_ask ||
372 input_mode == dont_ask_dont_tell) &&
373 rootEntry != menu) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 check_conf(menu);
375 return;
376 }
377 case P_COMMENT:
378 prompt = menu_get_prompt(menu);
379 if (prompt)
380 printf("%*c\n%*c %s\n%*c\n",
381 indent, '*',
EGRY Gabor534a4502008-01-11 23:44:39 +0100382 indent, '*', _(prompt),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 indent, '*');
384 default:
385 ;
386 }
387 }
388
389 if (!sym)
390 goto conf_childs;
391
392 if (sym_is_choice(sym)) {
393 conf_choice(menu);
394 if (sym->curr.tri != mod)
395 return;
396 goto conf_childs;
397 }
398
399 switch (sym->type) {
400 case S_INT:
401 case S_HEX:
402 case S_STRING:
403 conf_string(menu);
404 break;
405 default:
406 conf_sym(menu);
407 break;
408 }
409
410conf_childs:
411 if (sym)
412 indent += 2;
413 for (child = menu->list; child; child = child->next)
414 conf(child);
415 if (sym)
416 indent -= 2;
417}
418
419static void check_conf(struct menu *menu)
420{
421 struct symbol *sym;
422 struct menu *child;
423
424 if (!menu_is_visible(menu))
425 return;
426
427 sym = menu->sym;
Roman Zippel3f23ca22005-11-08 21:34:48 -0800428 if (sym && !sym_has_value(sym)) {
429 if (sym_is_changable(sym) ||
430 (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)) {
Aristeu Rozanskif0778c82010-05-06 12:48:34 -0400431 if (input_mode == dont_ask ||
432 input_mode == dont_ask_dont_tell) {
433 if (input_mode == dont_ask &&
434 sym->name && !sym_is_choice_value(sym)) {
435 if (!unset_variables)
436 fprintf(stderr, "The following"
437 " variables are not set:\n");
438 fprintf(stderr, "CONFIG_%s\n",
439 sym->name);
440 unset_variables++;
441 }
442 } else {
443 if (!conf_cnt++)
444 printf(_("*\n* Restart config...\n*\n"));
445 rootEntry = menu_get_parent_menu(menu);
446 conf(rootEntry);
447 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 }
450
451 for (child = menu->list; child; child = child->next)
452 check_conf(child);
453}
454
455int main(int ac, char **av)
456{
Andres Salomon2f4b4892007-12-17 01:34:58 -0500457 int opt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 const char *name;
459 struct stat tmpstat;
460
EGRY Gabor534a4502008-01-11 23:44:39 +0100461 setlocale(LC_ALL, "");
462 bindtextdomain(PACKAGE, LOCALEDIR);
463 textdomain(PACKAGE);
464
Aristeu Rozanskif0778c82010-05-06 12:48:34 -0400465 while ((opt = getopt(ac, av, "osbBdD:nmyrh")) != -1) {
Andres Salomon2f4b4892007-12-17 01:34:58 -0500466 switch (opt) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 case 'o':
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200468 input_mode = ask_silent;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 break;
470 case 's':
471 input_mode = ask_silent;
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200472 sync_kconfig = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 break;
Aristeu Rozanskif0778c82010-05-06 12:48:34 -0400474 case 'b':
475 input_mode = dont_ask;
476 break;
477 case 'B':
478 input_mode = dont_ask_dont_tell;
479 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 case 'd':
481 input_mode = set_default;
482 break;
483 case 'D':
484 input_mode = set_default;
Andres Salomon2f4b4892007-12-17 01:34:58 -0500485 defconfig_file = optarg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 break;
487 case 'n':
488 input_mode = set_no;
489 break;
490 case 'm':
491 input_mode = set_mod;
492 break;
493 case 'y':
494 input_mode = set_yes;
495 break;
496 case 'r':
Ingo Molnarb0fe5512009-03-12 15:15:31 +0100497 {
498 struct timeval now;
499 unsigned int seed;
500
501 /*
502 * Use microseconds derived seed,
503 * compensate for systems where it may be zero
504 */
505 gettimeofday(&now, NULL);
506
507 seed = (unsigned int)((now.tv_sec + 1) * (now.tv_usec + 1));
508 srand(seed);
509
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 input_mode = set_random;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 break;
Ingo Molnarb0fe5512009-03-12 15:15:31 +0100512 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 case 'h':
EGRY Gabor534a4502008-01-11 23:44:39 +0100514 printf(_("See README for usage info\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 exit(0);
Andres Salomon2f4b4892007-12-17 01:34:58 -0500516 break;
517 default:
EGRY Gabor534a4502008-01-11 23:44:39 +0100518 fprintf(stderr, _("See README for usage info\n"));
Andres Salomon2f4b4892007-12-17 01:34:58 -0500519 exit(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 }
521 }
Andres Salomon2f4b4892007-12-17 01:34:58 -0500522 if (ac == optind) {
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -0700523 printf(_("%s: Kconfig file missing\n"), av[0]);
Randy Dunlap250725a2006-06-08 22:12:50 -0700524 exit(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 }
Andres Salomon2f4b4892007-12-17 01:34:58 -0500526 name = av[optind];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 conf_parse(name);
528 //zconfdump(stdout);
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200529 if (sync_kconfig) {
Markus Heidelberg284026c2009-05-18 01:36:53 +0200530 name = conf_get_configname();
531 if (stat(name, &tmpstat)) {
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200532 fprintf(stderr, _("***\n"
533 "*** You have not yet configured your kernel!\n"
Markus Heidelberg284026c2009-05-18 01:36:53 +0200534 "*** (missing kernel config file \"%s\")\n"
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200535 "***\n"
536 "*** Please run some configurator (e.g. \"make oldconfig\" or\n"
537 "*** \"make menuconfig\" or \"make xconfig\").\n"
Markus Heidelberg284026c2009-05-18 01:36:53 +0200538 "***\n"), name);
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200539 exit(1);
540 }
541 }
542
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 switch (input_mode) {
544 case set_default:
545 if (!defconfig_file)
546 defconfig_file = conf_get_default_confname();
547 if (conf_read(defconfig_file)) {
EGRY Gabor534a4502008-01-11 23:44:39 +0100548 printf(_("***\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 "*** Can't find default configuration \"%s\"!\n"
EGRY Gabor534a4502008-01-11 23:44:39 +0100550 "***\n"), defconfig_file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 exit(1);
552 }
553 break;
554 case ask_silent:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 case ask_all:
556 case ask_new:
Aristeu Rozanskif0778c82010-05-06 12:48:34 -0400557 case dont_ask:
558 case dont_ask_dont_tell:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 conf_read(NULL);
560 break;
Roman Zippel90389162005-11-08 21:34:49 -0800561 case set_no:
562 case set_mod:
563 case set_yes:
564 case set_random:
565 name = getenv("KCONFIG_ALLCONFIG");
566 if (name && !stat(name, &tmpstat)) {
Roman Zippel669bfad2006-06-08 22:12:42 -0700567 conf_read_simple(name, S_DEF_USER);
Roman Zippel90389162005-11-08 21:34:49 -0800568 break;
569 }
570 switch (input_mode) {
571 case set_no: name = "allno.config"; break;
572 case set_mod: name = "allmod.config"; break;
573 case set_yes: name = "allyes.config"; break;
574 case set_random: name = "allrandom.config"; break;
575 default: break;
576 }
577 if (!stat(name, &tmpstat))
Roman Zippel669bfad2006-06-08 22:12:42 -0700578 conf_read_simple(name, S_DEF_USER);
Roman Zippel90389162005-11-08 21:34:49 -0800579 else if (!stat("all.config", &tmpstat))
Roman Zippel669bfad2006-06-08 22:12:42 -0700580 conf_read_simple("all.config", S_DEF_USER);
Roman Zippel90389162005-11-08 21:34:49 -0800581 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 default:
583 break;
584 }
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200585
586 if (sync_kconfig) {
587 if (conf_get_changed()) {
588 name = getenv("KCONFIG_NOSILENTUPDATE");
589 if (name && *name) {
590 fprintf(stderr,
591 _("\n*** Kernel configuration requires explicit update.\n\n"));
592 return 1;
593 }
594 }
595 valid_stdin = isatty(0) && isatty(1) && isatty(2);
596 }
597
Sam Ravnborgf443d2e2008-06-30 22:45:38 +0200598 switch (input_mode) {
599 case set_no:
600 conf_set_all_new_symbols(def_no);
601 break;
602 case set_yes:
603 conf_set_all_new_symbols(def_yes);
604 break;
605 case set_mod:
606 conf_set_all_new_symbols(def_mod);
607 break;
608 case set_random:
609 conf_set_all_new_symbols(def_random);
610 break;
Sam Ravnborg09748e12008-06-30 23:02:59 +0200611 case set_default:
612 conf_set_all_new_symbols(def_default);
613 break;
Sam Ravnborgcd9140e1e2008-06-30 22:53:04 +0200614 case ask_new:
Sam Ravnborgf443d2e2008-06-30 22:45:38 +0200615 case ask_all:
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200616 rootEntry = &rootmenu;
617 conf(&rootmenu);
618 input_mode = ask_silent;
619 /* fall through */
Aristeu Rozanskif0778c82010-05-06 12:48:34 -0400620 case dont_ask:
621 case dont_ask_dont_tell:
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200622 case ask_silent:
623 /* Update until a loop caused no more changes */
624 do {
625 conf_cnt = 0;
626 check_conf(&rootmenu);
Aristeu Rozanskif0778c82010-05-06 12:48:34 -0400627 } while (conf_cnt &&
628 (input_mode != dont_ask &&
629 input_mode != dont_ask_dont_tell));
Sam Ravnborgf443d2e2008-06-30 22:45:38 +0200630 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 }
Sam Ravnborgf443d2e2008-06-30 22:45:38 +0200632
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200633 if (sync_kconfig) {
634 /* silentoldconfig is used during the build so we shall update autoconf.
635 * All other commands are only used to generate a config.
636 */
637 if (conf_get_changed() && conf_write(NULL)) {
638 fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n"));
639 exit(1);
640 }
641 if (conf_write_autoconf()) {
642 fprintf(stderr, _("\n*** Error during update of the kernel configuration.\n\n"));
643 return 1;
644 }
Aristeu Rozanskif0778c82010-05-06 12:48:34 -0400645 } else if (!unset_variables || input_mode != dont_ask) {
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200646 if (conf_write(NULL)) {
647 fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n"));
648 exit(1);
649 }
Roman Zippelc955cca2006-06-08 22:12:39 -0700650 }
Aristeu Rozanskif0778c82010-05-06 12:48:34 -0400651 return unset_variables ? EUNSETOPT : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652}