Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> |
| 3 | * Released under the terms of the GNU GPL v2.0. |
| 4 | */ |
| 5 | |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 6 | #include <locale.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | #include <ctype.h> |
Markus Mayer | 74dba80 | 2015-12-09 14:56:12 -0800 | [diff] [blame] | 8 | #include <limits.h> |
Randy Dunlap | 9dfb563 | 2006-04-18 22:21:53 -0700 | [diff] [blame] | 9 | #include <stdio.h> |
Ladislav Michl | 75ff430 | 2008-01-09 16:36:19 +0100 | [diff] [blame] | 10 | #include <stdlib.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <string.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <time.h> |
Ladislav Michl | 75ff430 | 2008-01-09 16:36:19 +0100 | [diff] [blame] | 13 | #include <unistd.h> |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 14 | #include <getopt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <sys/stat.h> |
Ingo Molnar | b0fe551 | 2009-03-12 15:15:31 +0100 | [diff] [blame] | 16 | #include <sys/time.h> |
Yann E. MORIN | 0d8024c | 2013-04-13 22:49:13 +0200 | [diff] [blame] | 17 | #include <errno.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include "lkc.h" |
| 20 | |
| 21 | static void conf(struct menu *menu); |
| 22 | static void check_conf(struct menu *menu); |
Arnaud Lacombe | ab63f58 | 2011-07-02 00:59:41 -0400 | [diff] [blame] | 23 | static void xfgets(char *str, int size, FILE *in); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 25 | enum input_mode { |
| 26 | oldaskconfig, |
| 27 | silentoldconfig, |
| 28 | oldconfig, |
| 29 | allnoconfig, |
| 30 | allyesconfig, |
| 31 | allmodconfig, |
Sam Ravnborg | 0748cb3 | 2010-07-31 23:35:31 +0200 | [diff] [blame] | 32 | alldefconfig, |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 33 | randconfig, |
| 34 | defconfig, |
Sam Ravnborg | 7cf3d73 | 2010-07-31 23:35:34 +0200 | [diff] [blame] | 35 | savedefconfig, |
Sam Ravnborg | 861b4ea | 2010-07-31 23:35:28 +0200 | [diff] [blame] | 36 | listnewconfig, |
Adam Lee | fb16d89 | 2012-09-01 01:05:17 +0800 | [diff] [blame] | 37 | olddefconfig, |
Masahiro Yamada | 52e58a3 | 2018-01-11 22:39:39 +0900 | [diff] [blame^] | 38 | }; |
| 39 | static enum input_mode input_mode = oldaskconfig; |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 40 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | static int indent = 1; |
Ben Hutchings | 62dc989 | 2013-02-19 02:24:26 +0200 | [diff] [blame] | 42 | static int tty_stdio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | static int valid_stdin = 1; |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 44 | static int sync_kconfig; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | static int conf_cnt; |
Markus Mayer | 74dba80 | 2015-12-09 14:56:12 -0800 | [diff] [blame] | 46 | static char line[PATH_MAX]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | static struct menu *rootEntry; |
| 48 | |
Cheng Renquan | 66c4bd8 | 2009-07-12 16:11:48 +0800 | [diff] [blame] | 49 | static void print_help(struct menu *menu) |
Sam Ravnborg | 03d2912 | 2007-07-21 00:00:36 +0200 | [diff] [blame] | 50 | { |
Cheng Renquan | 66c4bd8 | 2009-07-12 16:11:48 +0800 | [diff] [blame] | 51 | struct gstr help = str_new(); |
| 52 | |
| 53 | menu_get_ext_help(menu, &help); |
| 54 | |
| 55 | printf("\n%s\n", str_get(&help)); |
| 56 | str_free(&help); |
Sam Ravnborg | 03d2912 | 2007-07-21 00:00:36 +0200 | [diff] [blame] | 57 | } |
| 58 | |
J.A. Magallon | 48b9d03 | 2005-06-25 14:59:22 -0700 | [diff] [blame] | 59 | static void strip(char *str) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | { |
J.A. Magallon | 48b9d03 | 2005-06-25 14:59:22 -0700 | [diff] [blame] | 61 | char *p = str; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | int l; |
| 63 | |
| 64 | while ((isspace(*p))) |
| 65 | p++; |
| 66 | l = strlen(p); |
| 67 | if (p != str) |
| 68 | memmove(str, p, l + 1); |
| 69 | if (!l) |
| 70 | return; |
| 71 | p = str + l - 1; |
| 72 | while ((isspace(*p))) |
| 73 | *p-- = 0; |
| 74 | } |
| 75 | |
| 76 | static void check_stdin(void) |
| 77 | { |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 78 | if (!valid_stdin) { |
Arnaldo Carvalho de Melo | 3b9fa09 | 2005-05-05 15:09:46 -0700 | [diff] [blame] | 79 | printf(_("aborted!\n\n")); |
| 80 | printf(_("Console input/output is redirected. ")); |
| 81 | printf(_("Run 'make oldconfig' to update configuration.\n\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | exit(1); |
| 83 | } |
| 84 | } |
| 85 | |
Roman Zippel | f82f3f9 | 2007-08-30 05:06:17 +0200 | [diff] [blame] | 86 | static int conf_askvalue(struct symbol *sym, const char *def) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | { |
| 88 | enum symbol_type type = sym_get_type(sym); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
| 90 | if (!sym_has_value(sym)) |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 91 | printf(_("(NEW) ")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
| 93 | line[0] = '\n'; |
| 94 | line[1] = 0; |
| 95 | |
| 96 | if (!sym_is_changable(sym)) { |
| 97 | printf("%s\n", def); |
| 98 | line[0] = '\n'; |
| 99 | line[1] = 0; |
Roman Zippel | f82f3f9 | 2007-08-30 05:06:17 +0200 | [diff] [blame] | 100 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | switch (input_mode) { |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 104 | case oldconfig: |
| 105 | case silentoldconfig: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | if (sym_has_value(sym)) { |
| 107 | printf("%s\n", def); |
Roman Zippel | f82f3f9 | 2007-08-30 05:06:17 +0200 | [diff] [blame] | 108 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | } |
| 110 | check_stdin(); |
Arnaud Lacombe | d8fc320 | 2011-05-31 12:30:26 -0400 | [diff] [blame] | 111 | /* fall through */ |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 112 | case oldaskconfig: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | fflush(stdout); |
Markus Mayer | 74dba80 | 2015-12-09 14:56:12 -0800 | [diff] [blame] | 114 | xfgets(line, sizeof(line), stdin); |
Ben Hutchings | 62dc989 | 2013-02-19 02:24:26 +0200 | [diff] [blame] | 115 | if (!tty_stdio) |
| 116 | printf("\n"); |
Roman Zippel | f82f3f9 | 2007-08-30 05:06:17 +0200 | [diff] [blame] | 117 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | default: |
| 119 | break; |
| 120 | } |
| 121 | |
| 122 | switch (type) { |
| 123 | case S_INT: |
| 124 | case S_HEX: |
| 125 | case S_STRING: |
| 126 | printf("%s\n", def); |
Roman Zippel | f82f3f9 | 2007-08-30 05:06:17 +0200 | [diff] [blame] | 127 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | default: |
| 129 | ; |
| 130 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | printf("%s", line); |
Roman Zippel | f82f3f9 | 2007-08-30 05:06:17 +0200 | [diff] [blame] | 132 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | } |
| 134 | |
Trevor Keith | 4356f48 | 2009-09-18 12:49:23 -0700 | [diff] [blame] | 135 | static int conf_string(struct menu *menu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | { |
| 137 | struct symbol *sym = menu->sym; |
Sam Ravnborg | 03d2912 | 2007-07-21 00:00:36 +0200 | [diff] [blame] | 138 | const char *def; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | |
| 140 | while (1) { |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 141 | printf("%*s%s ", indent - 1, "", _(menu->prompt->text)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | printf("(%s) ", sym->name); |
| 143 | def = sym_get_string_value(sym); |
| 144 | if (sym_get_string_value(sym)) |
| 145 | printf("[%s] ", def); |
Roman Zippel | f82f3f9 | 2007-08-30 05:06:17 +0200 | [diff] [blame] | 146 | if (!conf_askvalue(sym, def)) |
| 147 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | switch (line[0]) { |
| 149 | case '\n': |
| 150 | break; |
| 151 | case '?': |
| 152 | /* print help */ |
| 153 | if (line[1] == '\n') { |
Cheng Renquan | 66c4bd8 | 2009-07-12 16:11:48 +0800 | [diff] [blame] | 154 | print_help(menu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | def = NULL; |
| 156 | break; |
| 157 | } |
Arnaud Lacombe | d8fc320 | 2011-05-31 12:30:26 -0400 | [diff] [blame] | 158 | /* fall through */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | default: |
| 160 | line[strlen(line)-1] = 0; |
| 161 | def = line; |
| 162 | } |
| 163 | if (def && sym_set_string_value(sym, def)) |
| 164 | return 0; |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | static int conf_sym(struct menu *menu) |
| 169 | { |
| 170 | struct symbol *sym = menu->sym; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | tristate oldval, newval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | |
| 173 | while (1) { |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 174 | printf("%*s%s ", indent - 1, "", _(menu->prompt->text)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | if (sym->name) |
| 176 | printf("(%s) ", sym->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | putchar('['); |
| 178 | oldval = sym_get_tristate_value(sym); |
| 179 | switch (oldval) { |
| 180 | case no: |
| 181 | putchar('N'); |
| 182 | break; |
| 183 | case mod: |
| 184 | putchar('M'); |
| 185 | break; |
| 186 | case yes: |
| 187 | putchar('Y'); |
| 188 | break; |
| 189 | } |
| 190 | if (oldval != no && sym_tristate_within_range(sym, no)) |
| 191 | printf("/n"); |
| 192 | if (oldval != mod && sym_tristate_within_range(sym, mod)) |
| 193 | printf("/m"); |
| 194 | if (oldval != yes && sym_tristate_within_range(sym, yes)) |
| 195 | printf("/y"); |
Sam Ravnborg | 03d2912 | 2007-07-21 00:00:36 +0200 | [diff] [blame] | 196 | if (menu_has_help(menu)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | printf("/?"); |
| 198 | printf("] "); |
Roman Zippel | f82f3f9 | 2007-08-30 05:06:17 +0200 | [diff] [blame] | 199 | if (!conf_askvalue(sym, sym_get_string_value(sym))) |
| 200 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | strip(line); |
| 202 | |
| 203 | switch (line[0]) { |
| 204 | case 'n': |
| 205 | case 'N': |
| 206 | newval = no; |
| 207 | if (!line[1] || !strcmp(&line[1], "o")) |
| 208 | break; |
| 209 | continue; |
| 210 | case 'm': |
| 211 | case 'M': |
| 212 | newval = mod; |
| 213 | if (!line[1]) |
| 214 | break; |
| 215 | continue; |
| 216 | case 'y': |
| 217 | case 'Y': |
| 218 | newval = yes; |
| 219 | if (!line[1] || !strcmp(&line[1], "es")) |
| 220 | break; |
| 221 | continue; |
| 222 | case 0: |
| 223 | newval = oldval; |
| 224 | break; |
| 225 | case '?': |
| 226 | goto help; |
| 227 | default: |
| 228 | continue; |
| 229 | } |
| 230 | if (sym_set_tristate_value(sym, newval)) |
| 231 | return 0; |
| 232 | help: |
Cheng Renquan | 66c4bd8 | 2009-07-12 16:11:48 +0800 | [diff] [blame] | 233 | print_help(menu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | } |
| 235 | } |
| 236 | |
| 237 | static int conf_choice(struct menu *menu) |
| 238 | { |
| 239 | struct symbol *sym, *def_sym; |
| 240 | struct menu *child; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | bool is_new; |
| 242 | |
| 243 | sym = menu->sym; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | is_new = !sym_has_value(sym); |
| 245 | if (sym_is_changable(sym)) { |
| 246 | conf_sym(menu); |
| 247 | sym_calc_value(sym); |
| 248 | switch (sym_get_tristate_value(sym)) { |
| 249 | case no: |
| 250 | return 1; |
| 251 | case mod: |
| 252 | return 0; |
| 253 | case yes: |
| 254 | break; |
| 255 | } |
| 256 | } else { |
| 257 | switch (sym_get_tristate_value(sym)) { |
| 258 | case no: |
| 259 | return 1; |
| 260 | case mod: |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 261 | printf("%*s%s\n", indent - 1, "", _(menu_get_prompt(menu))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | return 0; |
| 263 | case yes: |
| 264 | break; |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | while (1) { |
| 269 | int cnt, def; |
| 270 | |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 271 | printf("%*s%s\n", indent - 1, "", _(menu_get_prompt(menu))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | def_sym = sym_get_choice_value(sym); |
| 273 | cnt = def = 0; |
Roman Zippel | 40aee72 | 2006-04-09 17:26:39 +0200 | [diff] [blame] | 274 | line[0] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | for (child = menu->list; child; child = child->next) { |
| 276 | if (!menu_is_visible(child)) |
| 277 | continue; |
| 278 | if (!child->sym) { |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 279 | printf("%*c %s\n", indent, '*', _(menu_get_prompt(child))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | continue; |
| 281 | } |
| 282 | cnt++; |
| 283 | if (child->sym == def_sym) { |
| 284 | def = cnt; |
| 285 | printf("%*c", indent, '>'); |
| 286 | } else |
| 287 | printf("%*c", indent, ' '); |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 288 | printf(" %d. %s", cnt, _(menu_get_prompt(child))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | if (child->sym->name) |
| 290 | printf(" (%s)", child->sym->name); |
| 291 | if (!sym_has_value(child->sym)) |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 292 | printf(_(" (NEW)")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | printf("\n"); |
| 294 | } |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 295 | printf(_("%*schoice"), indent - 1, ""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | if (cnt == 1) { |
| 297 | printf("[1]: 1\n"); |
| 298 | goto conf_childs; |
| 299 | } |
| 300 | printf("[1-%d", cnt); |
Sam Ravnborg | 03d2912 | 2007-07-21 00:00:36 +0200 | [diff] [blame] | 301 | if (menu_has_help(menu)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | printf("?"); |
| 303 | printf("]: "); |
| 304 | switch (input_mode) { |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 305 | case oldconfig: |
| 306 | case silentoldconfig: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | if (!is_new) { |
| 308 | cnt = def; |
| 309 | printf("%d\n", cnt); |
| 310 | break; |
| 311 | } |
| 312 | check_stdin(); |
Arnaud Lacombe | d8fc320 | 2011-05-31 12:30:26 -0400 | [diff] [blame] | 313 | /* fall through */ |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 314 | case oldaskconfig: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | fflush(stdout); |
Markus Mayer | 74dba80 | 2015-12-09 14:56:12 -0800 | [diff] [blame] | 316 | xfgets(line, sizeof(line), stdin); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | strip(line); |
| 318 | if (line[0] == '?') { |
Cheng Renquan | 66c4bd8 | 2009-07-12 16:11:48 +0800 | [diff] [blame] | 319 | print_help(menu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | continue; |
| 321 | } |
| 322 | if (!line[0]) |
| 323 | cnt = def; |
| 324 | else if (isdigit(line[0])) |
| 325 | cnt = atoi(line); |
| 326 | else |
| 327 | continue; |
| 328 | break; |
Sam Ravnborg | f443d2e | 2008-06-30 22:45:38 +0200 | [diff] [blame] | 329 | default: |
| 330 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | conf_childs: |
| 334 | for (child = menu->list; child; child = child->next) { |
| 335 | if (!child->sym || !menu_is_visible(child)) |
| 336 | continue; |
| 337 | if (!--cnt) |
| 338 | break; |
| 339 | } |
| 340 | if (!child) |
| 341 | continue; |
Ben Hutchings | 3ba4162 | 2011-04-23 18:42:56 +0100 | [diff] [blame] | 342 | if (line[0] && line[strlen(line) - 1] == '?') { |
Cheng Renquan | 66c4bd8 | 2009-07-12 16:11:48 +0800 | [diff] [blame] | 343 | print_help(child); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | continue; |
| 345 | } |
| 346 | sym_set_choice_value(sym, child->sym); |
Jan Beulich | f5eaa32 | 2008-01-24 11:54:23 +0000 | [diff] [blame] | 347 | for (child = child->list; child; child = child->next) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | indent += 2; |
Jan Beulich | f5eaa32 | 2008-01-24 11:54:23 +0000 | [diff] [blame] | 349 | conf(child); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | indent -= 2; |
| 351 | } |
| 352 | return 1; |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | static void conf(struct menu *menu) |
| 357 | { |
| 358 | struct symbol *sym; |
| 359 | struct property *prop; |
| 360 | struct menu *child; |
| 361 | |
| 362 | if (!menu_is_visible(menu)) |
| 363 | return; |
| 364 | |
| 365 | sym = menu->sym; |
| 366 | prop = menu->prompt; |
| 367 | if (prop) { |
| 368 | const char *prompt; |
| 369 | |
| 370 | switch (prop->type) { |
| 371 | case P_MENU: |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 372 | if ((input_mode == silentoldconfig || |
Sam Ravnborg | 861b4ea | 2010-07-31 23:35:28 +0200 | [diff] [blame] | 373 | input_mode == listnewconfig || |
Adam Lee | fb16d89 | 2012-09-01 01:05:17 +0800 | [diff] [blame] | 374 | input_mode == olddefconfig) && |
Aristeu Rozanski | f0778c8 | 2010-05-06 12:48:34 -0400 | [diff] [blame] | 375 | rootEntry != menu) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | check_conf(menu); |
| 377 | return; |
| 378 | } |
Arnaud Lacombe | d8fc320 | 2011-05-31 12:30:26 -0400 | [diff] [blame] | 379 | /* fall through */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | case P_COMMENT: |
| 381 | prompt = menu_get_prompt(menu); |
| 382 | if (prompt) |
| 383 | printf("%*c\n%*c %s\n%*c\n", |
| 384 | indent, '*', |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 385 | indent, '*', _(prompt), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | indent, '*'); |
| 387 | default: |
| 388 | ; |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | if (!sym) |
| 393 | goto conf_childs; |
| 394 | |
| 395 | if (sym_is_choice(sym)) { |
| 396 | conf_choice(menu); |
| 397 | if (sym->curr.tri != mod) |
| 398 | return; |
| 399 | goto conf_childs; |
| 400 | } |
| 401 | |
| 402 | switch (sym->type) { |
| 403 | case S_INT: |
| 404 | case S_HEX: |
| 405 | case S_STRING: |
| 406 | conf_string(menu); |
| 407 | break; |
| 408 | default: |
| 409 | conf_sym(menu); |
| 410 | break; |
| 411 | } |
| 412 | |
| 413 | conf_childs: |
| 414 | if (sym) |
| 415 | indent += 2; |
| 416 | for (child = menu->list; child; child = child->next) |
| 417 | conf(child); |
| 418 | if (sym) |
| 419 | indent -= 2; |
| 420 | } |
| 421 | |
| 422 | static void check_conf(struct menu *menu) |
| 423 | { |
| 424 | struct symbol *sym; |
| 425 | struct menu *child; |
| 426 | |
| 427 | if (!menu_is_visible(menu)) |
| 428 | return; |
| 429 | |
| 430 | sym = menu->sym; |
Roman Zippel | 3f23ca2 | 2005-11-08 21:34:48 -0800 | [diff] [blame] | 431 | if (sym && !sym_has_value(sym)) { |
| 432 | if (sym_is_changable(sym) || |
| 433 | (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)) { |
Sam Ravnborg | 861b4ea | 2010-07-31 23:35:28 +0200 | [diff] [blame] | 434 | if (input_mode == listnewconfig) { |
| 435 | if (sym->name && !sym_is_choice_value(sym)) { |
Arnaud Lacombe | ffb5957 | 2010-08-14 23:57:43 -0400 | [diff] [blame] | 436 | printf("%s%s\n", CONFIG_, sym->name); |
Aristeu Rozanski | f0778c8 | 2010-05-06 12:48:34 -0400 | [diff] [blame] | 437 | } |
Adam Lee | fb16d89 | 2012-09-01 01:05:17 +0800 | [diff] [blame] | 438 | } else if (input_mode != olddefconfig) { |
Aristeu Rozanski | f0778c8 | 2010-05-06 12:48:34 -0400 | [diff] [blame] | 439 | if (!conf_cnt++) |
| 440 | printf(_("*\n* Restart config...\n*\n")); |
| 441 | rootEntry = menu_get_parent_menu(menu); |
| 442 | conf(rootEntry); |
| 443 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | for (child = menu->list; child; child = child->next) |
| 448 | check_conf(child); |
| 449 | } |
| 450 | |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 451 | static struct option long_opts[] = { |
| 452 | {"oldaskconfig", no_argument, NULL, oldaskconfig}, |
| 453 | {"oldconfig", no_argument, NULL, oldconfig}, |
| 454 | {"silentoldconfig", no_argument, NULL, silentoldconfig}, |
| 455 | {"defconfig", optional_argument, NULL, defconfig}, |
Sam Ravnborg | 7cf3d73 | 2010-07-31 23:35:34 +0200 | [diff] [blame] | 456 | {"savedefconfig", required_argument, NULL, savedefconfig}, |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 457 | {"allnoconfig", no_argument, NULL, allnoconfig}, |
| 458 | {"allyesconfig", no_argument, NULL, allyesconfig}, |
| 459 | {"allmodconfig", no_argument, NULL, allmodconfig}, |
Sam Ravnborg | 0748cb3 | 2010-07-31 23:35:31 +0200 | [diff] [blame] | 460 | {"alldefconfig", no_argument, NULL, alldefconfig}, |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 461 | {"randconfig", no_argument, NULL, randconfig}, |
Sam Ravnborg | 861b4ea | 2010-07-31 23:35:28 +0200 | [diff] [blame] | 462 | {"listnewconfig", no_argument, NULL, listnewconfig}, |
Adam Lee | fb16d89 | 2012-09-01 01:05:17 +0800 | [diff] [blame] | 463 | {"olddefconfig", no_argument, NULL, olddefconfig}, |
| 464 | /* |
| 465 | * oldnoconfig is an alias of olddefconfig, because people already |
| 466 | * are dependent on its behavior(sets new symbols to their default |
| 467 | * value but not 'n') with the counter-intuitive name. |
| 468 | */ |
| 469 | {"oldnoconfig", no_argument, NULL, olddefconfig}, |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 470 | {NULL, 0, NULL, 0} |
| 471 | }; |
| 472 | |
Arnaud Lacombe | 3254399 | 2010-11-02 00:26:33 -0400 | [diff] [blame] | 473 | static void conf_usage(const char *progname) |
| 474 | { |
| 475 | |
Michal Marek | 0a1f00a | 2015-04-08 13:30:42 +0200 | [diff] [blame] | 476 | printf("Usage: %s [-s] [option] <kconfig-file>\n", progname); |
Arnaud Lacombe | 3254399 | 2010-11-02 00:26:33 -0400 | [diff] [blame] | 477 | printf("[option] is _one_ of the following:\n"); |
| 478 | printf(" --listnewconfig List new options\n"); |
| 479 | printf(" --oldaskconfig Start a new configuration using a line-oriented program\n"); |
| 480 | printf(" --oldconfig Update a configuration using a provided .config as base\n"); |
| 481 | printf(" --silentoldconfig Same as oldconfig, but quietly, additionally update deps\n"); |
Adam Lee | fb16d89 | 2012-09-01 01:05:17 +0800 | [diff] [blame] | 482 | printf(" --olddefconfig Same as silentoldconfig but sets new symbols to their default value\n"); |
| 483 | printf(" --oldnoconfig An alias of olddefconfig\n"); |
Arnaud Lacombe | 3254399 | 2010-11-02 00:26:33 -0400 | [diff] [blame] | 484 | printf(" --defconfig <file> New config with default defined in <file>\n"); |
| 485 | printf(" --savedefconfig <file> Save the minimal current configuration to <file>\n"); |
| 486 | printf(" --allnoconfig New config where all options are answered with no\n"); |
| 487 | printf(" --allyesconfig New config where all options are answered with yes\n"); |
| 488 | printf(" --allmodconfig New config where all options are answered with mod\n"); |
| 489 | printf(" --alldefconfig New config with all symbols set to default\n"); |
| 490 | printf(" --randconfig New config with random answer to all options\n"); |
| 491 | } |
| 492 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | int main(int ac, char **av) |
| 494 | { |
Arnaud Lacombe | 3254399 | 2010-11-02 00:26:33 -0400 | [diff] [blame] | 495 | const char *progname = av[0]; |
Andres Salomon | 2f4b489 | 2007-12-17 01:34:58 -0500 | [diff] [blame] | 496 | int opt; |
Arnaud Lacombe | 275744c | 2010-10-13 20:43:28 -0400 | [diff] [blame] | 497 | const char *name, *defconfig_file = NULL /* gcc uninit */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | struct stat tmpstat; |
| 499 | |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 500 | setlocale(LC_ALL, ""); |
| 501 | bindtextdomain(PACKAGE, LOCALEDIR); |
| 502 | textdomain(PACKAGE); |
| 503 | |
Ben Hutchings | 62dc989 | 2013-02-19 02:24:26 +0200 | [diff] [blame] | 504 | tty_stdio = isatty(0) && isatty(1) && isatty(2); |
| 505 | |
Michal Marek | 0a1f00a | 2015-04-08 13:30:42 +0200 | [diff] [blame] | 506 | while ((opt = getopt_long(ac, av, "s", long_opts, NULL)) != -1) { |
| 507 | if (opt == 's') { |
| 508 | conf_set_message_callback(NULL); |
| 509 | continue; |
| 510 | } |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 511 | input_mode = (enum input_mode)opt; |
Andres Salomon | 2f4b489 | 2007-12-17 01:34:58 -0500 | [diff] [blame] | 512 | switch (opt) { |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 513 | case silentoldconfig: |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 514 | sync_kconfig = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | break; |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 516 | case defconfig: |
Sam Ravnborg | 7cf3d73 | 2010-07-31 23:35:34 +0200 | [diff] [blame] | 517 | case savedefconfig: |
Andres Salomon | 2f4b489 | 2007-12-17 01:34:58 -0500 | [diff] [blame] | 518 | defconfig_file = optarg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | break; |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 520 | case randconfig: |
Ingo Molnar | b0fe551 | 2009-03-12 15:15:31 +0100 | [diff] [blame] | 521 | { |
| 522 | struct timeval now; |
| 523 | unsigned int seed; |
Yann E. MORIN | 0d8024c | 2013-04-13 22:49:13 +0200 | [diff] [blame] | 524 | char *seed_env; |
Ingo Molnar | b0fe551 | 2009-03-12 15:15:31 +0100 | [diff] [blame] | 525 | |
| 526 | /* |
| 527 | * Use microseconds derived seed, |
| 528 | * compensate for systems where it may be zero |
| 529 | */ |
| 530 | gettimeofday(&now, NULL); |
Ingo Molnar | b0fe551 | 2009-03-12 15:15:31 +0100 | [diff] [blame] | 531 | seed = (unsigned int)((now.tv_sec + 1) * (now.tv_usec + 1)); |
Yann E. MORIN | 0d8024c | 2013-04-13 22:49:13 +0200 | [diff] [blame] | 532 | |
| 533 | seed_env = getenv("KCONFIG_SEED"); |
| 534 | if( seed_env && *seed_env ) { |
| 535 | char *endp; |
Yann E. MORIN | e85ac12 | 2013-05-20 23:17:34 +0200 | [diff] [blame] | 536 | int tmp = (int)strtol(seed_env, &endp, 0); |
Yann E. MORIN | 0d8024c | 2013-04-13 22:49:13 +0200 | [diff] [blame] | 537 | if (*endp == '\0') { |
| 538 | seed = tmp; |
| 539 | } |
| 540 | } |
Yann E. MORIN | a5f6d79 | 2013-05-20 23:09:03 +0200 | [diff] [blame] | 541 | fprintf( stderr, "KCONFIG_SEED=0x%X\n", seed ); |
Ingo Molnar | b0fe551 | 2009-03-12 15:15:31 +0100 | [diff] [blame] | 542 | srand(seed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | break; |
Ingo Molnar | b0fe551 | 2009-03-12 15:15:31 +0100 | [diff] [blame] | 544 | } |
Arnaud Lacombe | 3254399 | 2010-11-02 00:26:33 -0400 | [diff] [blame] | 545 | case oldaskconfig: |
| 546 | case oldconfig: |
| 547 | case allnoconfig: |
| 548 | case allyesconfig: |
| 549 | case allmodconfig: |
| 550 | case alldefconfig: |
| 551 | case listnewconfig: |
Adam Lee | fb16d89 | 2012-09-01 01:05:17 +0800 | [diff] [blame] | 552 | case olddefconfig: |
Arnaud Lacombe | 3254399 | 2010-11-02 00:26:33 -0400 | [diff] [blame] | 553 | break; |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 554 | case '?': |
Arnaud Lacombe | 3254399 | 2010-11-02 00:26:33 -0400 | [diff] [blame] | 555 | conf_usage(progname); |
Andres Salomon | 2f4b489 | 2007-12-17 01:34:58 -0500 | [diff] [blame] | 556 | exit(1); |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 557 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | } |
| 559 | } |
Andres Salomon | 2f4b489 | 2007-12-17 01:34:58 -0500 | [diff] [blame] | 560 | if (ac == optind) { |
Arnaldo Carvalho de Melo | 3b9fa09 | 2005-05-05 15:09:46 -0700 | [diff] [blame] | 561 | printf(_("%s: Kconfig file missing\n"), av[0]); |
Arnaud Lacombe | 3254399 | 2010-11-02 00:26:33 -0400 | [diff] [blame] | 562 | conf_usage(progname); |
Randy Dunlap | 250725a | 2006-06-08 22:12:50 -0700 | [diff] [blame] | 563 | exit(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | } |
Andres Salomon | 2f4b489 | 2007-12-17 01:34:58 -0500 | [diff] [blame] | 565 | name = av[optind]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | conf_parse(name); |
| 567 | //zconfdump(stdout); |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 568 | if (sync_kconfig) { |
Markus Heidelberg | 284026c | 2009-05-18 01:36:53 +0200 | [diff] [blame] | 569 | name = conf_get_configname(); |
| 570 | if (stat(name, &tmpstat)) { |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 571 | fprintf(stderr, _("***\n" |
Arnaud Lacombe | 652cf98 | 2010-08-14 23:51:40 -0400 | [diff] [blame] | 572 | "*** Configuration file \"%s\" not found!\n" |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 573 | "***\n" |
| 574 | "*** Please run some configurator (e.g. \"make oldconfig\" or\n" |
| 575 | "*** \"make menuconfig\" or \"make xconfig\").\n" |
Markus Heidelberg | 284026c | 2009-05-18 01:36:53 +0200 | [diff] [blame] | 576 | "***\n"), name); |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 577 | exit(1); |
| 578 | } |
| 579 | } |
| 580 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | switch (input_mode) { |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 582 | case defconfig: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | if (!defconfig_file) |
| 584 | defconfig_file = conf_get_default_confname(); |
| 585 | if (conf_read(defconfig_file)) { |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 586 | printf(_("***\n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | "*** Can't find default configuration \"%s\"!\n" |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 588 | "***\n"), defconfig_file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | exit(1); |
| 590 | } |
| 591 | break; |
Sam Ravnborg | 7cf3d73 | 2010-07-31 23:35:34 +0200 | [diff] [blame] | 592 | case savedefconfig: |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 593 | case silentoldconfig: |
| 594 | case oldaskconfig: |
| 595 | case oldconfig: |
Sam Ravnborg | 861b4ea | 2010-07-31 23:35:28 +0200 | [diff] [blame] | 596 | case listnewconfig: |
Adam Lee | fb16d89 | 2012-09-01 01:05:17 +0800 | [diff] [blame] | 597 | case olddefconfig: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | conf_read(NULL); |
| 599 | break; |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 600 | case allnoconfig: |
| 601 | case allyesconfig: |
| 602 | case allmodconfig: |
Sam Ravnborg | 0748cb3 | 2010-07-31 23:35:31 +0200 | [diff] [blame] | 603 | case alldefconfig: |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 604 | case randconfig: |
Roman Zippel | 9038916 | 2005-11-08 21:34:49 -0800 | [diff] [blame] | 605 | name = getenv("KCONFIG_ALLCONFIG"); |
Eric W. Biederman | 9f420bf | 2012-05-07 05:37:45 -0700 | [diff] [blame] | 606 | if (!name) |
| 607 | break; |
| 608 | if ((strcmp(name, "") != 0) && (strcmp(name, "1") != 0)) { |
Eric W. Biederman | 5efe241 | 2012-04-26 01:51:32 -0700 | [diff] [blame] | 609 | if (conf_read_simple(name, S_DEF_USER)) { |
| 610 | fprintf(stderr, |
| 611 | _("*** Can't read seed configuration \"%s\"!\n"), |
| 612 | name); |
| 613 | exit(1); |
| 614 | } |
Roman Zippel | 9038916 | 2005-11-08 21:34:49 -0800 | [diff] [blame] | 615 | break; |
| 616 | } |
| 617 | switch (input_mode) { |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 618 | case allnoconfig: name = "allno.config"; break; |
| 619 | case allyesconfig: name = "allyes.config"; break; |
| 620 | case allmodconfig: name = "allmod.config"; break; |
Sam Ravnborg | 0748cb3 | 2010-07-31 23:35:31 +0200 | [diff] [blame] | 621 | case alldefconfig: name = "alldef.config"; break; |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 622 | case randconfig: name = "allrandom.config"; break; |
Roman Zippel | 9038916 | 2005-11-08 21:34:49 -0800 | [diff] [blame] | 623 | default: break; |
| 624 | } |
Eric W. Biederman | 5efe241 | 2012-04-26 01:51:32 -0700 | [diff] [blame] | 625 | if (conf_read_simple(name, S_DEF_USER) && |
| 626 | conf_read_simple("all.config", S_DEF_USER)) { |
| 627 | fprintf(stderr, |
| 628 | _("*** KCONFIG_ALLCONFIG set, but no \"%s\" or \"all.config\" file found\n"), |
| 629 | name); |
| 630 | exit(1); |
| 631 | } |
Roman Zippel | 9038916 | 2005-11-08 21:34:49 -0800 | [diff] [blame] | 632 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | default: |
| 634 | break; |
| 635 | } |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 636 | |
| 637 | if (sync_kconfig) { |
| 638 | if (conf_get_changed()) { |
| 639 | name = getenv("KCONFIG_NOSILENTUPDATE"); |
| 640 | if (name && *name) { |
| 641 | fprintf(stderr, |
Arnaud Lacombe | 652cf98 | 2010-08-14 23:51:40 -0400 | [diff] [blame] | 642 | _("\n*** The configuration requires explicit update.\n\n")); |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 643 | return 1; |
| 644 | } |
| 645 | } |
Ben Hutchings | 62dc989 | 2013-02-19 02:24:26 +0200 | [diff] [blame] | 646 | valid_stdin = tty_stdio; |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 647 | } |
| 648 | |
Sam Ravnborg | f443d2e | 2008-06-30 22:45:38 +0200 | [diff] [blame] | 649 | switch (input_mode) { |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 650 | case allnoconfig: |
Sam Ravnborg | f443d2e | 2008-06-30 22:45:38 +0200 | [diff] [blame] | 651 | conf_set_all_new_symbols(def_no); |
| 652 | break; |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 653 | case allyesconfig: |
Sam Ravnborg | f443d2e | 2008-06-30 22:45:38 +0200 | [diff] [blame] | 654 | conf_set_all_new_symbols(def_yes); |
| 655 | break; |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 656 | case allmodconfig: |
Sam Ravnborg | f443d2e | 2008-06-30 22:45:38 +0200 | [diff] [blame] | 657 | conf_set_all_new_symbols(def_mod); |
| 658 | break; |
Sam Ravnborg | 0748cb3 | 2010-07-31 23:35:31 +0200 | [diff] [blame] | 659 | case alldefconfig: |
| 660 | conf_set_all_new_symbols(def_default); |
| 661 | break; |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 662 | case randconfig: |
Yann E. MORIN | 3b9a19e | 2013-04-28 22:36:38 +0200 | [diff] [blame] | 663 | /* Really nothing to do in this loop */ |
| 664 | while (conf_set_all_new_symbols(def_random)) ; |
Sam Ravnborg | f443d2e | 2008-06-30 22:45:38 +0200 | [diff] [blame] | 665 | break; |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 666 | case defconfig: |
Sam Ravnborg | 09748e1 | 2008-06-30 23:02:59 +0200 | [diff] [blame] | 667 | conf_set_all_new_symbols(def_default); |
| 668 | break; |
Sam Ravnborg | 7cf3d73 | 2010-07-31 23:35:34 +0200 | [diff] [blame] | 669 | case savedefconfig: |
| 670 | break; |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 671 | case oldaskconfig: |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 672 | rootEntry = &rootmenu; |
| 673 | conf(&rootmenu); |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 674 | input_mode = silentoldconfig; |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 675 | /* fall through */ |
Sam Ravnborg | 1482834 | 2010-08-06 07:13:54 +0200 | [diff] [blame] | 676 | case oldconfig: |
Sam Ravnborg | 861b4ea | 2010-07-31 23:35:28 +0200 | [diff] [blame] | 677 | case listnewconfig: |
Adam Lee | fb16d89 | 2012-09-01 01:05:17 +0800 | [diff] [blame] | 678 | case olddefconfig: |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 679 | case silentoldconfig: |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 680 | /* Update until a loop caused no more changes */ |
| 681 | do { |
| 682 | conf_cnt = 0; |
| 683 | check_conf(&rootmenu); |
Aristeu Rozanski | f0778c8 | 2010-05-06 12:48:34 -0400 | [diff] [blame] | 684 | } while (conf_cnt && |
Sam Ravnborg | 861b4ea | 2010-07-31 23:35:28 +0200 | [diff] [blame] | 685 | (input_mode != listnewconfig && |
Adam Lee | fb16d89 | 2012-09-01 01:05:17 +0800 | [diff] [blame] | 686 | input_mode != olddefconfig)); |
Sam Ravnborg | f443d2e | 2008-06-30 22:45:38 +0200 | [diff] [blame] | 687 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | } |
Sam Ravnborg | f443d2e | 2008-06-30 22:45:38 +0200 | [diff] [blame] | 689 | |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 690 | if (sync_kconfig) { |
| 691 | /* silentoldconfig is used during the build so we shall update autoconf. |
| 692 | * All other commands are only used to generate a config. |
| 693 | */ |
| 694 | if (conf_get_changed() && conf_write(NULL)) { |
Arnaud Lacombe | 652cf98 | 2010-08-14 23:51:40 -0400 | [diff] [blame] | 695 | fprintf(stderr, _("\n*** Error during writing of the configuration.\n\n")); |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 696 | exit(1); |
| 697 | } |
| 698 | if (conf_write_autoconf()) { |
Arnaud Lacombe | 652cf98 | 2010-08-14 23:51:40 -0400 | [diff] [blame] | 699 | fprintf(stderr, _("\n*** Error during update of the configuration.\n\n")); |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 700 | return 1; |
| 701 | } |
Sam Ravnborg | 7cf3d73 | 2010-07-31 23:35:34 +0200 | [diff] [blame] | 702 | } else if (input_mode == savedefconfig) { |
| 703 | if (conf_write_defconfig(defconfig_file)) { |
| 704 | fprintf(stderr, _("n*** Error while saving defconfig to: %s\n\n"), |
Masahiro Yamada | bb66fc6 | 2014-06-10 19:08:13 +0900 | [diff] [blame] | 705 | defconfig_file); |
Sam Ravnborg | 7cf3d73 | 2010-07-31 23:35:34 +0200 | [diff] [blame] | 706 | return 1; |
| 707 | } |
Sam Ravnborg | 861b4ea | 2010-07-31 23:35:28 +0200 | [diff] [blame] | 708 | } else if (input_mode != listnewconfig) { |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 709 | if (conf_write(NULL)) { |
Arnaud Lacombe | 652cf98 | 2010-08-14 23:51:40 -0400 | [diff] [blame] | 710 | fprintf(stderr, _("\n*** Error during writing of the configuration.\n\n")); |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 711 | exit(1); |
| 712 | } |
Roman Zippel | c955cca | 2006-06-08 22:12:39 -0700 | [diff] [blame] | 713 | } |
Sam Ravnborg | 861b4ea | 2010-07-31 23:35:28 +0200 | [diff] [blame] | 714 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | } |
Arnaud Lacombe | ab63f58 | 2011-07-02 00:59:41 -0400 | [diff] [blame] | 716 | |
Jean Sacren | 4418a2b | 2010-08-04 16:03:16 -0600 | [diff] [blame] | 717 | /* |
| 718 | * Helper function to facilitate fgets() by Jean Sacren. |
| 719 | */ |
Arnaud Lacombe | ab63f58 | 2011-07-02 00:59:41 -0400 | [diff] [blame] | 720 | void xfgets(char *str, int size, FILE *in) |
Jean Sacren | 4418a2b | 2010-08-04 16:03:16 -0600 | [diff] [blame] | 721 | { |
| 722 | if (fgets(str, size, in) == NULL) |
| 723 | fprintf(stderr, "\nError in reading or end of file.\n"); |
| 724 | } |