blob: 2dec584f1268fcc73b45f97800b32fc238fbe451 [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
Aristeu Rozanskif0778c82010-05-06 12:48:34 -040020/* Return codes */
21#define EUNSETOPT 2 /* if -B and -b are used and unset config
22 * options were found */
23
Linus Torvalds1da177e2005-04-16 15:20:36 -070024static void conf(struct menu *menu);
25static void check_conf(struct menu *menu);
26
Sam Ravnborg4062f1a2010-07-31 23:35:26 +020027enum 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070040char *defconfig_file;
41
42static int indent = 1;
43static int valid_stdin = 1;
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +020044static int sync_kconfig;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045static int conf_cnt;
J.A. Magallon48b9d032005-06-25 14:59:22 -070046static char line[128];
Linus Torvalds1da177e2005-04-16 15:20:36 -070047static struct menu *rootEntry;
Aristeu Rozanskif0778c82010-05-06 12:48:34 -040048static int unset_variables;
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Cheng Renquan66c4bd82009-07-12 16:11:48 +080050static void print_help(struct menu *menu)
Sam Ravnborg03d29122007-07-21 00:00:36 +020051{
Cheng Renquan66c4bd82009-07-12 16:11:48 +080052 struct gstr help = str_new();
53
54 menu_get_ext_help(menu, &help);
55
56 printf("\n%s\n", str_get(&help));
57 str_free(&help);
Sam Ravnborg03d29122007-07-21 00:00:36 +020058}
59
J.A. Magallon48b9d032005-06-25 14:59:22 -070060static void strip(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -070061{
J.A. Magallon48b9d032005-06-25 14:59:22 -070062 char *p = str;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 int l;
64
65 while ((isspace(*p)))
66 p++;
67 l = strlen(p);
68 if (p != str)
69 memmove(str, p, l + 1);
70 if (!l)
71 return;
72 p = str + l - 1;
73 while ((isspace(*p)))
74 *p-- = 0;
75}
76
77static void check_stdin(void)
78{
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +020079 if (!valid_stdin) {
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070080 printf(_("aborted!\n\n"));
81 printf(_("Console input/output is redirected. "));
82 printf(_("Run 'make oldconfig' to update configuration.\n\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 exit(1);
84 }
85}
86
Roman Zippelf82f3f92007-08-30 05:06:17 +020087static int conf_askvalue(struct symbol *sym, const char *def)
Linus Torvalds1da177e2005-04-16 15:20:36 -070088{
89 enum symbol_type type = sym_get_type(sym);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
91 if (!sym_has_value(sym))
EGRY Gabor534a4502008-01-11 23:44:39 +010092 printf(_("(NEW) "));
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
94 line[0] = '\n';
95 line[1] = 0;
96
97 if (!sym_is_changable(sym)) {
98 printf("%s\n", def);
99 line[0] = '\n';
100 line[1] = 0;
Roman Zippelf82f3f92007-08-30 05:06:17 +0200101 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 }
103
104 switch (input_mode) {
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200105 case oldconfig:
106 case silentoldconfig:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 if (sym_has_value(sym)) {
108 printf("%s\n", def);
Roman Zippelf82f3f92007-08-30 05:06:17 +0200109 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 }
111 check_stdin();
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200112 case oldaskconfig:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 fflush(stdout);
Roman Zippel59c6a3f2006-04-09 17:26:50 +0200114 fgets(line, 128, stdin);
Roman Zippelf82f3f92007-08-30 05:06:17 +0200115 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 default:
117 break;
118 }
119
120 switch (type) {
121 case S_INT:
122 case S_HEX:
123 case S_STRING:
124 printf("%s\n", def);
Roman Zippelf82f3f92007-08-30 05:06:17 +0200125 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 default:
127 ;
128 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 printf("%s", line);
Roman Zippelf82f3f92007-08-30 05:06:17 +0200130 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131}
132
Trevor Keith4356f482009-09-18 12:49:23 -0700133static int conf_string(struct menu *menu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134{
135 struct symbol *sym = menu->sym;
Sam Ravnborg03d29122007-07-21 00:00:36 +0200136 const char *def;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
138 while (1) {
EGRY Gabor534a4502008-01-11 23:44:39 +0100139 printf("%*s%s ", indent - 1, "", _(menu->prompt->text));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 printf("(%s) ", sym->name);
141 def = sym_get_string_value(sym);
142 if (sym_get_string_value(sym))
143 printf("[%s] ", def);
Roman Zippelf82f3f92007-08-30 05:06:17 +0200144 if (!conf_askvalue(sym, def))
145 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 switch (line[0]) {
147 case '\n':
148 break;
149 case '?':
150 /* print help */
151 if (line[1] == '\n') {
Cheng Renquan66c4bd82009-07-12 16:11:48 +0800152 print_help(menu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 def = NULL;
154 break;
155 }
156 default:
157 line[strlen(line)-1] = 0;
158 def = line;
159 }
160 if (def && sym_set_string_value(sym, def))
161 return 0;
162 }
163}
164
165static int conf_sym(struct menu *menu)
166{
167 struct symbol *sym = menu->sym;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 tristate oldval, newval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
170 while (1) {
EGRY Gabor534a4502008-01-11 23:44:39 +0100171 printf("%*s%s ", indent - 1, "", _(menu->prompt->text));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 if (sym->name)
173 printf("(%s) ", sym->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 bool is_new;
239
240 sym = menu->sym;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 is_new = !sym_has_value(sym);
242 if (sym_is_changable(sym)) {
243 conf_sym(menu);
244 sym_calc_value(sym);
245 switch (sym_get_tristate_value(sym)) {
246 case no:
247 return 1;
248 case mod:
249 return 0;
250 case yes:
251 break;
252 }
253 } else {
254 switch (sym_get_tristate_value(sym)) {
255 case no:
256 return 1;
257 case mod:
EGRY Gabor534a4502008-01-11 23:44:39 +0100258 printf("%*s%s\n", indent - 1, "", _(menu_get_prompt(menu)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 return 0;
260 case yes:
261 break;
262 }
263 }
264
265 while (1) {
266 int cnt, def;
267
EGRY Gabor534a4502008-01-11 23:44:39 +0100268 printf("%*s%s\n", indent - 1, "", _(menu_get_prompt(menu)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 def_sym = sym_get_choice_value(sym);
270 cnt = def = 0;
Roman Zippel40aee722006-04-09 17:26:39 +0200271 line[0] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 for (child = menu->list; child; child = child->next) {
273 if (!menu_is_visible(child))
274 continue;
275 if (!child->sym) {
EGRY Gabor534a4502008-01-11 23:44:39 +0100276 printf("%*c %s\n", indent, '*', _(menu_get_prompt(child)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 continue;
278 }
279 cnt++;
280 if (child->sym == def_sym) {
281 def = cnt;
282 printf("%*c", indent, '>');
283 } else
284 printf("%*c", indent, ' ');
EGRY Gabor534a4502008-01-11 23:44:39 +0100285 printf(" %d. %s", cnt, _(menu_get_prompt(child)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 if (child->sym->name)
287 printf(" (%s)", child->sym->name);
288 if (!sym_has_value(child->sym))
EGRY Gabor534a4502008-01-11 23:44:39 +0100289 printf(_(" (NEW)"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 printf("\n");
291 }
EGRY Gabor534a4502008-01-11 23:44:39 +0100292 printf(_("%*schoice"), indent - 1, "");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 if (cnt == 1) {
294 printf("[1]: 1\n");
295 goto conf_childs;
296 }
297 printf("[1-%d", cnt);
Sam Ravnborg03d29122007-07-21 00:00:36 +0200298 if (menu_has_help(menu))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 printf("?");
300 printf("]: ");
301 switch (input_mode) {
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200302 case oldconfig:
303 case silentoldconfig:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 if (!is_new) {
305 cnt = def;
306 printf("%d\n", cnt);
307 break;
308 }
309 check_stdin();
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200310 case oldaskconfig:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 fflush(stdout);
Roman Zippel59c6a3f2006-04-09 17:26:50 +0200312 fgets(line, 128, stdin);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 strip(line);
314 if (line[0] == '?') {
Cheng Renquan66c4bd82009-07-12 16:11:48 +0800315 print_help(menu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 continue;
317 }
318 if (!line[0])
319 cnt = def;
320 else if (isdigit(line[0]))
321 cnt = atoi(line);
322 else
323 continue;
324 break;
Sam Ravnborgf443d2e2008-06-30 22:45:38 +0200325 default:
326 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 }
328
329 conf_childs:
330 for (child = menu->list; child; child = child->next) {
331 if (!child->sym || !menu_is_visible(child))
332 continue;
333 if (!--cnt)
334 break;
335 }
336 if (!child)
337 continue;
338 if (line[strlen(line) - 1] == '?') {
Cheng Renquan66c4bd82009-07-12 16:11:48 +0800339 print_help(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 continue;
341 }
342 sym_set_choice_value(sym, child->sym);
Jan Beulichf5eaa322008-01-24 11:54:23 +0000343 for (child = child->list; child; child = child->next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 indent += 2;
Jan Beulichf5eaa322008-01-24 11:54:23 +0000345 conf(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 indent -= 2;
347 }
348 return 1;
349 }
350}
351
352static void conf(struct menu *menu)
353{
354 struct symbol *sym;
355 struct property *prop;
356 struct menu *child;
357
358 if (!menu_is_visible(menu))
359 return;
360
361 sym = menu->sym;
362 prop = menu->prompt;
363 if (prop) {
364 const char *prompt;
365
366 switch (prop->type) {
367 case P_MENU:
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200368 if ((input_mode == silentoldconfig ||
369 input_mode == nonint_oldconfig ||
370 input_mode == loose_nonint_oldconfig) &&
Aristeu Rozanskif0778c82010-05-06 12:48:34 -0400371 rootEntry != menu) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 check_conf(menu);
373 return;
374 }
375 case P_COMMENT:
376 prompt = menu_get_prompt(menu);
377 if (prompt)
378 printf("%*c\n%*c %s\n%*c\n",
379 indent, '*',
EGRY Gabor534a4502008-01-11 23:44:39 +0100380 indent, '*', _(prompt),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 indent, '*');
382 default:
383 ;
384 }
385 }
386
387 if (!sym)
388 goto conf_childs;
389
390 if (sym_is_choice(sym)) {
391 conf_choice(menu);
392 if (sym->curr.tri != mod)
393 return;
394 goto conf_childs;
395 }
396
397 switch (sym->type) {
398 case S_INT:
399 case S_HEX:
400 case S_STRING:
401 conf_string(menu);
402 break;
403 default:
404 conf_sym(menu);
405 break;
406 }
407
408conf_childs:
409 if (sym)
410 indent += 2;
411 for (child = menu->list; child; child = child->next)
412 conf(child);
413 if (sym)
414 indent -= 2;
415}
416
417static void check_conf(struct menu *menu)
418{
419 struct symbol *sym;
420 struct menu *child;
421
422 if (!menu_is_visible(menu))
423 return;
424
425 sym = menu->sym;
Roman Zippel3f23ca22005-11-08 21:34:48 -0800426 if (sym && !sym_has_value(sym)) {
427 if (sym_is_changable(sym) ||
428 (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)) {
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200429 if (input_mode == nonint_oldconfig ||
430 input_mode == loose_nonint_oldconfig) {
431 if (input_mode == nonint_oldconfig &&
Aristeu Rozanskif0778c82010-05-06 12:48:34 -0400432 sym->name && !sym_is_choice_value(sym)) {
433 if (!unset_variables)
434 fprintf(stderr, "The following"
435 " variables are not set:\n");
436 fprintf(stderr, "CONFIG_%s\n",
437 sym->name);
438 unset_variables++;
439 }
440 } else {
441 if (!conf_cnt++)
442 printf(_("*\n* Restart config...\n*\n"));
443 rootEntry = menu_get_parent_menu(menu);
444 conf(rootEntry);
445 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 }
448
449 for (child = menu->list; child; child = child->next)
450 check_conf(child);
451}
452
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200453static 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467int main(int ac, char **av)
468{
Andres Salomon2f4b4892007-12-17 01:34:58 -0500469 int opt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 const char *name;
471 struct stat tmpstat;
472
EGRY Gabor534a4502008-01-11 23:44:39 +0100473 setlocale(LC_ALL, "");
474 bindtextdomain(PACKAGE, LOCALEDIR);
475 textdomain(PACKAGE);
476
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200477 while ((opt = getopt_long_only(ac, av, "", long_opts, NULL)) != -1) {
478 input_mode = (enum input_mode)opt;
Andres Salomon2f4b4892007-12-17 01:34:58 -0500479 switch (opt) {
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200480 case silentoldconfig:
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200481 sync_kconfig = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200483 case defconfig:
Andres Salomon2f4b4892007-12-17 01:34:58 -0500484 defconfig_file = optarg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200486 case randconfig:
Ingo Molnarb0fe5512009-03-12 15:15:31 +0100487 {
488 struct timeval now;
489 unsigned int seed;
490
491 /*
492 * Use microseconds derived seed,
493 * compensate for systems where it may be zero
494 */
495 gettimeofday(&now, NULL);
496
497 seed = (unsigned int)((now.tv_sec + 1) * (now.tv_usec + 1));
498 srand(seed);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 break;
Ingo Molnarb0fe5512009-03-12 15:15:31 +0100500 }
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200501 case '?':
EGRY Gabor534a4502008-01-11 23:44:39 +0100502 fprintf(stderr, _("See README for usage info\n"));
Andres Salomon2f4b4892007-12-17 01:34:58 -0500503 exit(1);
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200504 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 }
506 }
Andres Salomon2f4b4892007-12-17 01:34:58 -0500507 if (ac == optind) {
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -0700508 printf(_("%s: Kconfig file missing\n"), av[0]);
Randy Dunlap250725a2006-06-08 22:12:50 -0700509 exit(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 }
Andres Salomon2f4b4892007-12-17 01:34:58 -0500511 name = av[optind];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 conf_parse(name);
513 //zconfdump(stdout);
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200514 if (sync_kconfig) {
Markus Heidelberg284026c2009-05-18 01:36:53 +0200515 name = conf_get_configname();
516 if (stat(name, &tmpstat)) {
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200517 fprintf(stderr, _("***\n"
518 "*** You have not yet configured your kernel!\n"
Markus Heidelberg284026c2009-05-18 01:36:53 +0200519 "*** (missing kernel config file \"%s\")\n"
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200520 "***\n"
521 "*** Please run some configurator (e.g. \"make oldconfig\" or\n"
522 "*** \"make menuconfig\" or \"make xconfig\").\n"
Markus Heidelberg284026c2009-05-18 01:36:53 +0200523 "***\n"), name);
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200524 exit(1);
525 }
526 }
527
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 switch (input_mode) {
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200529 case defconfig:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 if (!defconfig_file)
531 defconfig_file = conf_get_default_confname();
532 if (conf_read(defconfig_file)) {
EGRY Gabor534a4502008-01-11 23:44:39 +0100533 printf(_("***\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 "*** Can't find default configuration \"%s\"!\n"
EGRY Gabor534a4502008-01-11 23:44:39 +0100535 "***\n"), defconfig_file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 exit(1);
537 }
538 break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200539 case silentoldconfig:
540 case oldaskconfig:
541 case oldconfig:
542 case nonint_oldconfig:
543 case loose_nonint_oldconfig:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 conf_read(NULL);
545 break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200546 case allnoconfig:
547 case allyesconfig:
548 case allmodconfig:
549 case randconfig:
Roman Zippel90389162005-11-08 21:34:49 -0800550 name = getenv("KCONFIG_ALLCONFIG");
551 if (name && !stat(name, &tmpstat)) {
Roman Zippel669bfad2006-06-08 22:12:42 -0700552 conf_read_simple(name, S_DEF_USER);
Roman Zippel90389162005-11-08 21:34:49 -0800553 break;
554 }
555 switch (input_mode) {
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200556 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;
Roman Zippel90389162005-11-08 21:34:49 -0800560 default: break;
561 }
562 if (!stat(name, &tmpstat))
Roman Zippel669bfad2006-06-08 22:12:42 -0700563 conf_read_simple(name, S_DEF_USER);
Roman Zippel90389162005-11-08 21:34:49 -0800564 else if (!stat("all.config", &tmpstat))
Roman Zippel669bfad2006-06-08 22:12:42 -0700565 conf_read_simple("all.config", S_DEF_USER);
Roman Zippel90389162005-11-08 21:34:49 -0800566 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 default:
568 break;
569 }
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200570
571 if (sync_kconfig) {
572 if (conf_get_changed()) {
573 name = getenv("KCONFIG_NOSILENTUPDATE");
574 if (name && *name) {
575 fprintf(stderr,
576 _("\n*** Kernel configuration requires explicit update.\n\n"));
577 return 1;
578 }
579 }
580 valid_stdin = isatty(0) && isatty(1) && isatty(2);
581 }
582
Sam Ravnborgf443d2e2008-06-30 22:45:38 +0200583 switch (input_mode) {
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200584 case allnoconfig:
Sam Ravnborgf443d2e2008-06-30 22:45:38 +0200585 conf_set_all_new_symbols(def_no);
586 break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200587 case allyesconfig:
Sam Ravnborgf443d2e2008-06-30 22:45:38 +0200588 conf_set_all_new_symbols(def_yes);
589 break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200590 case allmodconfig:
Sam Ravnborgf443d2e2008-06-30 22:45:38 +0200591 conf_set_all_new_symbols(def_mod);
592 break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200593 case randconfig:
Sam Ravnborgf443d2e2008-06-30 22:45:38 +0200594 conf_set_all_new_symbols(def_random);
595 break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200596 case defconfig:
Sam Ravnborg09748e12008-06-30 23:02:59 +0200597 conf_set_all_new_symbols(def_default);
598 break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200599 case oldconfig:
600 case oldaskconfig:
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200601 rootEntry = &rootmenu;
602 conf(&rootmenu);
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200603 input_mode = silentoldconfig;
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200604 /* fall through */
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200605 case nonint_oldconfig:
606 case loose_nonint_oldconfig:
607 case silentoldconfig:
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200608 /* Update until a loop caused no more changes */
609 do {
610 conf_cnt = 0;
611 check_conf(&rootmenu);
Aristeu Rozanskif0778c82010-05-06 12:48:34 -0400612 } while (conf_cnt &&
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200613 (input_mode != nonint_oldconfig &&
614 input_mode != loose_nonint_oldconfig));
Sam Ravnborgf443d2e2008-06-30 22:45:38 +0200615 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 }
Sam Ravnborgf443d2e2008-06-30 22:45:38 +0200617
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200618 if (sync_kconfig) {
619 /* silentoldconfig is used during the build so we shall update autoconf.
620 * All other commands are only used to generate a config.
621 */
622 if (conf_get_changed() && conf_write(NULL)) {
623 fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n"));
624 exit(1);
625 }
626 if (conf_write_autoconf()) {
627 fprintf(stderr, _("\n*** Error during update of the kernel configuration.\n\n"));
628 return 1;
629 }
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200630 } else if (!unset_variables || input_mode != nonint_oldconfig) {
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200631 if (conf_write(NULL)) {
632 fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n"));
633 exit(1);
634 }
Roman Zippelc955cca2006-06-08 22:12:39 -0700635 }
Aristeu Rozanskif0778c82010-05-06 12:48:34 -0400636 return unset_variables ? EUNSETOPT : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637}