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