blob: 6d2e936f3b6791d1bc2d49cb5dddff83edbcb84b [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();
Arnaud Lacombed8fc3202011-05-31 12:30:26 -0400109 /* fall through */
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200110 case oldaskconfig:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 fflush(stdout);
Jean Sacren4418a2b2010-08-04 16:03:16 -0600112 xfgets(line, 128, stdin);
Roman Zippelf82f3f92007-08-30 05:06:17 +0200113 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 default:
115 break;
116 }
117
118 switch (type) {
119 case S_INT:
120 case S_HEX:
121 case S_STRING:
122 printf("%s\n", def);
Roman Zippelf82f3f92007-08-30 05:06:17 +0200123 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 default:
125 ;
126 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 printf("%s", line);
Roman Zippelf82f3f92007-08-30 05:06:17 +0200128 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129}
130
Trevor Keith4356f482009-09-18 12:49:23 -0700131static int conf_string(struct menu *menu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132{
133 struct symbol *sym = menu->sym;
Sam Ravnborg03d29122007-07-21 00:00:36 +0200134 const char *def;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
136 while (1) {
EGRY Gabor534a4502008-01-11 23:44:39 +0100137 printf("%*s%s ", indent - 1, "", _(menu->prompt->text));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 printf("(%s) ", sym->name);
139 def = sym_get_string_value(sym);
140 if (sym_get_string_value(sym))
141 printf("[%s] ", def);
Roman Zippelf82f3f92007-08-30 05:06:17 +0200142 if (!conf_askvalue(sym, def))
143 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 switch (line[0]) {
145 case '\n':
146 break;
147 case '?':
148 /* print help */
149 if (line[1] == '\n') {
Cheng Renquan66c4bd82009-07-12 16:11:48 +0800150 print_help(menu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 def = NULL;
152 break;
153 }
Arnaud Lacombed8fc3202011-05-31 12:30:26 -0400154 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 default:
156 line[strlen(line)-1] = 0;
157 def = line;
158 }
159 if (def && sym_set_string_value(sym, def))
160 return 0;
161 }
162}
163
164static int conf_sym(struct menu *menu)
165{
166 struct symbol *sym = menu->sym;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 tristate oldval, newval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
169 while (1) {
EGRY Gabor534a4502008-01-11 23:44:39 +0100170 printf("%*s%s ", indent - 1, "", _(menu->prompt->text));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 if (sym->name)
172 printf("(%s) ", sym->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 putchar('[');
174 oldval = sym_get_tristate_value(sym);
175 switch (oldval) {
176 case no:
177 putchar('N');
178 break;
179 case mod:
180 putchar('M');
181 break;
182 case yes:
183 putchar('Y');
184 break;
185 }
186 if (oldval != no && sym_tristate_within_range(sym, no))
187 printf("/n");
188 if (oldval != mod && sym_tristate_within_range(sym, mod))
189 printf("/m");
190 if (oldval != yes && sym_tristate_within_range(sym, yes))
191 printf("/y");
Sam Ravnborg03d29122007-07-21 00:00:36 +0200192 if (menu_has_help(menu))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 printf("/?");
194 printf("] ");
Roman Zippelf82f3f92007-08-30 05:06:17 +0200195 if (!conf_askvalue(sym, sym_get_string_value(sym)))
196 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 strip(line);
198
199 switch (line[0]) {
200 case 'n':
201 case 'N':
202 newval = no;
203 if (!line[1] || !strcmp(&line[1], "o"))
204 break;
205 continue;
206 case 'm':
207 case 'M':
208 newval = mod;
209 if (!line[1])
210 break;
211 continue;
212 case 'y':
213 case 'Y':
214 newval = yes;
215 if (!line[1] || !strcmp(&line[1], "es"))
216 break;
217 continue;
218 case 0:
219 newval = oldval;
220 break;
221 case '?':
222 goto help;
223 default:
224 continue;
225 }
226 if (sym_set_tristate_value(sym, newval))
227 return 0;
228help:
Cheng Renquan66c4bd82009-07-12 16:11:48 +0800229 print_help(menu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 }
231}
232
233static int conf_choice(struct menu *menu)
234{
235 struct symbol *sym, *def_sym;
236 struct menu *child;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 bool is_new;
238
239 sym = menu->sym;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 is_new = !sym_has_value(sym);
241 if (sym_is_changable(sym)) {
242 conf_sym(menu);
243 sym_calc_value(sym);
244 switch (sym_get_tristate_value(sym)) {
245 case no:
246 return 1;
247 case mod:
248 return 0;
249 case yes:
250 break;
251 }
252 } else {
253 switch (sym_get_tristate_value(sym)) {
254 case no:
255 return 1;
256 case mod:
EGRY Gabor534a4502008-01-11 23:44:39 +0100257 printf("%*s%s\n", indent - 1, "", _(menu_get_prompt(menu)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 return 0;
259 case yes:
260 break;
261 }
262 }
263
264 while (1) {
265 int cnt, def;
266
EGRY Gabor534a4502008-01-11 23:44:39 +0100267 printf("%*s%s\n", indent - 1, "", _(menu_get_prompt(menu)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 def_sym = sym_get_choice_value(sym);
269 cnt = def = 0;
Roman Zippel40aee722006-04-09 17:26:39 +0200270 line[0] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 for (child = menu->list; child; child = child->next) {
272 if (!menu_is_visible(child))
273 continue;
274 if (!child->sym) {
EGRY Gabor534a4502008-01-11 23:44:39 +0100275 printf("%*c %s\n", indent, '*', _(menu_get_prompt(child)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 continue;
277 }
278 cnt++;
279 if (child->sym == def_sym) {
280 def = cnt;
281 printf("%*c", indent, '>');
282 } else
283 printf("%*c", indent, ' ');
EGRY Gabor534a4502008-01-11 23:44:39 +0100284 printf(" %d. %s", cnt, _(menu_get_prompt(child)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 if (child->sym->name)
286 printf(" (%s)", child->sym->name);
287 if (!sym_has_value(child->sym))
EGRY Gabor534a4502008-01-11 23:44:39 +0100288 printf(_(" (NEW)"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 printf("\n");
290 }
EGRY Gabor534a4502008-01-11 23:44:39 +0100291 printf(_("%*schoice"), indent - 1, "");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 if (cnt == 1) {
293 printf("[1]: 1\n");
294 goto conf_childs;
295 }
296 printf("[1-%d", cnt);
Sam Ravnborg03d29122007-07-21 00:00:36 +0200297 if (menu_has_help(menu))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 printf("?");
299 printf("]: ");
300 switch (input_mode) {
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200301 case oldconfig:
302 case silentoldconfig:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 if (!is_new) {
304 cnt = def;
305 printf("%d\n", cnt);
306 break;
307 }
308 check_stdin();
Arnaud Lacombed8fc3202011-05-31 12:30:26 -0400309 /* fall through */
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200310 case oldaskconfig:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 fflush(stdout);
Jean Sacren4418a2b2010-08-04 16:03:16 -0600312 xfgets(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;
Ben Hutchings3ba41622011-04-23 18:42:56 +0100338 if (line[0] && 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 ||
Sam Ravnborg861b4ea2010-07-31 23:35:28 +0200369 input_mode == listnewconfig ||
Sam Ravnborgef61ca82010-07-31 23:35:27 +0200370 input_mode == oldnoconfig) &&
Aristeu Rozanskif0778c82010-05-06 12:48:34 -0400371 rootEntry != menu) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 check_conf(menu);
373 return;
374 }
Arnaud Lacombed8fc3202011-05-31 12:30:26 -0400375 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 case P_COMMENT:
377 prompt = menu_get_prompt(menu);
378 if (prompt)
379 printf("%*c\n%*c %s\n%*c\n",
380 indent, '*',
EGRY Gabor534a4502008-01-11 23:44:39 +0100381 indent, '*', _(prompt),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 indent, '*');
383 default:
384 ;
385 }
386 }
387
388 if (!sym)
389 goto conf_childs;
390
391 if (sym_is_choice(sym)) {
392 conf_choice(menu);
393 if (sym->curr.tri != mod)
394 return;
395 goto conf_childs;
396 }
397
398 switch (sym->type) {
399 case S_INT:
400 case S_HEX:
401 case S_STRING:
402 conf_string(menu);
403 break;
404 default:
405 conf_sym(menu);
406 break;
407 }
408
409conf_childs:
410 if (sym)
411 indent += 2;
412 for (child = menu->list; child; child = child->next)
413 conf(child);
414 if (sym)
415 indent -= 2;
416}
417
418static void check_conf(struct menu *menu)
419{
420 struct symbol *sym;
421 struct menu *child;
422
423 if (!menu_is_visible(menu))
424 return;
425
426 sym = menu->sym;
Roman Zippel3f23ca22005-11-08 21:34:48 -0800427 if (sym && !sym_has_value(sym)) {
428 if (sym_is_changable(sym) ||
429 (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)) {
Sam Ravnborg861b4ea2010-07-31 23:35:28 +0200430 if (input_mode == listnewconfig) {
431 if (sym->name && !sym_is_choice_value(sym)) {
Arnaud Lacombeffb59572010-08-14 23:57:43 -0400432 printf("%s%s\n", CONFIG_, sym->name);
Aristeu Rozanskif0778c82010-05-06 12:48:34 -0400433 }
Kyle McMartin71d80662010-09-01 11:21:30 -0400434 } else if (input_mode != oldnoconfig) {
Aristeu Rozanskif0778c82010-05-06 12:48:34 -0400435 if (!conf_cnt++)
436 printf(_("*\n* Restart config...\n*\n"));
437 rootEntry = menu_get_parent_menu(menu);
438 conf(rootEntry);
439 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 }
442
443 for (child = menu->list; child; child = child->next)
444 check_conf(child);
445}
446
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200447static struct option long_opts[] = {
448 {"oldaskconfig", no_argument, NULL, oldaskconfig},
449 {"oldconfig", no_argument, NULL, oldconfig},
450 {"silentoldconfig", no_argument, NULL, silentoldconfig},
451 {"defconfig", optional_argument, NULL, defconfig},
Sam Ravnborg7cf3d732010-07-31 23:35:34 +0200452 {"savedefconfig", required_argument, NULL, savedefconfig},
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200453 {"allnoconfig", no_argument, NULL, allnoconfig},
454 {"allyesconfig", no_argument, NULL, allyesconfig},
455 {"allmodconfig", no_argument, NULL, allmodconfig},
Sam Ravnborg0748cb32010-07-31 23:35:31 +0200456 {"alldefconfig", no_argument, NULL, alldefconfig},
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200457 {"randconfig", no_argument, NULL, randconfig},
Sam Ravnborg861b4ea2010-07-31 23:35:28 +0200458 {"listnewconfig", no_argument, NULL, listnewconfig},
Sam Ravnborgef61ca82010-07-31 23:35:27 +0200459 {"oldnoconfig", no_argument, NULL, oldnoconfig},
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200460 {NULL, 0, NULL, 0}
461};
462
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463int main(int ac, char **av)
464{
Andres Salomon2f4b4892007-12-17 01:34:58 -0500465 int opt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 const char *name;
467 struct stat tmpstat;
468
EGRY Gabor534a4502008-01-11 23:44:39 +0100469 setlocale(LC_ALL, "");
470 bindtextdomain(PACKAGE, LOCALEDIR);
471 textdomain(PACKAGE);
472
Arnaud Lacombec94d3fb2010-08-23 12:01:24 -0400473 while ((opt = getopt_long(ac, av, "", long_opts, NULL)) != -1) {
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200474 input_mode = (enum input_mode)opt;
Andres Salomon2f4b4892007-12-17 01:34:58 -0500475 switch (opt) {
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200476 case silentoldconfig:
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200477 sync_kconfig = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200479 case defconfig:
Sam Ravnborg7cf3d732010-07-31 23:35:34 +0200480 case savedefconfig:
Andres Salomon2f4b4892007-12-17 01:34:58 -0500481 defconfig_file = optarg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200483 case randconfig:
Ingo Molnarb0fe5512009-03-12 15:15:31 +0100484 {
485 struct timeval now;
486 unsigned int seed;
487
488 /*
489 * Use microseconds derived seed,
490 * compensate for systems where it may be zero
491 */
492 gettimeofday(&now, NULL);
493
494 seed = (unsigned int)((now.tv_sec + 1) * (now.tv_usec + 1));
495 srand(seed);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 break;
Ingo Molnarb0fe5512009-03-12 15:15:31 +0100497 }
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200498 case '?':
EGRY Gabor534a4502008-01-11 23:44:39 +0100499 fprintf(stderr, _("See README for usage info\n"));
Andres Salomon2f4b4892007-12-17 01:34:58 -0500500 exit(1);
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200501 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 }
503 }
Andres Salomon2f4b4892007-12-17 01:34:58 -0500504 if (ac == optind) {
Arnaldo Carvalho de Melo3b9fa092005-05-05 15:09:46 -0700505 printf(_("%s: Kconfig file missing\n"), av[0]);
Randy Dunlap250725a2006-06-08 22:12:50 -0700506 exit(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 }
Andres Salomon2f4b4892007-12-17 01:34:58 -0500508 name = av[optind];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 conf_parse(name);
510 //zconfdump(stdout);
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200511 if (sync_kconfig) {
Markus Heidelberg284026c2009-05-18 01:36:53 +0200512 name = conf_get_configname();
513 if (stat(name, &tmpstat)) {
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200514 fprintf(stderr, _("***\n"
Arnaud Lacombe652cf982010-08-14 23:51:40 -0400515 "*** Configuration file \"%s\" not found!\n"
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200516 "***\n"
517 "*** Please run some configurator (e.g. \"make oldconfig\" or\n"
518 "*** \"make menuconfig\" or \"make xconfig\").\n"
Markus Heidelberg284026c2009-05-18 01:36:53 +0200519 "***\n"), name);
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200520 exit(1);
521 }
522 }
523
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 switch (input_mode) {
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200525 case defconfig:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 if (!defconfig_file)
527 defconfig_file = conf_get_default_confname();
528 if (conf_read(defconfig_file)) {
EGRY Gabor534a4502008-01-11 23:44:39 +0100529 printf(_("***\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 "*** Can't find default configuration \"%s\"!\n"
EGRY Gabor534a4502008-01-11 23:44:39 +0100531 "***\n"), defconfig_file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 exit(1);
533 }
534 break;
Sam Ravnborg7cf3d732010-07-31 23:35:34 +0200535 case savedefconfig:
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200536 case silentoldconfig:
537 case oldaskconfig:
538 case oldconfig:
Sam Ravnborg861b4ea2010-07-31 23:35:28 +0200539 case listnewconfig:
Sam Ravnborgef61ca82010-07-31 23:35:27 +0200540 case oldnoconfig:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 conf_read(NULL);
542 break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200543 case allnoconfig:
544 case allyesconfig:
545 case allmodconfig:
Sam Ravnborg0748cb32010-07-31 23:35:31 +0200546 case alldefconfig:
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200547 case randconfig:
Roman Zippel90389162005-11-08 21:34:49 -0800548 name = getenv("KCONFIG_ALLCONFIG");
549 if (name && !stat(name, &tmpstat)) {
Roman Zippel669bfad2006-06-08 22:12:42 -0700550 conf_read_simple(name, S_DEF_USER);
Roman Zippel90389162005-11-08 21:34:49 -0800551 break;
552 }
553 switch (input_mode) {
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200554 case allnoconfig: name = "allno.config"; break;
555 case allyesconfig: name = "allyes.config"; break;
556 case allmodconfig: name = "allmod.config"; break;
Sam Ravnborg0748cb32010-07-31 23:35:31 +0200557 case alldefconfig: name = "alldef.config"; break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200558 case randconfig: name = "allrandom.config"; break;
Roman Zippel90389162005-11-08 21:34:49 -0800559 default: break;
560 }
561 if (!stat(name, &tmpstat))
Roman Zippel669bfad2006-06-08 22:12:42 -0700562 conf_read_simple(name, S_DEF_USER);
Roman Zippel90389162005-11-08 21:34:49 -0800563 else if (!stat("all.config", &tmpstat))
Roman Zippel669bfad2006-06-08 22:12:42 -0700564 conf_read_simple("all.config", S_DEF_USER);
Roman Zippel90389162005-11-08 21:34:49 -0800565 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 default:
567 break;
568 }
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200569
570 if (sync_kconfig) {
571 if (conf_get_changed()) {
572 name = getenv("KCONFIG_NOSILENTUPDATE");
573 if (name && *name) {
574 fprintf(stderr,
Arnaud Lacombe652cf982010-08-14 23:51:40 -0400575 _("\n*** The configuration requires explicit update.\n\n"));
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200576 return 1;
577 }
578 }
579 valid_stdin = isatty(0) && isatty(1) && isatty(2);
580 }
581
Sam Ravnborgf443d2e2008-06-30 22:45:38 +0200582 switch (input_mode) {
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200583 case allnoconfig:
Sam Ravnborgf443d2e2008-06-30 22:45:38 +0200584 conf_set_all_new_symbols(def_no);
585 break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200586 case allyesconfig:
Sam Ravnborgf443d2e2008-06-30 22:45:38 +0200587 conf_set_all_new_symbols(def_yes);
588 break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200589 case allmodconfig:
Sam Ravnborgf443d2e2008-06-30 22:45:38 +0200590 conf_set_all_new_symbols(def_mod);
591 break;
Sam Ravnborg0748cb32010-07-31 23:35:31 +0200592 case alldefconfig:
593 conf_set_all_new_symbols(def_default);
594 break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200595 case randconfig:
Sam Ravnborgf443d2e2008-06-30 22:45:38 +0200596 conf_set_all_new_symbols(def_random);
597 break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200598 case defconfig:
Sam Ravnborg09748e12008-06-30 23:02:59 +0200599 conf_set_all_new_symbols(def_default);
600 break;
Sam Ravnborg7cf3d732010-07-31 23:35:34 +0200601 case savedefconfig:
602 break;
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200603 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 Ravnborg14828342010-08-06 07:13:54 +0200608 case oldconfig:
Sam Ravnborg861b4ea2010-07-31 23:35:28 +0200609 case listnewconfig:
Sam Ravnborgef61ca82010-07-31 23:35:27 +0200610 case oldnoconfig:
Sam Ravnborg4062f1a2010-07-31 23:35:26 +0200611 case silentoldconfig:
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200612 /* Update until a loop caused no more changes */
613 do {
614 conf_cnt = 0;
615 check_conf(&rootmenu);
Aristeu Rozanskif0778c82010-05-06 12:48:34 -0400616 } while (conf_cnt &&
Sam Ravnborg861b4ea2010-07-31 23:35:28 +0200617 (input_mode != listnewconfig &&
Sam Ravnborgef61ca82010-07-31 23:35:27 +0200618 input_mode != oldnoconfig));
Sam Ravnborgf443d2e2008-06-30 22:45:38 +0200619 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 }
Sam Ravnborgf443d2e2008-06-30 22:45:38 +0200621
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200622 if (sync_kconfig) {
623 /* silentoldconfig is used during the build so we shall update autoconf.
624 * All other commands are only used to generate a config.
625 */
626 if (conf_get_changed() && conf_write(NULL)) {
Arnaud Lacombe652cf982010-08-14 23:51:40 -0400627 fprintf(stderr, _("\n*** Error during writing of the configuration.\n\n"));
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200628 exit(1);
629 }
630 if (conf_write_autoconf()) {
Arnaud Lacombe652cf982010-08-14 23:51:40 -0400631 fprintf(stderr, _("\n*** Error during update of the configuration.\n\n"));
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200632 return 1;
633 }
Sam Ravnborg7cf3d732010-07-31 23:35:34 +0200634 } else if (input_mode == savedefconfig) {
635 if (conf_write_defconfig(defconfig_file)) {
636 fprintf(stderr, _("n*** Error while saving defconfig to: %s\n\n"),
637 defconfig_file);
638 return 1;
639 }
Sam Ravnborg861b4ea2010-07-31 23:35:28 +0200640 } else if (input_mode != listnewconfig) {
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200641 if (conf_write(NULL)) {
Arnaud Lacombe652cf982010-08-14 23:51:40 -0400642 fprintf(stderr, _("\n*** Error during writing of the configuration.\n\n"));
zippel@linux-m68k.org204c96f2008-09-29 05:27:10 +0200643 exit(1);
644 }
Roman Zippelc955cca2006-06-08 22:12:39 -0700645 }
Sam Ravnborg861b4ea2010-07-31 23:35:28 +0200646 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647}
Jean Sacren4418a2b2010-08-04 16:03:16 -0600648/*
649 * Helper function to facilitate fgets() by Jean Sacren.
650 */
651void xfgets(str, size, in)
652 char *str;
653 int size;
654 FILE *in;
655{
656 if (fgets(str, size, in) == NULL)
657 fprintf(stderr, "\nError in reading or end of file.\n");
658}