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> |
Randy Dunlap | 9dfb563 | 2006-04-18 22:21:53 -0700 | [diff] [blame] | 8 | #include <stdio.h> |
Ladislav Michl | 75ff430 | 2008-01-09 16:36:19 +0100 | [diff] [blame] | 9 | #include <stdlib.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <string.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <time.h> |
Ladislav Michl | 75ff430 | 2008-01-09 16:36:19 +0100 | [diff] [blame] | 12 | #include <unistd.h> |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 13 | #include <getopt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <sys/stat.h> |
Ingo Molnar | b0fe551 | 2009-03-12 15:15:31 +0100 | [diff] [blame] | 15 | #include <sys/time.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | |
| 17 | #define LKC_DIRECT_LINK |
| 18 | #include "lkc.h" |
| 19 | |
| 20 | static void conf(struct menu *menu); |
| 21 | static void check_conf(struct menu *menu); |
| 22 | |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 23 | enum input_mode { |
| 24 | oldaskconfig, |
| 25 | silentoldconfig, |
| 26 | oldconfig, |
| 27 | allnoconfig, |
| 28 | allyesconfig, |
| 29 | allmodconfig, |
| 30 | randconfig, |
| 31 | defconfig, |
Sam Ravnborg | 861b4ea | 2010-07-31 23:35:28 +0200 | [diff] [blame^] | 32 | listnewconfig, |
Sam Ravnborg | ef61ca8 | 2010-07-31 23:35:27 +0200 | [diff] [blame] | 33 | oldnoconfig, |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 34 | } input_mode = oldaskconfig; |
| 35 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | char *defconfig_file; |
| 37 | |
| 38 | static int indent = 1; |
| 39 | static int valid_stdin = 1; |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 40 | static int sync_kconfig; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | static int conf_cnt; |
J.A. Magallon | 48b9d03 | 2005-06-25 14:59:22 -0700 | [diff] [blame] | 42 | static char line[128]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | static struct menu *rootEntry; |
| 44 | |
Cheng Renquan | 66c4bd8 | 2009-07-12 16:11:48 +0800 | [diff] [blame] | 45 | static void print_help(struct menu *menu) |
Sam Ravnborg | 03d2912 | 2007-07-21 00:00:36 +0200 | [diff] [blame] | 46 | { |
Cheng Renquan | 66c4bd8 | 2009-07-12 16:11:48 +0800 | [diff] [blame] | 47 | struct gstr help = str_new(); |
| 48 | |
| 49 | menu_get_ext_help(menu, &help); |
| 50 | |
| 51 | printf("\n%s\n", str_get(&help)); |
| 52 | str_free(&help); |
Sam Ravnborg | 03d2912 | 2007-07-21 00:00:36 +0200 | [diff] [blame] | 53 | } |
| 54 | |
J.A. Magallon | 48b9d03 | 2005-06-25 14:59:22 -0700 | [diff] [blame] | 55 | static void strip(char *str) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | { |
J.A. Magallon | 48b9d03 | 2005-06-25 14:59:22 -0700 | [diff] [blame] | 57 | char *p = str; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | int l; |
| 59 | |
| 60 | while ((isspace(*p))) |
| 61 | p++; |
| 62 | l = strlen(p); |
| 63 | if (p != str) |
| 64 | memmove(str, p, l + 1); |
| 65 | if (!l) |
| 66 | return; |
| 67 | p = str + l - 1; |
| 68 | while ((isspace(*p))) |
| 69 | *p-- = 0; |
| 70 | } |
| 71 | |
| 72 | static void check_stdin(void) |
| 73 | { |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 74 | if (!valid_stdin) { |
Arnaldo Carvalho de Melo | 3b9fa09 | 2005-05-05 15:09:46 -0700 | [diff] [blame] | 75 | printf(_("aborted!\n\n")); |
| 76 | printf(_("Console input/output is redirected. ")); |
| 77 | printf(_("Run 'make oldconfig' to update configuration.\n\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | exit(1); |
| 79 | } |
| 80 | } |
| 81 | |
Roman Zippel | f82f3f9 | 2007-08-30 05:06:17 +0200 | [diff] [blame] | 82 | static int conf_askvalue(struct symbol *sym, const char *def) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | { |
| 84 | enum symbol_type type = sym_get_type(sym); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | |
| 86 | if (!sym_has_value(sym)) |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 87 | printf(_("(NEW) ")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
| 89 | line[0] = '\n'; |
| 90 | line[1] = 0; |
| 91 | |
| 92 | if (!sym_is_changable(sym)) { |
| 93 | printf("%s\n", def); |
| 94 | line[0] = '\n'; |
| 95 | line[1] = 0; |
Roman Zippel | f82f3f9 | 2007-08-30 05:06:17 +0200 | [diff] [blame] | 96 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | switch (input_mode) { |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 100 | case oldconfig: |
| 101 | case silentoldconfig: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | if (sym_has_value(sym)) { |
| 103 | printf("%s\n", def); |
Roman Zippel | f82f3f9 | 2007-08-30 05:06:17 +0200 | [diff] [blame] | 104 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | } |
| 106 | check_stdin(); |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 107 | case oldaskconfig: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | fflush(stdout); |
Roman Zippel | 59c6a3f | 2006-04-09 17:26:50 +0200 | [diff] [blame] | 109 | fgets(line, 128, stdin); |
Roman Zippel | f82f3f9 | 2007-08-30 05:06:17 +0200 | [diff] [blame] | 110 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | default: |
| 112 | break; |
| 113 | } |
| 114 | |
| 115 | switch (type) { |
| 116 | case S_INT: |
| 117 | case S_HEX: |
| 118 | case S_STRING: |
| 119 | printf("%s\n", def); |
Roman Zippel | f82f3f9 | 2007-08-30 05:06:17 +0200 | [diff] [blame] | 120 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | default: |
| 122 | ; |
| 123 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | printf("%s", line); |
Roman Zippel | f82f3f9 | 2007-08-30 05:06:17 +0200 | [diff] [blame] | 125 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | } |
| 127 | |
Trevor Keith | 4356f48 | 2009-09-18 12:49:23 -0700 | [diff] [blame] | 128 | static int conf_string(struct menu *menu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | { |
| 130 | struct symbol *sym = menu->sym; |
Sam Ravnborg | 03d2912 | 2007-07-21 00:00:36 +0200 | [diff] [blame] | 131 | const char *def; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
| 133 | while (1) { |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 134 | printf("%*s%s ", indent - 1, "", _(menu->prompt->text)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | printf("(%s) ", sym->name); |
| 136 | def = sym_get_string_value(sym); |
| 137 | if (sym_get_string_value(sym)) |
| 138 | printf("[%s] ", def); |
Roman Zippel | f82f3f9 | 2007-08-30 05:06:17 +0200 | [diff] [blame] | 139 | if (!conf_askvalue(sym, def)) |
| 140 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | switch (line[0]) { |
| 142 | case '\n': |
| 143 | break; |
| 144 | case '?': |
| 145 | /* print help */ |
| 146 | if (line[1] == '\n') { |
Cheng Renquan | 66c4bd8 | 2009-07-12 16:11:48 +0800 | [diff] [blame] | 147 | print_help(menu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | def = NULL; |
| 149 | break; |
| 150 | } |
| 151 | default: |
| 152 | line[strlen(line)-1] = 0; |
| 153 | def = line; |
| 154 | } |
| 155 | if (def && sym_set_string_value(sym, def)) |
| 156 | return 0; |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | static int conf_sym(struct menu *menu) |
| 161 | { |
| 162 | struct symbol *sym = menu->sym; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | tristate oldval, newval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | |
| 165 | while (1) { |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 166 | printf("%*s%s ", indent - 1, "", _(menu->prompt->text)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | if (sym->name) |
| 168 | printf("(%s) ", sym->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | putchar('['); |
| 170 | oldval = sym_get_tristate_value(sym); |
| 171 | switch (oldval) { |
| 172 | case no: |
| 173 | putchar('N'); |
| 174 | break; |
| 175 | case mod: |
| 176 | putchar('M'); |
| 177 | break; |
| 178 | case yes: |
| 179 | putchar('Y'); |
| 180 | break; |
| 181 | } |
| 182 | if (oldval != no && sym_tristate_within_range(sym, no)) |
| 183 | printf("/n"); |
| 184 | if (oldval != mod && sym_tristate_within_range(sym, mod)) |
| 185 | printf("/m"); |
| 186 | if (oldval != yes && sym_tristate_within_range(sym, yes)) |
| 187 | printf("/y"); |
Sam Ravnborg | 03d2912 | 2007-07-21 00:00:36 +0200 | [diff] [blame] | 188 | if (menu_has_help(menu)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | printf("/?"); |
| 190 | printf("] "); |
Roman Zippel | f82f3f9 | 2007-08-30 05:06:17 +0200 | [diff] [blame] | 191 | if (!conf_askvalue(sym, sym_get_string_value(sym))) |
| 192 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | strip(line); |
| 194 | |
| 195 | switch (line[0]) { |
| 196 | case 'n': |
| 197 | case 'N': |
| 198 | newval = no; |
| 199 | if (!line[1] || !strcmp(&line[1], "o")) |
| 200 | break; |
| 201 | continue; |
| 202 | case 'm': |
| 203 | case 'M': |
| 204 | newval = mod; |
| 205 | if (!line[1]) |
| 206 | break; |
| 207 | continue; |
| 208 | case 'y': |
| 209 | case 'Y': |
| 210 | newval = yes; |
| 211 | if (!line[1] || !strcmp(&line[1], "es")) |
| 212 | break; |
| 213 | continue; |
| 214 | case 0: |
| 215 | newval = oldval; |
| 216 | break; |
| 217 | case '?': |
| 218 | goto help; |
| 219 | default: |
| 220 | continue; |
| 221 | } |
| 222 | if (sym_set_tristate_value(sym, newval)) |
| 223 | return 0; |
| 224 | help: |
Cheng Renquan | 66c4bd8 | 2009-07-12 16:11:48 +0800 | [diff] [blame] | 225 | print_help(menu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | } |
| 227 | } |
| 228 | |
| 229 | static int conf_choice(struct menu *menu) |
| 230 | { |
| 231 | struct symbol *sym, *def_sym; |
| 232 | struct menu *child; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | bool is_new; |
| 234 | |
| 235 | sym = menu->sym; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | is_new = !sym_has_value(sym); |
| 237 | if (sym_is_changable(sym)) { |
| 238 | conf_sym(menu); |
| 239 | sym_calc_value(sym); |
| 240 | switch (sym_get_tristate_value(sym)) { |
| 241 | case no: |
| 242 | return 1; |
| 243 | case mod: |
| 244 | return 0; |
| 245 | case yes: |
| 246 | break; |
| 247 | } |
| 248 | } else { |
| 249 | switch (sym_get_tristate_value(sym)) { |
| 250 | case no: |
| 251 | return 1; |
| 252 | case mod: |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 253 | printf("%*s%s\n", indent - 1, "", _(menu_get_prompt(menu))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | return 0; |
| 255 | case yes: |
| 256 | break; |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | while (1) { |
| 261 | int cnt, def; |
| 262 | |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 263 | printf("%*s%s\n", indent - 1, "", _(menu_get_prompt(menu))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | def_sym = sym_get_choice_value(sym); |
| 265 | cnt = def = 0; |
Roman Zippel | 40aee72 | 2006-04-09 17:26:39 +0200 | [diff] [blame] | 266 | line[0] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | for (child = menu->list; child; child = child->next) { |
| 268 | if (!menu_is_visible(child)) |
| 269 | continue; |
| 270 | if (!child->sym) { |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 271 | printf("%*c %s\n", indent, '*', _(menu_get_prompt(child))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | continue; |
| 273 | } |
| 274 | cnt++; |
| 275 | if (child->sym == def_sym) { |
| 276 | def = cnt; |
| 277 | printf("%*c", indent, '>'); |
| 278 | } else |
| 279 | printf("%*c", indent, ' '); |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 280 | printf(" %d. %s", cnt, _(menu_get_prompt(child))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | if (child->sym->name) |
| 282 | printf(" (%s)", child->sym->name); |
| 283 | if (!sym_has_value(child->sym)) |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 284 | printf(_(" (NEW)")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | printf("\n"); |
| 286 | } |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 287 | printf(_("%*schoice"), indent - 1, ""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | if (cnt == 1) { |
| 289 | printf("[1]: 1\n"); |
| 290 | goto conf_childs; |
| 291 | } |
| 292 | printf("[1-%d", cnt); |
Sam Ravnborg | 03d2912 | 2007-07-21 00:00:36 +0200 | [diff] [blame] | 293 | if (menu_has_help(menu)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | printf("?"); |
| 295 | printf("]: "); |
| 296 | switch (input_mode) { |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 297 | case oldconfig: |
| 298 | case silentoldconfig: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | if (!is_new) { |
| 300 | cnt = def; |
| 301 | printf("%d\n", cnt); |
| 302 | break; |
| 303 | } |
| 304 | check_stdin(); |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 305 | case oldaskconfig: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | fflush(stdout); |
Roman Zippel | 59c6a3f | 2006-04-09 17:26:50 +0200 | [diff] [blame] | 307 | fgets(line, 128, stdin); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | strip(line); |
| 309 | if (line[0] == '?') { |
Cheng Renquan | 66c4bd8 | 2009-07-12 16:11:48 +0800 | [diff] [blame] | 310 | print_help(menu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | continue; |
| 312 | } |
| 313 | if (!line[0]) |
| 314 | cnt = def; |
| 315 | else if (isdigit(line[0])) |
| 316 | cnt = atoi(line); |
| 317 | else |
| 318 | continue; |
| 319 | break; |
Sam Ravnborg | f443d2e | 2008-06-30 22:45:38 +0200 | [diff] [blame] | 320 | default: |
| 321 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | conf_childs: |
| 325 | for (child = menu->list; child; child = child->next) { |
| 326 | if (!child->sym || !menu_is_visible(child)) |
| 327 | continue; |
| 328 | if (!--cnt) |
| 329 | break; |
| 330 | } |
| 331 | if (!child) |
| 332 | continue; |
| 333 | if (line[strlen(line) - 1] == '?') { |
Cheng Renquan | 66c4bd8 | 2009-07-12 16:11:48 +0800 | [diff] [blame] | 334 | print_help(child); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | continue; |
| 336 | } |
| 337 | sym_set_choice_value(sym, child->sym); |
Jan Beulich | f5eaa32 | 2008-01-24 11:54:23 +0000 | [diff] [blame] | 338 | for (child = child->list; child; child = child->next) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | indent += 2; |
Jan Beulich | f5eaa32 | 2008-01-24 11:54:23 +0000 | [diff] [blame] | 340 | conf(child); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | indent -= 2; |
| 342 | } |
| 343 | return 1; |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | static void conf(struct menu *menu) |
| 348 | { |
| 349 | struct symbol *sym; |
| 350 | struct property *prop; |
| 351 | struct menu *child; |
| 352 | |
| 353 | if (!menu_is_visible(menu)) |
| 354 | return; |
| 355 | |
| 356 | sym = menu->sym; |
| 357 | prop = menu->prompt; |
| 358 | if (prop) { |
| 359 | const char *prompt; |
| 360 | |
| 361 | switch (prop->type) { |
| 362 | case P_MENU: |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 363 | if ((input_mode == silentoldconfig || |
Sam Ravnborg | 861b4ea | 2010-07-31 23:35:28 +0200 | [diff] [blame^] | 364 | input_mode == listnewconfig || |
Sam Ravnborg | ef61ca8 | 2010-07-31 23:35:27 +0200 | [diff] [blame] | 365 | input_mode == oldnoconfig) && |
Aristeu Rozanski | f0778c8 | 2010-05-06 12:48:34 -0400 | [diff] [blame] | 366 | rootEntry != menu) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | check_conf(menu); |
| 368 | return; |
| 369 | } |
| 370 | case P_COMMENT: |
| 371 | prompt = menu_get_prompt(menu); |
| 372 | if (prompt) |
| 373 | printf("%*c\n%*c %s\n%*c\n", |
| 374 | indent, '*', |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 375 | indent, '*', _(prompt), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | indent, '*'); |
| 377 | default: |
| 378 | ; |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | if (!sym) |
| 383 | goto conf_childs; |
| 384 | |
| 385 | if (sym_is_choice(sym)) { |
| 386 | conf_choice(menu); |
| 387 | if (sym->curr.tri != mod) |
| 388 | return; |
| 389 | goto conf_childs; |
| 390 | } |
| 391 | |
| 392 | switch (sym->type) { |
| 393 | case S_INT: |
| 394 | case S_HEX: |
| 395 | case S_STRING: |
| 396 | conf_string(menu); |
| 397 | break; |
| 398 | default: |
| 399 | conf_sym(menu); |
| 400 | break; |
| 401 | } |
| 402 | |
| 403 | conf_childs: |
| 404 | if (sym) |
| 405 | indent += 2; |
| 406 | for (child = menu->list; child; child = child->next) |
| 407 | conf(child); |
| 408 | if (sym) |
| 409 | indent -= 2; |
| 410 | } |
| 411 | |
| 412 | static void check_conf(struct menu *menu) |
| 413 | { |
| 414 | struct symbol *sym; |
| 415 | struct menu *child; |
| 416 | |
| 417 | if (!menu_is_visible(menu)) |
| 418 | return; |
| 419 | |
| 420 | sym = menu->sym; |
Roman Zippel | 3f23ca2 | 2005-11-08 21:34:48 -0800 | [diff] [blame] | 421 | if (sym && !sym_has_value(sym)) { |
| 422 | if (sym_is_changable(sym) || |
| 423 | (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)) { |
Sam Ravnborg | 861b4ea | 2010-07-31 23:35:28 +0200 | [diff] [blame^] | 424 | if (input_mode == listnewconfig) { |
| 425 | if (sym->name && !sym_is_choice_value(sym)) { |
| 426 | printf("CONFIG_%s\n", sym->name); |
Aristeu Rozanski | f0778c8 | 2010-05-06 12:48:34 -0400 | [diff] [blame] | 427 | } |
| 428 | } else { |
| 429 | if (!conf_cnt++) |
| 430 | printf(_("*\n* Restart config...\n*\n")); |
| 431 | rootEntry = menu_get_parent_menu(menu); |
| 432 | conf(rootEntry); |
| 433 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | for (child = menu->list; child; child = child->next) |
| 438 | check_conf(child); |
| 439 | } |
| 440 | |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 441 | static struct option long_opts[] = { |
| 442 | {"oldaskconfig", no_argument, NULL, oldaskconfig}, |
| 443 | {"oldconfig", no_argument, NULL, oldconfig}, |
| 444 | {"silentoldconfig", no_argument, NULL, silentoldconfig}, |
| 445 | {"defconfig", optional_argument, NULL, defconfig}, |
| 446 | {"allnoconfig", no_argument, NULL, allnoconfig}, |
| 447 | {"allyesconfig", no_argument, NULL, allyesconfig}, |
| 448 | {"allmodconfig", no_argument, NULL, allmodconfig}, |
| 449 | {"randconfig", no_argument, NULL, randconfig}, |
Sam Ravnborg | 861b4ea | 2010-07-31 23:35:28 +0200 | [diff] [blame^] | 450 | {"listnewconfig", no_argument, NULL, listnewconfig}, |
Sam Ravnborg | ef61ca8 | 2010-07-31 23:35:27 +0200 | [diff] [blame] | 451 | {"oldnoconfig", no_argument, NULL, oldnoconfig}, |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 452 | {NULL, 0, NULL, 0} |
| 453 | }; |
| 454 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | int main(int ac, char **av) |
| 456 | { |
Andres Salomon | 2f4b489 | 2007-12-17 01:34:58 -0500 | [diff] [blame] | 457 | int opt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | const char *name; |
| 459 | struct stat tmpstat; |
| 460 | |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 461 | setlocale(LC_ALL, ""); |
| 462 | bindtextdomain(PACKAGE, LOCALEDIR); |
| 463 | textdomain(PACKAGE); |
| 464 | |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 465 | while ((opt = getopt_long_only(ac, av, "", long_opts, NULL)) != -1) { |
| 466 | input_mode = (enum input_mode)opt; |
Andres Salomon | 2f4b489 | 2007-12-17 01:34:58 -0500 | [diff] [blame] | 467 | switch (opt) { |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 468 | case silentoldconfig: |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 469 | sync_kconfig = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | break; |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 471 | case defconfig: |
Andres Salomon | 2f4b489 | 2007-12-17 01:34:58 -0500 | [diff] [blame] | 472 | defconfig_file = optarg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | break; |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 474 | case randconfig: |
Ingo Molnar | b0fe551 | 2009-03-12 15:15:31 +0100 | [diff] [blame] | 475 | { |
| 476 | struct timeval now; |
| 477 | unsigned int seed; |
| 478 | |
| 479 | /* |
| 480 | * Use microseconds derived seed, |
| 481 | * compensate for systems where it may be zero |
| 482 | */ |
| 483 | gettimeofday(&now, NULL); |
| 484 | |
| 485 | seed = (unsigned int)((now.tv_sec + 1) * (now.tv_usec + 1)); |
| 486 | srand(seed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | break; |
Ingo Molnar | b0fe551 | 2009-03-12 15:15:31 +0100 | [diff] [blame] | 488 | } |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 489 | case '?': |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 490 | fprintf(stderr, _("See README for usage info\n")); |
Andres Salomon | 2f4b489 | 2007-12-17 01:34:58 -0500 | [diff] [blame] | 491 | exit(1); |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 492 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | } |
| 494 | } |
Andres Salomon | 2f4b489 | 2007-12-17 01:34:58 -0500 | [diff] [blame] | 495 | if (ac == optind) { |
Arnaldo Carvalho de Melo | 3b9fa09 | 2005-05-05 15:09:46 -0700 | [diff] [blame] | 496 | printf(_("%s: Kconfig file missing\n"), av[0]); |
Randy Dunlap | 250725a | 2006-06-08 22:12:50 -0700 | [diff] [blame] | 497 | exit(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | } |
Andres Salomon | 2f4b489 | 2007-12-17 01:34:58 -0500 | [diff] [blame] | 499 | name = av[optind]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | conf_parse(name); |
| 501 | //zconfdump(stdout); |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 502 | if (sync_kconfig) { |
Markus Heidelberg | 284026c | 2009-05-18 01:36:53 +0200 | [diff] [blame] | 503 | name = conf_get_configname(); |
| 504 | if (stat(name, &tmpstat)) { |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 505 | fprintf(stderr, _("***\n" |
| 506 | "*** You have not yet configured your kernel!\n" |
Markus Heidelberg | 284026c | 2009-05-18 01:36:53 +0200 | [diff] [blame] | 507 | "*** (missing kernel config file \"%s\")\n" |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 508 | "***\n" |
| 509 | "*** Please run some configurator (e.g. \"make oldconfig\" or\n" |
| 510 | "*** \"make menuconfig\" or \"make xconfig\").\n" |
Markus Heidelberg | 284026c | 2009-05-18 01:36:53 +0200 | [diff] [blame] | 511 | "***\n"), name); |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 512 | exit(1); |
| 513 | } |
| 514 | } |
| 515 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | switch (input_mode) { |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 517 | case defconfig: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | if (!defconfig_file) |
| 519 | defconfig_file = conf_get_default_confname(); |
| 520 | if (conf_read(defconfig_file)) { |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 521 | printf(_("***\n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | "*** Can't find default configuration \"%s\"!\n" |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 523 | "***\n"), defconfig_file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | exit(1); |
| 525 | } |
| 526 | break; |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 527 | case silentoldconfig: |
| 528 | case oldaskconfig: |
| 529 | case oldconfig: |
Sam Ravnborg | 861b4ea | 2010-07-31 23:35:28 +0200 | [diff] [blame^] | 530 | case listnewconfig: |
Sam Ravnborg | ef61ca8 | 2010-07-31 23:35:27 +0200 | [diff] [blame] | 531 | case oldnoconfig: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | conf_read(NULL); |
| 533 | break; |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 534 | case allnoconfig: |
| 535 | case allyesconfig: |
| 536 | case allmodconfig: |
| 537 | case randconfig: |
Roman Zippel | 9038916 | 2005-11-08 21:34:49 -0800 | [diff] [blame] | 538 | name = getenv("KCONFIG_ALLCONFIG"); |
| 539 | if (name && !stat(name, &tmpstat)) { |
Roman Zippel | 669bfad | 2006-06-08 22:12:42 -0700 | [diff] [blame] | 540 | conf_read_simple(name, S_DEF_USER); |
Roman Zippel | 9038916 | 2005-11-08 21:34:49 -0800 | [diff] [blame] | 541 | break; |
| 542 | } |
| 543 | switch (input_mode) { |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 544 | case allnoconfig: name = "allno.config"; break; |
| 545 | case allyesconfig: name = "allyes.config"; break; |
| 546 | case allmodconfig: name = "allmod.config"; break; |
| 547 | case randconfig: name = "allrandom.config"; break; |
Roman Zippel | 9038916 | 2005-11-08 21:34:49 -0800 | [diff] [blame] | 548 | default: break; |
| 549 | } |
| 550 | if (!stat(name, &tmpstat)) |
Roman Zippel | 669bfad | 2006-06-08 22:12:42 -0700 | [diff] [blame] | 551 | conf_read_simple(name, S_DEF_USER); |
Roman Zippel | 9038916 | 2005-11-08 21:34:49 -0800 | [diff] [blame] | 552 | else if (!stat("all.config", &tmpstat)) |
Roman Zippel | 669bfad | 2006-06-08 22:12:42 -0700 | [diff] [blame] | 553 | conf_read_simple("all.config", S_DEF_USER); |
Roman Zippel | 9038916 | 2005-11-08 21:34:49 -0800 | [diff] [blame] | 554 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | default: |
| 556 | break; |
| 557 | } |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 558 | |
| 559 | if (sync_kconfig) { |
| 560 | if (conf_get_changed()) { |
| 561 | name = getenv("KCONFIG_NOSILENTUPDATE"); |
| 562 | if (name && *name) { |
| 563 | fprintf(stderr, |
| 564 | _("\n*** Kernel configuration requires explicit update.\n\n")); |
| 565 | return 1; |
| 566 | } |
| 567 | } |
| 568 | valid_stdin = isatty(0) && isatty(1) && isatty(2); |
| 569 | } |
| 570 | |
Sam Ravnborg | f443d2e | 2008-06-30 22:45:38 +0200 | [diff] [blame] | 571 | switch (input_mode) { |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 572 | case allnoconfig: |
Sam Ravnborg | f443d2e | 2008-06-30 22:45:38 +0200 | [diff] [blame] | 573 | conf_set_all_new_symbols(def_no); |
| 574 | break; |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 575 | case allyesconfig: |
Sam Ravnborg | f443d2e | 2008-06-30 22:45:38 +0200 | [diff] [blame] | 576 | conf_set_all_new_symbols(def_yes); |
| 577 | break; |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 578 | case allmodconfig: |
Sam Ravnborg | f443d2e | 2008-06-30 22:45:38 +0200 | [diff] [blame] | 579 | conf_set_all_new_symbols(def_mod); |
| 580 | break; |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 581 | case randconfig: |
Sam Ravnborg | f443d2e | 2008-06-30 22:45:38 +0200 | [diff] [blame] | 582 | conf_set_all_new_symbols(def_random); |
| 583 | break; |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 584 | case defconfig: |
Sam Ravnborg | 09748e1 | 2008-06-30 23:02:59 +0200 | [diff] [blame] | 585 | conf_set_all_new_symbols(def_default); |
| 586 | break; |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 587 | case oldconfig: |
| 588 | case oldaskconfig: |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 589 | rootEntry = &rootmenu; |
| 590 | conf(&rootmenu); |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 591 | input_mode = silentoldconfig; |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 592 | /* fall through */ |
Sam Ravnborg | 861b4ea | 2010-07-31 23:35:28 +0200 | [diff] [blame^] | 593 | case listnewconfig: |
Sam Ravnborg | ef61ca8 | 2010-07-31 23:35:27 +0200 | [diff] [blame] | 594 | case oldnoconfig: |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 595 | case silentoldconfig: |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 596 | /* Update until a loop caused no more changes */ |
| 597 | do { |
| 598 | conf_cnt = 0; |
| 599 | check_conf(&rootmenu); |
Aristeu Rozanski | f0778c8 | 2010-05-06 12:48:34 -0400 | [diff] [blame] | 600 | } while (conf_cnt && |
Sam Ravnborg | 861b4ea | 2010-07-31 23:35:28 +0200 | [diff] [blame^] | 601 | (input_mode != listnewconfig && |
Sam Ravnborg | ef61ca8 | 2010-07-31 23:35:27 +0200 | [diff] [blame] | 602 | input_mode != oldnoconfig)); |
Sam Ravnborg | f443d2e | 2008-06-30 22:45:38 +0200 | [diff] [blame] | 603 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | } |
Sam Ravnborg | f443d2e | 2008-06-30 22:45:38 +0200 | [diff] [blame] | 605 | |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 606 | if (sync_kconfig) { |
| 607 | /* silentoldconfig is used during the build so we shall update autoconf. |
| 608 | * All other commands are only used to generate a config. |
| 609 | */ |
| 610 | if (conf_get_changed() && conf_write(NULL)) { |
| 611 | fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n")); |
| 612 | exit(1); |
| 613 | } |
| 614 | if (conf_write_autoconf()) { |
| 615 | fprintf(stderr, _("\n*** Error during update of the kernel configuration.\n\n")); |
| 616 | return 1; |
| 617 | } |
Sam Ravnborg | 861b4ea | 2010-07-31 23:35:28 +0200 | [diff] [blame^] | 618 | } else if (input_mode != listnewconfig) { |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 619 | if (conf_write(NULL)) { |
| 620 | fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n")); |
| 621 | exit(1); |
| 622 | } |
Roman Zippel | c955cca | 2006-06-08 22:12:39 -0700 | [diff] [blame] | 623 | } |
Sam Ravnborg | 861b4ea | 2010-07-31 23:35:28 +0200 | [diff] [blame^] | 624 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | } |