blob: c8bd33cb3bf7d3d60b39a5ef86c47ae34e394a18 [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,
Sam Ravnborg0748cb32010-07-31 23:35:31 +020030 alldefconfig,
Sam Ravnborg4062f1a2010-07-31 23:35:26 +020031 randconfig,
32 defconfig,
Sam Ravnborg861b4ea2010-07-31 23:35:28 +020033 listnewconfig,
Sam Ravnborgef61ca82010-07-31 23:35:27 +020034 oldnoconfig,
Sam Ravnborg4062f1a2010-07-31 23:35:26 +020035} input_mode = oldaskconfig;
36
Linus Torvalds1da177e2005-04-16 15:20:36 -070037char *defconfig_file;
38
39static int indent = 1;
40static int valid_stdin = 1;
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +020041static int sync_kconfig;
Linus Torvalds1da177e2005-04-16 15:20:36 -070042static int conf_cnt;
J.A. Magallon48b9d032005-06-25 14:59:22 -070043static char line[128];
Linus Torvalds1da177e2005-04-16 15:20:36 -070044static struct menu *rootEntry;
45
Cheng Renquan66c4bd82009-07-12 16:11:48 +080046static void print_help(struct menu *menu)
Sam Ravnborg03d29122007-07-21 00:00:36 +020047{
Cheng Renquan66c4bd82009-07-12 16:11:48 +080048 struct gstr help = str_new();
49
50 menu_get_ext_help(menu, &help);
51
52 printf("\n%s\n", str_get(&help));
53 str_free(&help);
Sam Ravnborg03d29122007-07-21 00:00:36 +020054}
55
J.A. Magallon48b9d032005-06-25 14:59:22 -070056static void strip(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057{
J.A. Magallon48b9d032005-06-25 14:59:22 -070058 char *p = str;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 int l;
60
61 while ((isspace(*p)))
62 p++;
63 l = strlen(p);
64 if (p != str)
65 memmove(str, p, l + 1);
66 if (!l)
67 return;
68 p = str + l - 1;
69 while ((isspace(*p)))
70 *p-- = 0;
71}
72
73static void check_stdin(void)
74{
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +020075 if (!valid_stdin) {
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070076 printf(_("aborted!\n\n"));
77 printf(_("Console input/output is redirected. "));
78 printf(_("Run 'make oldconfig' to update configuration.\n\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 exit(1);
80 }
81}
82
Roman Zippelf82f3f92007-08-30 05:06:17 +020083static int conf_askvalue(struct symbol *sym, const char *def)
Linus Torvalds1da177e2005-04-16 15:20:36 -070084{
85 enum symbol_type type = sym_get_type(sym);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
87 if (!sym_has_value(sym))
EGRY Gabor534a4502008-01-11 23:44:39 +010088 printf(_("(NEW) "));
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
90 line[0] = '\n';
91 line[1] = 0;
92
93 if (!sym_is_changable(sym)) {
94 printf("%s\n", def);
95 line[0] = '\n';
96 line[1] = 0;
Roman Zippelf82f3f92007-08-30 05:06:17 +020097 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 }
99
100 switch (input_mode) {
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200101 case oldconfig:
102 case silentoldconfig:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 if (sym_has_value(sym)) {
104 printf("%s\n", def);
Roman Zippelf82f3f92007-08-30 05:06:17 +0200105 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 }
107 check_stdin();
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200108 case oldaskconfig:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 fflush(stdout);
Roman Zippel59c6a3f2006-04-09 17:26:50 +0200110 fgets(line, 128, stdin);
Roman Zippelf82f3f92007-08-30 05:06:17 +0200111 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 default:
113 break;
114 }
115
116 switch (type) {
117 case S_INT:
118 case S_HEX:
119 case S_STRING:
120 printf("%s\n", def);
Roman Zippelf82f3f92007-08-30 05:06:17 +0200121 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 default:
123 ;
124 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 printf("%s", line);
Roman Zippelf82f3f92007-08-30 05:06:17 +0200126 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127}
128
Trevor Keith4356f482009-09-18 12:49:23 -0700129static int conf_string(struct menu *menu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130{
131 struct symbol *sym = menu->sym;
Sam Ravnborg03d29122007-07-21 00:00:36 +0200132 const char *def;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
134 while (1) {
EGRY Gabor534a4502008-01-11 23:44:39 +0100135 printf("%*s%s ", indent - 1, "", _(menu->prompt->text));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 printf("(%s) ", sym->name);
137 def = sym_get_string_value(sym);
138 if (sym_get_string_value(sym))
139 printf("[%s] ", def);
Roman Zippelf82f3f92007-08-30 05:06:17 +0200140 if (!conf_askvalue(sym, def))
141 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 switch (line[0]) {
143 case '\n':
144 break;
145 case '?':
146 /* print help */
147 if (line[1] == '\n') {
Cheng Renquan66c4bd82009-07-12 16:11:48 +0800148 print_help(menu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 def = NULL;
150 break;
151 }
152 default:
153 line[strlen(line)-1] = 0;
154 def = line;
155 }
156 if (def && sym_set_string_value(sym, def))
157 return 0;
158 }
159}
160
161static int conf_sym(struct menu *menu)
162{
163 struct symbol *sym = menu->sym;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 tristate oldval, newval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
166 while (1) {
EGRY Gabor534a4502008-01-11 23:44:39 +0100167 printf("%*s%s ", indent - 1, "", _(menu->prompt->text));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 if (sym->name)
169 printf("(%s) ", sym->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 putchar('[');
171 oldval = sym_get_tristate_value(sym);
172 switch (oldval) {
173 case no:
174 putchar('N');
175 break;
176 case mod:
177 putchar('M');
178 break;
179 case yes:
180 putchar('Y');
181 break;
182 }
183 if (oldval != no && sym_tristate_within_range(sym, no))
184 printf("/n");
185 if (oldval != mod && sym_tristate_within_range(sym, mod))
186 printf("/m");
187 if (oldval != yes && sym_tristate_within_range(sym, yes))
188 printf("/y");
Sam Ravnborg03d29122007-07-21 00:00:36 +0200189 if (menu_has_help(menu))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 printf("/?");
191 printf("] ");
Roman Zippelf82f3f92007-08-30 05:06:17 +0200192 if (!conf_askvalue(sym, sym_get_string_value(sym)))
193 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 strip(line);
195
196 switch (line[0]) {
197 case 'n':
198 case 'N':
199 newval = no;
200 if (!line[1] || !strcmp(&line[1], "o"))
201 break;
202 continue;
203 case 'm':
204 case 'M':
205 newval = mod;
206 if (!line[1])
207 break;
208 continue;
209 case 'y':
210 case 'Y':
211 newval = yes;
212 if (!line[1] || !strcmp(&line[1], "es"))
213 break;
214 continue;
215 case 0:
216 newval = oldval;
217 break;
218 case '?':
219 goto help;
220 default:
221 continue;
222 }
223 if (sym_set_tristate_value(sym, newval))
224 return 0;
225help:
Cheng Renquan66c4bd82009-07-12 16:11:48 +0800226 print_help(menu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 }
228}
229
230static int conf_choice(struct menu *menu)
231{
232 struct symbol *sym, *def_sym;
233 struct menu *child;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 bool is_new;
235
236 sym = menu->sym;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 is_new = !sym_has_value(sym);
238 if (sym_is_changable(sym)) {
239 conf_sym(menu);
240 sym_calc_value(sym);
241 switch (sym_get_tristate_value(sym)) {
242 case no:
243 return 1;
244 case mod:
245 return 0;
246 case yes:
247 break;
248 }
249 } else {
250 switch (sym_get_tristate_value(sym)) {
251 case no:
252 return 1;
253 case mod:
EGRY Gabor534a4502008-01-11 23:44:39 +0100254 printf("%*s%s\n", indent - 1, "", _(menu_get_prompt(menu)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 return 0;
256 case yes:
257 break;
258 }
259 }
260
261 while (1) {
262 int cnt, def;
263
EGRY Gabor534a4502008-01-11 23:44:39 +0100264 printf("%*s%s\n", indent - 1, "", _(menu_get_prompt(menu)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 def_sym = sym_get_choice_value(sym);
266 cnt = def = 0;
Roman Zippel40aee722006-04-09 17:26:39 +0200267 line[0] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 for (child = menu->list; child; child = child->next) {
269 if (!menu_is_visible(child))
270 continue;
271 if (!child->sym) {
EGRY Gabor534a4502008-01-11 23:44:39 +0100272 printf("%*c %s\n", indent, '*', _(menu_get_prompt(child)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 continue;
274 }
275 cnt++;
276 if (child->sym == def_sym) {
277 def = cnt;
278 printf("%*c", indent, '>');
279 } else
280 printf("%*c", indent, ' ');
EGRY Gabor534a4502008-01-11 23:44:39 +0100281 printf(" %d. %s", cnt, _(menu_get_prompt(child)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 if (child->sym->name)
283 printf(" (%s)", child->sym->name);
284 if (!sym_has_value(child->sym))
EGRY Gabor534a4502008-01-11 23:44:39 +0100285 printf(_(" (NEW)"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 printf("\n");
287 }
EGRY Gabor534a4502008-01-11 23:44:39 +0100288 printf(_("%*schoice"), indent - 1, "");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 if (cnt == 1) {
290 printf("[1]: 1\n");
291 goto conf_childs;
292 }
293 printf("[1-%d", cnt);
Sam Ravnborg03d29122007-07-21 00:00:36 +0200294 if (menu_has_help(menu))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 printf("?");
296 printf("]: ");
297 switch (input_mode) {
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200298 case oldconfig:
299 case silentoldconfig:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 if (!is_new) {
301 cnt = def;
302 printf("%d\n", cnt);
303 break;
304 }
305 check_stdin();
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200306 case oldaskconfig:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 fflush(stdout);
Roman Zippel59c6a3f2006-04-09 17:26:50 +0200308 fgets(line, 128, stdin);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 strip(line);
310 if (line[0] == '?') {
Cheng Renquan66c4bd82009-07-12 16:11:48 +0800311 print_help(menu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 continue;
313 }
314 if (!line[0])
315 cnt = def;
316 else if (isdigit(line[0]))
317 cnt = atoi(line);
318 else
319 continue;
320 break;
Sam Ravnborgf443d2e2008-06-30 22:45:38 +0200321 default:
322 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 }
324
325 conf_childs:
326 for (child = menu->list; child; child = child->next) {
327 if (!child->sym || !menu_is_visible(child))
328 continue;
329 if (!--cnt)
330 break;
331 }
332 if (!child)
333 continue;
334 if (line[strlen(line) - 1] == '?') {
Cheng Renquan66c4bd82009-07-12 16:11:48 +0800335 print_help(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 continue;
337 }
338 sym_set_choice_value(sym, child->sym);
Jan Beulichf5eaa322008-01-24 11:54:23 +0000339 for (child = child->list; child; child = child->next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 indent += 2;
Jan Beulichf5eaa322008-01-24 11:54:23 +0000341 conf(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 indent -= 2;
343 }
344 return 1;
345 }
346}
347
348static void conf(struct menu *menu)
349{
350 struct symbol *sym;
351 struct property *prop;
352 struct menu *child;
353
354 if (!menu_is_visible(menu))
355 return;
356
357 sym = menu->sym;
358 prop = menu->prompt;
359 if (prop) {
360 const char *prompt;
361
362 switch (prop->type) {
363 case P_MENU:
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200364 if ((input_mode == silentoldconfig ||
Sam Ravnborg861b4ea2010-07-31 23:35:28 +0200365 input_mode == listnewconfig ||
Sam Ravnborgef61ca82010-07-31 23:35:27 +0200366 input_mode == oldnoconfig) &&
Aristeu Rozanskif0778c82010-05-06 12:48:34 -0400367 rootEntry != menu) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 check_conf(menu);
369 return;
370 }
371 case P_COMMENT:
372 prompt = menu_get_prompt(menu);
373 if (prompt)
374 printf("%*c\n%*c %s\n%*c\n",
375 indent, '*',
EGRY Gabor534a4502008-01-11 23:44:39 +0100376 indent, '*', _(prompt),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 indent, '*');
378 default:
379 ;
380 }
381 }
382
383 if (!sym)
384 goto conf_childs;
385
386 if (sym_is_choice(sym)) {
387 conf_choice(menu);
388 if (sym->curr.tri != mod)
389 return;
390 goto conf_childs;
391 }
392
393 switch (sym->type) {
394 case S_INT:
395 case S_HEX:
396 case S_STRING:
397 conf_string(menu);
398 break;
399 default:
400 conf_sym(menu);
401 break;
402 }
403
404conf_childs:
405 if (sym)
406 indent += 2;
407 for (child = menu->list; child; child = child->next)
408 conf(child);
409 if (sym)
410 indent -= 2;
411}
412
413static void check_conf(struct menu *menu)
414{
415 struct symbol *sym;
416 struct menu *child;
417
418 if (!menu_is_visible(menu))
419 return;
420
421 sym = menu->sym;
Roman Zippel3f23ca22005-11-08 21:34:48 -0800422 if (sym && !sym_has_value(sym)) {
423 if (sym_is_changable(sym) ||
424 (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)) {
Sam Ravnborg861b4ea2010-07-31 23:35:28 +0200425 if (input_mode == listnewconfig) {
426 if (sym->name && !sym_is_choice_value(sym)) {
427 printf("CONFIG_%s\n", sym->name);
Aristeu Rozanskif0778c82010-05-06 12:48:34 -0400428 }
429 } else {
430 if (!conf_cnt++)
431 printf(_("*\n* Restart config...\n*\n"));
432 rootEntry = menu_get_parent_menu(menu);
433 conf(rootEntry);
434 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 }
437
438 for (child = menu->list; child; child = child->next)
439 check_conf(child);
440}
441
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200442static struct option long_opts[] = {
443 {"oldaskconfig", no_argument, NULL, oldaskconfig},
444 {"oldconfig", no_argument, NULL, oldconfig},
445 {"silentoldconfig", no_argument, NULL, silentoldconfig},
446 {"defconfig", optional_argument, NULL, defconfig},
447 {"allnoconfig", no_argument, NULL, allnoconfig},
448 {"allyesconfig", no_argument, NULL, allyesconfig},
449 {"allmodconfig", no_argument, NULL, allmodconfig},
Sam Ravnborg0748cb32010-07-31 23:35:31 +0200450 {"alldefconfig", no_argument, NULL, alldefconfig},
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200451 {"randconfig", no_argument, NULL, randconfig},
Sam Ravnborg861b4ea2010-07-31 23:35:28 +0200452 {"listnewconfig", no_argument, NULL, listnewconfig},
Sam Ravnborgef61ca82010-07-31 23:35:27 +0200453 {"oldnoconfig", no_argument, NULL, oldnoconfig},
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200454 {NULL, 0, NULL, 0}
455};
456
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457int main(int ac, char **av)
458{
Andres Salomon2f4b4892007-12-17 01:34:58 -0500459 int opt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 const char *name;
461 struct stat tmpstat;
462
EGRY Gabor534a4502008-01-11 23:44:39 +0100463 setlocale(LC_ALL, "");
464 bindtextdomain(PACKAGE, LOCALEDIR);
465 textdomain(PACKAGE);
466
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200467 while ((opt = getopt_long_only(ac, av, "", long_opts, NULL)) != -1) {
468 input_mode = (enum input_mode)opt;
Andres Salomon2f4b4892007-12-17 01:34:58 -0500469 switch (opt) {
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200470 case silentoldconfig:
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200471 sync_kconfig = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200473 case defconfig:
Andres Salomon2f4b4892007-12-17 01:34:58 -0500474 defconfig_file = optarg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200476 case randconfig:
Ingo Molnarb0fe5512009-03-12 15:15:31 +0100477 {
478 struct timeval now;
479 unsigned int seed;
480
481 /*
482 * Use microseconds derived seed,
483 * compensate for systems where it may be zero
484 */
485 gettimeofday(&now, NULL);
486
487 seed = (unsigned int)((now.tv_sec + 1) * (now.tv_usec + 1));
488 srand(seed);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 break;
Ingo Molnarb0fe5512009-03-12 15:15:31 +0100490 }
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200491 case '?':
EGRY Gabor534a4502008-01-11 23:44:39 +0100492 fprintf(stderr, _("See README for usage info\n"));
Andres Salomon2f4b4892007-12-17 01:34:58 -0500493 exit(1);
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200494 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 }
496 }
Andres Salomon2f4b4892007-12-17 01:34:58 -0500497 if (ac == optind) {
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -0700498 printf(_("%s: Kconfig file missing\n"), av[0]);
Randy Dunlap250725a2006-06-08 22:12:50 -0700499 exit(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 }
Andres Salomon2f4b4892007-12-17 01:34:58 -0500501 name = av[optind];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 conf_parse(name);
503 //zconfdump(stdout);
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200504 if (sync_kconfig) {
Markus Heidelberg284026c2009-05-18 01:36:53 +0200505 name = conf_get_configname();
506 if (stat(name, &tmpstat)) {
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200507 fprintf(stderr, _("***\n"
508 "*** You have not yet configured your kernel!\n"
Markus Heidelberg284026c2009-05-18 01:36:53 +0200509 "*** (missing kernel config file \"%s\")\n"
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200510 "***\n"
511 "*** Please run some configurator (e.g. \"make oldconfig\" or\n"
512 "*** \"make menuconfig\" or \"make xconfig\").\n"
Markus Heidelberg284026c2009-05-18 01:36:53 +0200513 "***\n"), name);
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200514 exit(1);
515 }
516 }
517
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 switch (input_mode) {
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200519 case defconfig:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 if (!defconfig_file)
521 defconfig_file = conf_get_default_confname();
522 if (conf_read(defconfig_file)) {
EGRY Gabor534a4502008-01-11 23:44:39 +0100523 printf(_("***\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 "*** Can't find default configuration \"%s\"!\n"
EGRY Gabor534a4502008-01-11 23:44:39 +0100525 "***\n"), defconfig_file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 exit(1);
527 }
528 break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200529 case silentoldconfig:
530 case oldaskconfig:
531 case oldconfig:
Sam Ravnborg861b4ea2010-07-31 23:35:28 +0200532 case listnewconfig:
Sam Ravnborgef61ca82010-07-31 23:35:27 +0200533 case oldnoconfig:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 conf_read(NULL);
535 break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200536 case allnoconfig:
537 case allyesconfig:
538 case allmodconfig:
Sam Ravnborg0748cb32010-07-31 23:35:31 +0200539 case alldefconfig:
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200540 case randconfig:
Roman Zippel90389162005-11-08 21:34:49 -0800541 name = getenv("KCONFIG_ALLCONFIG");
542 if (name && !stat(name, &tmpstat)) {
Roman Zippel669bfad2006-06-08 22:12:42 -0700543 conf_read_simple(name, S_DEF_USER);
Roman Zippel90389162005-11-08 21:34:49 -0800544 break;
545 }
546 switch (input_mode) {
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200547 case allnoconfig: name = "allno.config"; break;
548 case allyesconfig: name = "allyes.config"; break;
549 case allmodconfig: name = "allmod.config"; break;
Sam Ravnborg0748cb32010-07-31 23:35:31 +0200550 case alldefconfig: name = "alldef.config"; break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200551 case randconfig: name = "allrandom.config"; break;
Roman Zippel90389162005-11-08 21:34:49 -0800552 default: break;
553 }
554 if (!stat(name, &tmpstat))
Roman Zippel669bfad2006-06-08 22:12:42 -0700555 conf_read_simple(name, S_DEF_USER);
Roman Zippel90389162005-11-08 21:34:49 -0800556 else if (!stat("all.config", &tmpstat))
Roman Zippel669bfad2006-06-08 22:12:42 -0700557 conf_read_simple("all.config", S_DEF_USER);
Roman Zippel90389162005-11-08 21:34:49 -0800558 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 default:
560 break;
561 }
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200562
563 if (sync_kconfig) {
564 if (conf_get_changed()) {
565 name = getenv("KCONFIG_NOSILENTUPDATE");
566 if (name && *name) {
567 fprintf(stderr,
568 _("\n*** Kernel configuration requires explicit update.\n\n"));
569 return 1;
570 }
571 }
572 valid_stdin = isatty(0) && isatty(1) && isatty(2);
573 }
574
Sam Ravnborgf443d2e2008-06-30 22:45:38 +0200575 switch (input_mode) {
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200576 case allnoconfig:
Sam Ravnborgf443d2e2008-06-30 22:45:38 +0200577 conf_set_all_new_symbols(def_no);
578 break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200579 case allyesconfig:
Sam Ravnborgf443d2e2008-06-30 22:45:38 +0200580 conf_set_all_new_symbols(def_yes);
581 break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200582 case allmodconfig:
Sam Ravnborgf443d2e2008-06-30 22:45:38 +0200583 conf_set_all_new_symbols(def_mod);
584 break;
Sam Ravnborg0748cb32010-07-31 23:35:31 +0200585 case alldefconfig:
586 conf_set_all_new_symbols(def_default);
587 break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200588 case randconfig:
Sam Ravnborgf443d2e2008-06-30 22:45:38 +0200589 conf_set_all_new_symbols(def_random);
590 break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200591 case defconfig:
Sam Ravnborg09748e12008-06-30 23:02:59 +0200592 conf_set_all_new_symbols(def_default);
593 break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200594 case oldconfig:
595 case oldaskconfig:
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200596 rootEntry = &rootmenu;
597 conf(&rootmenu);
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200598 input_mode = silentoldconfig;
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200599 /* fall through */
Sam Ravnborg861b4ea2010-07-31 23:35:28 +0200600 case listnewconfig:
Sam Ravnborgef61ca82010-07-31 23:35:27 +0200601 case oldnoconfig:
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200602 case silentoldconfig:
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200603 /* Update until a loop caused no more changes */
604 do {
605 conf_cnt = 0;
606 check_conf(&rootmenu);
Aristeu Rozanskif0778c82010-05-06 12:48:34 -0400607 } while (conf_cnt &&
Sam Ravnborg861b4ea2010-07-31 23:35:28 +0200608 (input_mode != listnewconfig &&
Sam Ravnborgef61ca82010-07-31 23:35:27 +0200609 input_mode != oldnoconfig));
Sam Ravnborgf443d2e2008-06-30 22:45:38 +0200610 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 }
Sam Ravnborgf443d2e2008-06-30 22:45:38 +0200612
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200613 if (sync_kconfig) {
614 /* silentoldconfig is used during the build so we shall update autoconf.
615 * All other commands are only used to generate a config.
616 */
617 if (conf_get_changed() && conf_write(NULL)) {
618 fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n"));
619 exit(1);
620 }
621 if (conf_write_autoconf()) {
622 fprintf(stderr, _("\n*** Error during update of the kernel configuration.\n\n"));
623 return 1;
624 }
Sam Ravnborg861b4ea2010-07-31 23:35:28 +0200625 } else if (input_mode != listnewconfig) {
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200626 if (conf_write(NULL)) {
627 fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n"));
628 exit(1);
629 }
Roman Zippelc955cca2006-06-08 22:12:39 -0700630 }
Sam Ravnborg861b4ea2010-07-31 23:35:28 +0200631 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632}