blob: ff5c914c0e5c2559d26a66bc43a86a0d53ed4a28 [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>
Sam Ravnborg4062f1a2010-07-31 23:35:26 +020013#include <getopt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <sys/stat.h>
Ingo Molnarb0fe5512009-03-12 15:15:31 +010015#include <sys/time.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
17#define LKC_DIRECT_LINK
18#include "lkc.h"
19
20static void conf(struct menu *menu);
21static void check_conf(struct menu *menu);
22
Sam Ravnborg4062f1a2010-07-31 23:35:26 +020023enum input_mode {
24 oldaskconfig,
25 silentoldconfig,
26 oldconfig,
27 allnoconfig,
28 allyesconfig,
29 allmodconfig,
30 randconfig,
31 defconfig,
Sam Ravnborg861b4ea2010-07-31 23:35:28 +020032 listnewconfig,
Sam Ravnborgef61ca82010-07-31 23:35:27 +020033 oldnoconfig,
Sam Ravnborg4062f1a2010-07-31 23:35:26 +020034} input_mode = oldaskconfig;
35
Linus Torvalds1da177e2005-04-16 15:20:36 -070036char *defconfig_file;
37
38static int indent = 1;
39static int valid_stdin = 1;
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +020040static int sync_kconfig;
Linus Torvalds1da177e2005-04-16 15:20:36 -070041static int conf_cnt;
J.A. Magallon48b9d032005-06-25 14:59:22 -070042static char line[128];
Linus Torvalds1da177e2005-04-16 15:20:36 -070043static struct menu *rootEntry;
44
Cheng Renquan66c4bd82009-07-12 16:11:48 +080045static void print_help(struct menu *menu)
Sam Ravnborg03d29122007-07-21 00:00:36 +020046{
Cheng Renquan66c4bd82009-07-12 16:11:48 +080047 struct gstr help = str_new();
48
49 menu_get_ext_help(menu, &help);
50
51 printf("\n%s\n", str_get(&help));
52 str_free(&help);
Sam Ravnborg03d29122007-07-21 00:00:36 +020053}
54
J.A. Magallon48b9d032005-06-25 14:59:22 -070055static void strip(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -070056{
J.A. Magallon48b9d032005-06-25 14:59:22 -070057 char *p = str;
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 int l;
59
60 while ((isspace(*p)))
61 p++;
62 l = strlen(p);
63 if (p != str)
64 memmove(str, p, l + 1);
65 if (!l)
66 return;
67 p = str + l - 1;
68 while ((isspace(*p)))
69 *p-- = 0;
70}
71
72static void check_stdin(void)
73{
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +020074 if (!valid_stdin) {
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070075 printf(_("aborted!\n\n"));
76 printf(_("Console input/output is redirected. "));
77 printf(_("Run 'make oldconfig' to update configuration.\n\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 exit(1);
79 }
80}
81
Roman Zippelf82f3f92007-08-30 05:06:17 +020082static int conf_askvalue(struct symbol *sym, const char *def)
Linus Torvalds1da177e2005-04-16 15:20:36 -070083{
84 enum symbol_type type = sym_get_type(sym);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
86 if (!sym_has_value(sym))
EGRY Gabor534a4502008-01-11 23:44:39 +010087 printf(_("(NEW) "));
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
89 line[0] = '\n';
90 line[1] = 0;
91
92 if (!sym_is_changable(sym)) {
93 printf("%s\n", def);
94 line[0] = '\n';
95 line[1] = 0;
Roman Zippelf82f3f92007-08-30 05:06:17 +020096 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 }
98
99 switch (input_mode) {
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200100 case oldconfig:
101 case silentoldconfig:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 if (sym_has_value(sym)) {
103 printf("%s\n", def);
Roman Zippelf82f3f92007-08-30 05:06:17 +0200104 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 }
106 check_stdin();
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200107 case oldaskconfig:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 fflush(stdout);
Roman Zippel59c6a3f2006-04-09 17:26:50 +0200109 fgets(line, 128, stdin);
Roman Zippelf82f3f92007-08-30 05:06:17 +0200110 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 default:
112 break;
113 }
114
115 switch (type) {
116 case S_INT:
117 case S_HEX:
118 case S_STRING:
119 printf("%s\n", def);
Roman Zippelf82f3f92007-08-30 05:06:17 +0200120 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 default:
122 ;
123 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 printf("%s", line);
Roman Zippelf82f3f92007-08-30 05:06:17 +0200125 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126}
127
Trevor Keith4356f482009-09-18 12:49:23 -0700128static int conf_string(struct menu *menu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129{
130 struct symbol *sym = menu->sym;
Sam Ravnborg03d29122007-07-21 00:00:36 +0200131 const char *def;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
133 while (1) {
EGRY Gabor534a4502008-01-11 23:44:39 +0100134 printf("%*s%s ", indent - 1, "", _(menu->prompt->text));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 printf("(%s) ", sym->name);
136 def = sym_get_string_value(sym);
137 if (sym_get_string_value(sym))
138 printf("[%s] ", def);
Roman Zippelf82f3f92007-08-30 05:06:17 +0200139 if (!conf_askvalue(sym, def))
140 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 switch (line[0]) {
142 case '\n':
143 break;
144 case '?':
145 /* print help */
146 if (line[1] == '\n') {
Cheng Renquan66c4bd82009-07-12 16:11:48 +0800147 print_help(menu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 def = NULL;
149 break;
150 }
151 default:
152 line[strlen(line)-1] = 0;
153 def = line;
154 }
155 if (def && sym_set_string_value(sym, def))
156 return 0;
157 }
158}
159
160static int conf_sym(struct menu *menu)
161{
162 struct symbol *sym = menu->sym;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 tristate oldval, newval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
165 while (1) {
EGRY Gabor534a4502008-01-11 23:44:39 +0100166 printf("%*s%s ", indent - 1, "", _(menu->prompt->text));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 if (sym->name)
168 printf("(%s) ", sym->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 putchar('[');
170 oldval = sym_get_tristate_value(sym);
171 switch (oldval) {
172 case no:
173 putchar('N');
174 break;
175 case mod:
176 putchar('M');
177 break;
178 case yes:
179 putchar('Y');
180 break;
181 }
182 if (oldval != no && sym_tristate_within_range(sym, no))
183 printf("/n");
184 if (oldval != mod && sym_tristate_within_range(sym, mod))
185 printf("/m");
186 if (oldval != yes && sym_tristate_within_range(sym, yes))
187 printf("/y");
Sam Ravnborg03d29122007-07-21 00:00:36 +0200188 if (menu_has_help(menu))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 printf("/?");
190 printf("] ");
Roman Zippelf82f3f92007-08-30 05:06:17 +0200191 if (!conf_askvalue(sym, sym_get_string_value(sym)))
192 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 strip(line);
194
195 switch (line[0]) {
196 case 'n':
197 case 'N':
198 newval = no;
199 if (!line[1] || !strcmp(&line[1], "o"))
200 break;
201 continue;
202 case 'm':
203 case 'M':
204 newval = mod;
205 if (!line[1])
206 break;
207 continue;
208 case 'y':
209 case 'Y':
210 newval = yes;
211 if (!line[1] || !strcmp(&line[1], "es"))
212 break;
213 continue;
214 case 0:
215 newval = oldval;
216 break;
217 case '?':
218 goto help;
219 default:
220 continue;
221 }
222 if (sym_set_tristate_value(sym, newval))
223 return 0;
224help:
Cheng Renquan66c4bd82009-07-12 16:11:48 +0800225 print_help(menu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 }
227}
228
229static int conf_choice(struct menu *menu)
230{
231 struct symbol *sym, *def_sym;
232 struct menu *child;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 bool is_new;
234
235 sym = menu->sym;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 is_new = !sym_has_value(sym);
237 if (sym_is_changable(sym)) {
238 conf_sym(menu);
239 sym_calc_value(sym);
240 switch (sym_get_tristate_value(sym)) {
241 case no:
242 return 1;
243 case mod:
244 return 0;
245 case yes:
246 break;
247 }
248 } else {
249 switch (sym_get_tristate_value(sym)) {
250 case no:
251 return 1;
252 case mod:
EGRY Gabor534a4502008-01-11 23:44:39 +0100253 printf("%*s%s\n", indent - 1, "", _(menu_get_prompt(menu)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 return 0;
255 case yes:
256 break;
257 }
258 }
259
260 while (1) {
261 int cnt, def;
262
EGRY Gabor534a4502008-01-11 23:44:39 +0100263 printf("%*s%s\n", indent - 1, "", _(menu_get_prompt(menu)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 def_sym = sym_get_choice_value(sym);
265 cnt = def = 0;
Roman Zippel40aee722006-04-09 17:26:39 +0200266 line[0] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 for (child = menu->list; child; child = child->next) {
268 if (!menu_is_visible(child))
269 continue;
270 if (!child->sym) {
EGRY Gabor534a4502008-01-11 23:44:39 +0100271 printf("%*c %s\n", indent, '*', _(menu_get_prompt(child)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 continue;
273 }
274 cnt++;
275 if (child->sym == def_sym) {
276 def = cnt;
277 printf("%*c", indent, '>');
278 } else
279 printf("%*c", indent, ' ');
EGRY Gabor534a4502008-01-11 23:44:39 +0100280 printf(" %d. %s", cnt, _(menu_get_prompt(child)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 if (child->sym->name)
282 printf(" (%s)", child->sym->name);
283 if (!sym_has_value(child->sym))
EGRY Gabor534a4502008-01-11 23:44:39 +0100284 printf(_(" (NEW)"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 printf("\n");
286 }
EGRY Gabor534a4502008-01-11 23:44:39 +0100287 printf(_("%*schoice"), indent - 1, "");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 if (cnt == 1) {
289 printf("[1]: 1\n");
290 goto conf_childs;
291 }
292 printf("[1-%d", cnt);
Sam Ravnborg03d29122007-07-21 00:00:36 +0200293 if (menu_has_help(menu))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 printf("?");
295 printf("]: ");
296 switch (input_mode) {
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200297 case oldconfig:
298 case silentoldconfig:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 if (!is_new) {
300 cnt = def;
301 printf("%d\n", cnt);
302 break;
303 }
304 check_stdin();
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200305 case oldaskconfig:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 fflush(stdout);
Roman Zippel59c6a3f2006-04-09 17:26:50 +0200307 fgets(line, 128, stdin);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 strip(line);
309 if (line[0] == '?') {
Cheng Renquan66c4bd82009-07-12 16:11:48 +0800310 print_help(menu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 continue;
312 }
313 if (!line[0])
314 cnt = def;
315 else if (isdigit(line[0]))
316 cnt = atoi(line);
317 else
318 continue;
319 break;
Sam Ravnborgf443d2e2008-06-30 22:45:38 +0200320 default:
321 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 }
323
324 conf_childs:
325 for (child = menu->list; child; child = child->next) {
326 if (!child->sym || !menu_is_visible(child))
327 continue;
328 if (!--cnt)
329 break;
330 }
331 if (!child)
332 continue;
333 if (line[strlen(line) - 1] == '?') {
Cheng Renquan66c4bd82009-07-12 16:11:48 +0800334 print_help(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 continue;
336 }
337 sym_set_choice_value(sym, child->sym);
Jan Beulichf5eaa322008-01-24 11:54:23 +0000338 for (child = child->list; child; child = child->next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 indent += 2;
Jan Beulichf5eaa322008-01-24 11:54:23 +0000340 conf(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 indent -= 2;
342 }
343 return 1;
344 }
345}
346
347static void conf(struct menu *menu)
348{
349 struct symbol *sym;
350 struct property *prop;
351 struct menu *child;
352
353 if (!menu_is_visible(menu))
354 return;
355
356 sym = menu->sym;
357 prop = menu->prompt;
358 if (prop) {
359 const char *prompt;
360
361 switch (prop->type) {
362 case P_MENU:
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200363 if ((input_mode == silentoldconfig ||
Sam Ravnborg861b4ea2010-07-31 23:35:28 +0200364 input_mode == listnewconfig ||
Sam Ravnborgef61ca82010-07-31 23:35:27 +0200365 input_mode == oldnoconfig) &&
Aristeu Rozanskif0778c82010-05-06 12:48:34 -0400366 rootEntry != menu) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 check_conf(menu);
368 return;
369 }
370 case P_COMMENT:
371 prompt = menu_get_prompt(menu);
372 if (prompt)
373 printf("%*c\n%*c %s\n%*c\n",
374 indent, '*',
EGRY Gabor534a4502008-01-11 23:44:39 +0100375 indent, '*', _(prompt),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 indent, '*');
377 default:
378 ;
379 }
380 }
381
382 if (!sym)
383 goto conf_childs;
384
385 if (sym_is_choice(sym)) {
386 conf_choice(menu);
387 if (sym->curr.tri != mod)
388 return;
389 goto conf_childs;
390 }
391
392 switch (sym->type) {
393 case S_INT:
394 case S_HEX:
395 case S_STRING:
396 conf_string(menu);
397 break;
398 default:
399 conf_sym(menu);
400 break;
401 }
402
403conf_childs:
404 if (sym)
405 indent += 2;
406 for (child = menu->list; child; child = child->next)
407 conf(child);
408 if (sym)
409 indent -= 2;
410}
411
412static void check_conf(struct menu *menu)
413{
414 struct symbol *sym;
415 struct menu *child;
416
417 if (!menu_is_visible(menu))
418 return;
419
420 sym = menu->sym;
Roman Zippel3f23ca22005-11-08 21:34:48 -0800421 if (sym && !sym_has_value(sym)) {
422 if (sym_is_changable(sym) ||
423 (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)) {
Sam Ravnborg861b4ea2010-07-31 23:35:28 +0200424 if (input_mode == listnewconfig) {
425 if (sym->name && !sym_is_choice_value(sym)) {
426 printf("CONFIG_%s\n", sym->name);
Aristeu Rozanskif0778c82010-05-06 12:48:34 -0400427 }
428 } else {
429 if (!conf_cnt++)
430 printf(_("*\n* Restart config...\n*\n"));
431 rootEntry = menu_get_parent_menu(menu);
432 conf(rootEntry);
433 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 }
436
437 for (child = menu->list; child; child = child->next)
438 check_conf(child);
439}
440
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200441static struct option long_opts[] = {
442 {"oldaskconfig", no_argument, NULL, oldaskconfig},
443 {"oldconfig", no_argument, NULL, oldconfig},
444 {"silentoldconfig", no_argument, NULL, silentoldconfig},
445 {"defconfig", optional_argument, NULL, defconfig},
446 {"allnoconfig", no_argument, NULL, allnoconfig},
447 {"allyesconfig", no_argument, NULL, allyesconfig},
448 {"allmodconfig", no_argument, NULL, allmodconfig},
449 {"randconfig", no_argument, NULL, randconfig},
Sam Ravnborg861b4ea2010-07-31 23:35:28 +0200450 {"listnewconfig", no_argument, NULL, listnewconfig},
Sam Ravnborgef61ca82010-07-31 23:35:27 +0200451 {"oldnoconfig", no_argument, NULL, oldnoconfig},
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200452 {NULL, 0, NULL, 0}
453};
454
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455int 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
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200465 while ((opt = getopt_long_only(ac, av, "", long_opts, NULL)) != -1) {
466 input_mode = (enum input_mode)opt;
Andres Salomon2f4b4892007-12-17 01:34:58 -0500467 switch (opt) {
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200468 case silentoldconfig:
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200469 sync_kconfig = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200471 case defconfig:
Andres Salomon2f4b4892007-12-17 01:34:58 -0500472 defconfig_file = optarg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200474 case randconfig:
Ingo Molnarb0fe5512009-03-12 15:15:31 +0100475 {
476 struct timeval now;
477 unsigned int seed;
478
479 /*
480 * Use microseconds derived seed,
481 * compensate for systems where it may be zero
482 */
483 gettimeofday(&now, NULL);
484
485 seed = (unsigned int)((now.tv_sec + 1) * (now.tv_usec + 1));
486 srand(seed);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 break;
Ingo Molnarb0fe5512009-03-12 15:15:31 +0100488 }
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200489 case '?':
EGRY Gabor534a4502008-01-11 23:44:39 +0100490 fprintf(stderr, _("See README for usage info\n"));
Andres Salomon2f4b4892007-12-17 01:34:58 -0500491 exit(1);
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200492 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 }
494 }
Andres Salomon2f4b4892007-12-17 01:34:58 -0500495 if (ac == optind) {
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -0700496 printf(_("%s: Kconfig file missing\n"), av[0]);
Randy Dunlap250725a2006-06-08 22:12:50 -0700497 exit(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 }
Andres Salomon2f4b4892007-12-17 01:34:58 -0500499 name = av[optind];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 conf_parse(name);
501 //zconfdump(stdout);
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200502 if (sync_kconfig) {
Markus Heidelberg284026c2009-05-18 01:36:53 +0200503 name = conf_get_configname();
504 if (stat(name, &tmpstat)) {
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200505 fprintf(stderr, _("***\n"
506 "*** You have not yet configured your kernel!\n"
Markus Heidelberg284026c2009-05-18 01:36:53 +0200507 "*** (missing kernel config file \"%s\")\n"
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200508 "***\n"
509 "*** Please run some configurator (e.g. \"make oldconfig\" or\n"
510 "*** \"make menuconfig\" or \"make xconfig\").\n"
Markus Heidelberg284026c2009-05-18 01:36:53 +0200511 "***\n"), name);
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200512 exit(1);
513 }
514 }
515
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 switch (input_mode) {
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200517 case defconfig:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 if (!defconfig_file)
519 defconfig_file = conf_get_default_confname();
520 if (conf_read(defconfig_file)) {
EGRY Gabor534a4502008-01-11 23:44:39 +0100521 printf(_("***\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 "*** Can't find default configuration \"%s\"!\n"
EGRY Gabor534a4502008-01-11 23:44:39 +0100523 "***\n"), defconfig_file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 exit(1);
525 }
526 break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200527 case silentoldconfig:
528 case oldaskconfig:
529 case oldconfig:
Sam Ravnborg861b4ea2010-07-31 23:35:28 +0200530 case listnewconfig:
Sam Ravnborgef61ca82010-07-31 23:35:27 +0200531 case oldnoconfig:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 conf_read(NULL);
533 break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200534 case allnoconfig:
535 case allyesconfig:
536 case allmodconfig:
537 case randconfig:
Roman Zippel90389162005-11-08 21:34:49 -0800538 name = getenv("KCONFIG_ALLCONFIG");
539 if (name && !stat(name, &tmpstat)) {
Roman Zippel669bfad2006-06-08 22:12:42 -0700540 conf_read_simple(name, S_DEF_USER);
Roman Zippel90389162005-11-08 21:34:49 -0800541 break;
542 }
543 switch (input_mode) {
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200544 case allnoconfig: name = "allno.config"; break;
545 case allyesconfig: name = "allyes.config"; break;
546 case allmodconfig: name = "allmod.config"; break;
547 case randconfig: name = "allrandom.config"; break;
Roman Zippel90389162005-11-08 21:34:49 -0800548 default: break;
549 }
550 if (!stat(name, &tmpstat))
Roman Zippel669bfad2006-06-08 22:12:42 -0700551 conf_read_simple(name, S_DEF_USER);
Roman Zippel90389162005-11-08 21:34:49 -0800552 else if (!stat("all.config", &tmpstat))
Roman Zippel669bfad2006-06-08 22:12:42 -0700553 conf_read_simple("all.config", S_DEF_USER);
Roman Zippel90389162005-11-08 21:34:49 -0800554 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 default:
556 break;
557 }
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200558
559 if (sync_kconfig) {
560 if (conf_get_changed()) {
561 name = getenv("KCONFIG_NOSILENTUPDATE");
562 if (name && *name) {
563 fprintf(stderr,
564 _("\n*** Kernel configuration requires explicit update.\n\n"));
565 return 1;
566 }
567 }
568 valid_stdin = isatty(0) && isatty(1) && isatty(2);
569 }
570
Sam Ravnborgf443d2e2008-06-30 22:45:38 +0200571 switch (input_mode) {
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200572 case allnoconfig:
Sam Ravnborgf443d2e2008-06-30 22:45:38 +0200573 conf_set_all_new_symbols(def_no);
574 break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200575 case allyesconfig:
Sam Ravnborgf443d2e2008-06-30 22:45:38 +0200576 conf_set_all_new_symbols(def_yes);
577 break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200578 case allmodconfig:
Sam Ravnborgf443d2e2008-06-30 22:45:38 +0200579 conf_set_all_new_symbols(def_mod);
580 break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200581 case randconfig:
Sam Ravnborgf443d2e2008-06-30 22:45:38 +0200582 conf_set_all_new_symbols(def_random);
583 break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200584 case defconfig:
Sam Ravnborg09748e12008-06-30 23:02:59 +0200585 conf_set_all_new_symbols(def_default);
586 break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200587 case oldconfig:
588 case oldaskconfig:
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200589 rootEntry = &rootmenu;
590 conf(&rootmenu);
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200591 input_mode = silentoldconfig;
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200592 /* fall through */
Sam Ravnborg861b4ea2010-07-31 23:35:28 +0200593 case listnewconfig:
Sam Ravnborgef61ca82010-07-31 23:35:27 +0200594 case oldnoconfig:
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200595 case silentoldconfig:
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200596 /* Update until a loop caused no more changes */
597 do {
598 conf_cnt = 0;
599 check_conf(&rootmenu);
Aristeu Rozanskif0778c82010-05-06 12:48:34 -0400600 } while (conf_cnt &&
Sam Ravnborg861b4ea2010-07-31 23:35:28 +0200601 (input_mode != listnewconfig &&
Sam Ravnborgef61ca82010-07-31 23:35:27 +0200602 input_mode != oldnoconfig));
Sam Ravnborgf443d2e2008-06-30 22:45:38 +0200603 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 }
Sam Ravnborgf443d2e2008-06-30 22:45:38 +0200605
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200606 if (sync_kconfig) {
607 /* silentoldconfig is used during the build so we shall update autoconf.
608 * All other commands are only used to generate a config.
609 */
610 if (conf_get_changed() && conf_write(NULL)) {
611 fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n"));
612 exit(1);
613 }
614 if (conf_write_autoconf()) {
615 fprintf(stderr, _("\n*** Error during update of the kernel configuration.\n\n"));
616 return 1;
617 }
Sam Ravnborg861b4ea2010-07-31 23:35:28 +0200618 } else if (input_mode != listnewconfig) {
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200619 if (conf_write(NULL)) {
620 fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n"));
621 exit(1);
622 }
Roman Zippelc955cca2006-06-08 22:12:39 -0700623 }
Sam Ravnborg861b4ea2010-07-31 23:35:28 +0200624 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625}