blob: 4b3ad9b862b174fab6262a83cd682ee0c3a3a5d5 [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 Ravnborg7cf3d732010-07-31 23:35:34 +020033 savedefconfig,
Sam Ravnborg861b4ea2010-07-31 23:35:28 +020034 listnewconfig,
Sam Ravnborgef61ca82010-07-31 23:35:27 +020035 oldnoconfig,
Sam Ravnborg4062f1a2010-07-31 23:35:26 +020036} input_mode = oldaskconfig;
37
Linus Torvalds1da177e2005-04-16 15:20:36 -070038char *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;
46
Cheng Renquan66c4bd82009-07-12 16:11:48 +080047static void print_help(struct menu *menu)
Sam Ravnborg03d29122007-07-21 00:00:36 +020048{
Cheng Renquan66c4bd82009-07-12 16:11:48 +080049 struct gstr help = str_new();
50
51 menu_get_ext_help(menu, &help);
52
53 printf("\n%s\n", str_get(&help));
54 str_free(&help);
Sam Ravnborg03d29122007-07-21 00:00:36 +020055}
56
J.A. Magallon48b9d032005-06-25 14:59:22 -070057static void strip(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -070058{
J.A. Magallon48b9d032005-06-25 14:59:22 -070059 char *p = str;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 int l;
61
62 while ((isspace(*p)))
63 p++;
64 l = strlen(p);
65 if (p != str)
66 memmove(str, p, l + 1);
67 if (!l)
68 return;
69 p = str + l - 1;
70 while ((isspace(*p)))
71 *p-- = 0;
72}
73
74static void check_stdin(void)
75{
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +020076 if (!valid_stdin) {
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -070077 printf(_("aborted!\n\n"));
78 printf(_("Console input/output is redirected. "));
79 printf(_("Run 'make oldconfig' to update configuration.\n\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 exit(1);
81 }
82}
83
Roman Zippelf82f3f92007-08-30 05:06:17 +020084static int conf_askvalue(struct symbol *sym, const char *def)
Linus Torvalds1da177e2005-04-16 15:20:36 -070085{
86 enum symbol_type type = sym_get_type(sym);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
88 if (!sym_has_value(sym))
EGRY Gabor534a4502008-01-11 23:44:39 +010089 printf(_("(NEW) "));
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
91 line[0] = '\n';
92 line[1] = 0;
93
94 if (!sym_is_changable(sym)) {
95 printf("%s\n", def);
96 line[0] = '\n';
97 line[1] = 0;
Roman Zippelf82f3f92007-08-30 05:06:17 +020098 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 }
100
101 switch (input_mode) {
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200102 case oldconfig:
103 case silentoldconfig:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 if (sym_has_value(sym)) {
105 printf("%s\n", def);
Roman Zippelf82f3f92007-08-30 05:06:17 +0200106 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 }
108 check_stdin();
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200109 case oldaskconfig:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 fflush(stdout);
Jean Sacren4418a2b2010-08-04 16:03:16 -0600111 xfgets(line, 128, stdin);
Roman Zippelf82f3f92007-08-30 05:06:17 +0200112 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 default:
114 break;
115 }
116
117 switch (type) {
118 case S_INT:
119 case S_HEX:
120 case S_STRING:
121 printf("%s\n", def);
Roman Zippelf82f3f92007-08-30 05:06:17 +0200122 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 default:
124 ;
125 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 printf("%s", line);
Roman Zippelf82f3f92007-08-30 05:06:17 +0200127 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128}
129
Trevor Keith4356f482009-09-18 12:49:23 -0700130static int conf_string(struct menu *menu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131{
132 struct symbol *sym = menu->sym;
Sam Ravnborg03d29122007-07-21 00:00:36 +0200133 const char *def;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
135 while (1) {
EGRY Gabor534a4502008-01-11 23:44:39 +0100136 printf("%*s%s ", indent - 1, "", _(menu->prompt->text));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 printf("(%s) ", sym->name);
138 def = sym_get_string_value(sym);
139 if (sym_get_string_value(sym))
140 printf("[%s] ", def);
Roman Zippelf82f3f92007-08-30 05:06:17 +0200141 if (!conf_askvalue(sym, def))
142 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 switch (line[0]) {
144 case '\n':
145 break;
146 case '?':
147 /* print help */
148 if (line[1] == '\n') {
Cheng Renquan66c4bd82009-07-12 16:11:48 +0800149 print_help(menu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 def = NULL;
151 break;
152 }
153 default:
154 line[strlen(line)-1] = 0;
155 def = line;
156 }
157 if (def && sym_set_string_value(sym, def))
158 return 0;
159 }
160}
161
162static int conf_sym(struct menu *menu)
163{
164 struct symbol *sym = menu->sym;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 tristate oldval, newval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
167 while (1) {
EGRY Gabor534a4502008-01-11 23:44:39 +0100168 printf("%*s%s ", indent - 1, "", _(menu->prompt->text));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 if (sym->name)
170 printf("(%s) ", sym->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 putchar('[');
172 oldval = sym_get_tristate_value(sym);
173 switch (oldval) {
174 case no:
175 putchar('N');
176 break;
177 case mod:
178 putchar('M');
179 break;
180 case yes:
181 putchar('Y');
182 break;
183 }
184 if (oldval != no && sym_tristate_within_range(sym, no))
185 printf("/n");
186 if (oldval != mod && sym_tristate_within_range(sym, mod))
187 printf("/m");
188 if (oldval != yes && sym_tristate_within_range(sym, yes))
189 printf("/y");
Sam Ravnborg03d29122007-07-21 00:00:36 +0200190 if (menu_has_help(menu))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 printf("/?");
192 printf("] ");
Roman Zippelf82f3f92007-08-30 05:06:17 +0200193 if (!conf_askvalue(sym, sym_get_string_value(sym)))
194 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 strip(line);
196
197 switch (line[0]) {
198 case 'n':
199 case 'N':
200 newval = no;
201 if (!line[1] || !strcmp(&line[1], "o"))
202 break;
203 continue;
204 case 'm':
205 case 'M':
206 newval = mod;
207 if (!line[1])
208 break;
209 continue;
210 case 'y':
211 case 'Y':
212 newval = yes;
213 if (!line[1] || !strcmp(&line[1], "es"))
214 break;
215 continue;
216 case 0:
217 newval = oldval;
218 break;
219 case '?':
220 goto help;
221 default:
222 continue;
223 }
224 if (sym_set_tristate_value(sym, newval))
225 return 0;
226help:
Cheng Renquan66c4bd82009-07-12 16:11:48 +0800227 print_help(menu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 }
229}
230
231static int conf_choice(struct menu *menu)
232{
233 struct symbol *sym, *def_sym;
234 struct menu *child;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 bool is_new;
236
237 sym = menu->sym;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 is_new = !sym_has_value(sym);
239 if (sym_is_changable(sym)) {
240 conf_sym(menu);
241 sym_calc_value(sym);
242 switch (sym_get_tristate_value(sym)) {
243 case no:
244 return 1;
245 case mod:
246 return 0;
247 case yes:
248 break;
249 }
250 } else {
251 switch (sym_get_tristate_value(sym)) {
252 case no:
253 return 1;
254 case mod:
EGRY Gabor534a4502008-01-11 23:44:39 +0100255 printf("%*s%s\n", indent - 1, "", _(menu_get_prompt(menu)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 return 0;
257 case yes:
258 break;
259 }
260 }
261
262 while (1) {
263 int cnt, def;
264
EGRY Gabor534a4502008-01-11 23:44:39 +0100265 printf("%*s%s\n", indent - 1, "", _(menu_get_prompt(menu)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 def_sym = sym_get_choice_value(sym);
267 cnt = def = 0;
Roman Zippel40aee722006-04-09 17:26:39 +0200268 line[0] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 for (child = menu->list; child; child = child->next) {
270 if (!menu_is_visible(child))
271 continue;
272 if (!child->sym) {
EGRY Gabor534a4502008-01-11 23:44:39 +0100273 printf("%*c %s\n", indent, '*', _(menu_get_prompt(child)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 continue;
275 }
276 cnt++;
277 if (child->sym == def_sym) {
278 def = cnt;
279 printf("%*c", indent, '>');
280 } else
281 printf("%*c", indent, ' ');
EGRY Gabor534a4502008-01-11 23:44:39 +0100282 printf(" %d. %s", cnt, _(menu_get_prompt(child)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 if (child->sym->name)
284 printf(" (%s)", child->sym->name);
285 if (!sym_has_value(child->sym))
EGRY Gabor534a4502008-01-11 23:44:39 +0100286 printf(_(" (NEW)"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 printf("\n");
288 }
EGRY Gabor534a4502008-01-11 23:44:39 +0100289 printf(_("%*schoice"), indent - 1, "");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 if (cnt == 1) {
291 printf("[1]: 1\n");
292 goto conf_childs;
293 }
294 printf("[1-%d", cnt);
Sam Ravnborg03d29122007-07-21 00:00:36 +0200295 if (menu_has_help(menu))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 printf("?");
297 printf("]: ");
298 switch (input_mode) {
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200299 case oldconfig:
300 case silentoldconfig:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 if (!is_new) {
302 cnt = def;
303 printf("%d\n", cnt);
304 break;
305 }
306 check_stdin();
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200307 case oldaskconfig:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 fflush(stdout);
Jean Sacren4418a2b2010-08-04 16:03:16 -0600309 xfgets(line, 128, stdin);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 strip(line);
311 if (line[0] == '?') {
Cheng Renquan66c4bd82009-07-12 16:11:48 +0800312 print_help(menu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 continue;
314 }
315 if (!line[0])
316 cnt = def;
317 else if (isdigit(line[0]))
318 cnt = atoi(line);
319 else
320 continue;
321 break;
Sam Ravnborgf443d2e2008-06-30 22:45:38 +0200322 default:
323 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 }
325
326 conf_childs:
327 for (child = menu->list; child; child = child->next) {
328 if (!child->sym || !menu_is_visible(child))
329 continue;
330 if (!--cnt)
331 break;
332 }
333 if (!child)
334 continue;
335 if (line[strlen(line) - 1] == '?') {
Cheng Renquan66c4bd82009-07-12 16:11:48 +0800336 print_help(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 continue;
338 }
339 sym_set_choice_value(sym, child->sym);
Jan Beulichf5eaa322008-01-24 11:54:23 +0000340 for (child = child->list; child; child = child->next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 indent += 2;
Jan Beulichf5eaa322008-01-24 11:54:23 +0000342 conf(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 indent -= 2;
344 }
345 return 1;
346 }
347}
348
349static void conf(struct menu *menu)
350{
351 struct symbol *sym;
352 struct property *prop;
353 struct menu *child;
354
355 if (!menu_is_visible(menu))
356 return;
357
358 sym = menu->sym;
359 prop = menu->prompt;
360 if (prop) {
361 const char *prompt;
362
363 switch (prop->type) {
364 case P_MENU:
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200365 if ((input_mode == silentoldconfig ||
Sam Ravnborg861b4ea2010-07-31 23:35:28 +0200366 input_mode == listnewconfig ||
Sam Ravnborgef61ca82010-07-31 23:35:27 +0200367 input_mode == oldnoconfig) &&
Aristeu Rozanskif0778c82010-05-06 12:48:34 -0400368 rootEntry != menu) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 check_conf(menu);
370 return;
371 }
372 case P_COMMENT:
373 prompt = menu_get_prompt(menu);
374 if (prompt)
375 printf("%*c\n%*c %s\n%*c\n",
376 indent, '*',
EGRY Gabor534a4502008-01-11 23:44:39 +0100377 indent, '*', _(prompt),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 indent, '*');
379 default:
380 ;
381 }
382 }
383
384 if (!sym)
385 goto conf_childs;
386
387 if (sym_is_choice(sym)) {
388 conf_choice(menu);
389 if (sym->curr.tri != mod)
390 return;
391 goto conf_childs;
392 }
393
394 switch (sym->type) {
395 case S_INT:
396 case S_HEX:
397 case S_STRING:
398 conf_string(menu);
399 break;
400 default:
401 conf_sym(menu);
402 break;
403 }
404
405conf_childs:
406 if (sym)
407 indent += 2;
408 for (child = menu->list; child; child = child->next)
409 conf(child);
410 if (sym)
411 indent -= 2;
412}
413
414static void check_conf(struct menu *menu)
415{
416 struct symbol *sym;
417 struct menu *child;
418
419 if (!menu_is_visible(menu))
420 return;
421
422 sym = menu->sym;
Roman Zippel3f23ca22005-11-08 21:34:48 -0800423 if (sym && !sym_has_value(sym)) {
424 if (sym_is_changable(sym) ||
425 (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)) {
Sam Ravnborg861b4ea2010-07-31 23:35:28 +0200426 if (input_mode == listnewconfig) {
427 if (sym->name && !sym_is_choice_value(sym)) {
428 printf("CONFIG_%s\n", sym->name);
Aristeu Rozanskif0778c82010-05-06 12:48:34 -0400429 }
430 } else {
431 if (!conf_cnt++)
432 printf(_("*\n* Restart config...\n*\n"));
433 rootEntry = menu_get_parent_menu(menu);
434 conf(rootEntry);
435 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 }
438
439 for (child = menu->list; child; child = child->next)
440 check_conf(child);
441}
442
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200443static struct option long_opts[] = {
444 {"oldaskconfig", no_argument, NULL, oldaskconfig},
445 {"oldconfig", no_argument, NULL, oldconfig},
446 {"silentoldconfig", no_argument, NULL, silentoldconfig},
447 {"defconfig", optional_argument, NULL, defconfig},
Sam Ravnborg7cf3d732010-07-31 23:35:34 +0200448 {"savedefconfig", required_argument, NULL, savedefconfig},
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200449 {"allnoconfig", no_argument, NULL, allnoconfig},
450 {"allyesconfig", no_argument, NULL, allyesconfig},
451 {"allmodconfig", no_argument, NULL, allmodconfig},
Sam Ravnborg0748cb32010-07-31 23:35:31 +0200452 {"alldefconfig", no_argument, NULL, alldefconfig},
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200453 {"randconfig", no_argument, NULL, randconfig},
Sam Ravnborg861b4ea2010-07-31 23:35:28 +0200454 {"listnewconfig", no_argument, NULL, listnewconfig},
Sam Ravnborgef61ca82010-07-31 23:35:27 +0200455 {"oldnoconfig", no_argument, NULL, oldnoconfig},
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200456 {NULL, 0, NULL, 0}
457};
458
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459int main(int ac, char **av)
460{
Andres Salomon2f4b4892007-12-17 01:34:58 -0500461 int opt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 const char *name;
463 struct stat tmpstat;
464
EGRY Gabor534a4502008-01-11 23:44:39 +0100465 setlocale(LC_ALL, "");
466 bindtextdomain(PACKAGE, LOCALEDIR);
467 textdomain(PACKAGE);
468
Arnaud Lacombec94d3fb2010-08-23 12:01:24 -0400469 while ((opt = getopt_long(ac, av, "", long_opts, NULL)) != -1) {
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200470 input_mode = (enum input_mode)opt;
Andres Salomon2f4b4892007-12-17 01:34:58 -0500471 switch (opt) {
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200472 case silentoldconfig:
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200473 sync_kconfig = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200475 case defconfig:
Sam Ravnborg7cf3d732010-07-31 23:35:34 +0200476 case savedefconfig:
Andres Salomon2f4b4892007-12-17 01:34:58 -0500477 defconfig_file = optarg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200479 case randconfig:
Ingo Molnarb0fe5512009-03-12 15:15:31 +0100480 {
481 struct timeval now;
482 unsigned int seed;
483
484 /*
485 * Use microseconds derived seed,
486 * compensate for systems where it may be zero
487 */
488 gettimeofday(&now, NULL);
489
490 seed = (unsigned int)((now.tv_sec + 1) * (now.tv_usec + 1));
491 srand(seed);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 break;
Ingo Molnarb0fe5512009-03-12 15:15:31 +0100493 }
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200494 case '?':
EGRY Gabor534a4502008-01-11 23:44:39 +0100495 fprintf(stderr, _("See README for usage info\n"));
Andres Salomon2f4b4892007-12-17 01:34:58 -0500496 exit(1);
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200497 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 }
499 }
Andres Salomon2f4b4892007-12-17 01:34:58 -0500500 if (ac == optind) {
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -0700501 printf(_("%s: Kconfig file missing\n"), av[0]);
Randy Dunlap250725a2006-06-08 22:12:50 -0700502 exit(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 }
Andres Salomon2f4b4892007-12-17 01:34:58 -0500504 name = av[optind];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 conf_parse(name);
506 //zconfdump(stdout);
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200507 if (sync_kconfig) {
Markus Heidelberg284026c2009-05-18 01:36:53 +0200508 name = conf_get_configname();
509 if (stat(name, &tmpstat)) {
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200510 fprintf(stderr, _("***\n"
511 "*** You have not yet configured your kernel!\n"
Markus Heidelberg284026c2009-05-18 01:36:53 +0200512 "*** (missing kernel config file \"%s\")\n"
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200513 "***\n"
514 "*** Please run some configurator (e.g. \"make oldconfig\" or\n"
515 "*** \"make menuconfig\" or \"make xconfig\").\n"
Markus Heidelberg284026c2009-05-18 01:36:53 +0200516 "***\n"), name);
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200517 exit(1);
518 }
519 }
520
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 switch (input_mode) {
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200522 case defconfig:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 if (!defconfig_file)
524 defconfig_file = conf_get_default_confname();
525 if (conf_read(defconfig_file)) {
EGRY Gabor534a4502008-01-11 23:44:39 +0100526 printf(_("***\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 "*** Can't find default configuration \"%s\"!\n"
EGRY Gabor534a4502008-01-11 23:44:39 +0100528 "***\n"), defconfig_file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 exit(1);
530 }
531 break;
Sam Ravnborg7cf3d732010-07-31 23:35:34 +0200532 case savedefconfig:
533 conf_read(NULL);
534 break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200535 case silentoldconfig:
536 case oldaskconfig:
537 case oldconfig:
Sam Ravnborg861b4ea2010-07-31 23:35:28 +0200538 case listnewconfig:
Sam Ravnborgef61ca82010-07-31 23:35:27 +0200539 case oldnoconfig:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 conf_read(NULL);
541 break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200542 case allnoconfig:
543 case allyesconfig:
544 case allmodconfig:
Sam Ravnborg0748cb32010-07-31 23:35:31 +0200545 case alldefconfig:
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200546 case randconfig:
Roman Zippel90389162005-11-08 21:34:49 -0800547 name = getenv("KCONFIG_ALLCONFIG");
548 if (name && !stat(name, &tmpstat)) {
Roman Zippel669bfad2006-06-08 22:12:42 -0700549 conf_read_simple(name, S_DEF_USER);
Roman Zippel90389162005-11-08 21:34:49 -0800550 break;
551 }
552 switch (input_mode) {
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200553 case allnoconfig: name = "allno.config"; break;
554 case allyesconfig: name = "allyes.config"; break;
555 case allmodconfig: name = "allmod.config"; break;
Sam Ravnborg0748cb32010-07-31 23:35:31 +0200556 case alldefconfig: name = "alldef.config"; break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200557 case randconfig: name = "allrandom.config"; break;
Roman Zippel90389162005-11-08 21:34:49 -0800558 default: break;
559 }
560 if (!stat(name, &tmpstat))
Roman Zippel669bfad2006-06-08 22:12:42 -0700561 conf_read_simple(name, S_DEF_USER);
Roman Zippel90389162005-11-08 21:34:49 -0800562 else if (!stat("all.config", &tmpstat))
Roman Zippel669bfad2006-06-08 22:12:42 -0700563 conf_read_simple("all.config", S_DEF_USER);
Roman Zippel90389162005-11-08 21:34:49 -0800564 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 default:
566 break;
567 }
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200568
569 if (sync_kconfig) {
570 if (conf_get_changed()) {
571 name = getenv("KCONFIG_NOSILENTUPDATE");
572 if (name && *name) {
573 fprintf(stderr,
574 _("\n*** Kernel configuration requires explicit update.\n\n"));
575 return 1;
576 }
577 }
578 valid_stdin = isatty(0) && isatty(1) && isatty(2);
579 }
580
Sam Ravnborgf443d2e2008-06-30 22:45:38 +0200581 switch (input_mode) {
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200582 case allnoconfig:
Sam Ravnborgf443d2e2008-06-30 22:45:38 +0200583 conf_set_all_new_symbols(def_no);
584 break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200585 case allyesconfig:
Sam Ravnborgf443d2e2008-06-30 22:45:38 +0200586 conf_set_all_new_symbols(def_yes);
587 break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200588 case allmodconfig:
Sam Ravnborgf443d2e2008-06-30 22:45:38 +0200589 conf_set_all_new_symbols(def_mod);
590 break;
Sam Ravnborg0748cb32010-07-31 23:35:31 +0200591 case alldefconfig:
592 conf_set_all_new_symbols(def_default);
593 break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200594 case randconfig:
Sam Ravnborgf443d2e2008-06-30 22:45:38 +0200595 conf_set_all_new_symbols(def_random);
596 break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200597 case defconfig:
Sam Ravnborg09748e12008-06-30 23:02:59 +0200598 conf_set_all_new_symbols(def_default);
599 break;
Sam Ravnborg7cf3d732010-07-31 23:35:34 +0200600 case savedefconfig:
601 break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200602 case oldconfig:
603 case oldaskconfig:
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200604 rootEntry = &rootmenu;
605 conf(&rootmenu);
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200606 input_mode = silentoldconfig;
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200607 /* fall through */
Sam Ravnborg861b4ea2010-07-31 23:35:28 +0200608 case listnewconfig:
Sam Ravnborgef61ca82010-07-31 23:35:27 +0200609 case oldnoconfig:
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200610 case silentoldconfig:
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200611 /* Update until a loop caused no more changes */
612 do {
613 conf_cnt = 0;
614 check_conf(&rootmenu);
Aristeu Rozanskif0778c82010-05-06 12:48:34 -0400615 } while (conf_cnt &&
Sam Ravnborg861b4ea2010-07-31 23:35:28 +0200616 (input_mode != listnewconfig &&
Sam Ravnborgef61ca82010-07-31 23:35:27 +0200617 input_mode != oldnoconfig));
Sam Ravnborgf443d2e2008-06-30 22:45:38 +0200618 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 }
Sam Ravnborgf443d2e2008-06-30 22:45:38 +0200620
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200621 if (sync_kconfig) {
622 /* silentoldconfig is used during the build so we shall update autoconf.
623 * All other commands are only used to generate a config.
624 */
625 if (conf_get_changed() && conf_write(NULL)) {
626 fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n"));
627 exit(1);
628 }
629 if (conf_write_autoconf()) {
630 fprintf(stderr, _("\n*** Error during update of the kernel configuration.\n\n"));
631 return 1;
632 }
Sam Ravnborg7cf3d732010-07-31 23:35:34 +0200633 } else if (input_mode == savedefconfig) {
634 if (conf_write_defconfig(defconfig_file)) {
635 fprintf(stderr, _("n*** Error while saving defconfig to: %s\n\n"),
636 defconfig_file);
637 return 1;
638 }
Sam Ravnborg861b4ea2010-07-31 23:35:28 +0200639 } else if (input_mode != listnewconfig) {
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200640 if (conf_write(NULL)) {
641 fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n"));
642 exit(1);
643 }
Roman Zippelc955cca2006-06-08 22:12:39 -0700644 }
Sam Ravnborg861b4ea2010-07-31 23:35:28 +0200645 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646}
Jean Sacren4418a2b2010-08-04 16:03:16 -0600647/*
648 * Helper function to facilitate fgets() by Jean Sacren.
649 */
650void xfgets(str, size, in)
651 char *str;
652 int size;
653 FILE *in;
654{
655 if (fgets(str, size, in) == NULL)
656 fprintf(stderr, "\nError in reading or end of file.\n");
657}