Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [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 | |
| 6 | #include <locale.h> |
| 7 | #include <ctype.h> |
| 8 | #include <stdio.h> |
| 9 | #include <stdlib.h> |
| 10 | #include <string.h> |
| 11 | #include <time.h> |
| 12 | #include <unistd.h> |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 13 | #include <getopt.h> |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 14 | #include <sys/stat.h> |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 15 | #include <sys/time.h> |
| 16 | #include <errno.h> |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 17 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 18 | #include "lkc.h" |
| 19 | |
Stefan Reinauer | 57a3131 | 2015-08-20 11:19:34 -0700 | [diff] [blame] | 20 | int kconfig_warnings = 0; |
| 21 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 22 | static void conf(struct menu *menu); |
| 23 | static void check_conf(struct menu *menu); |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 24 | static void xfgets(char *str, int size, FILE *in); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 25 | |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 26 | enum input_mode { |
| 27 | oldaskconfig, |
| 28 | silentoldconfig, |
| 29 | oldconfig, |
| 30 | allnoconfig, |
| 31 | allyesconfig, |
| 32 | allmodconfig, |
| 33 | alldefconfig, |
| 34 | randconfig, |
| 35 | defconfig, |
| 36 | savedefconfig, |
| 37 | listnewconfig, |
| 38 | olddefconfig, |
| 39 | } input_mode = oldaskconfig; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 40 | |
| 41 | static int indent = 1; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 42 | static int tty_stdio; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 43 | static int valid_stdin = 1; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 44 | static int sync_kconfig; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 45 | static int conf_cnt; |
| 46 | static char line[128]; |
| 47 | static struct menu *rootEntry; |
| 48 | |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 49 | static void print_help(struct menu *menu) |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 50 | { |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [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); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | static void strip(char *str) |
| 60 | { |
| 61 | char *p = str; |
| 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 | { |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 78 | if (!valid_stdin) { |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 79 | printf(_("aborted!\n\n")); |
| 80 | printf(_("Console input/output is redirected. ")); |
| 81 | printf(_("Run 'make oldconfig' to update configuration.\n\n")); |
| 82 | exit(1); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | static int conf_askvalue(struct symbol *sym, const char *def) |
| 87 | { |
| 88 | enum symbol_type type = sym_get_type(sym); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 89 | |
| 90 | if (!sym_has_value(sym)) |
| 91 | printf(_("(NEW) ")); |
| 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; |
| 100 | return 0; |
| 101 | } |
| 102 | |
| 103 | switch (input_mode) { |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 104 | case oldconfig: |
| 105 | case silentoldconfig: |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 106 | if (sym_has_value(sym)) { |
| 107 | printf("%s\n", def); |
| 108 | return 0; |
| 109 | } |
| 110 | check_stdin(); |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 111 | /* fall through */ |
| 112 | case oldaskconfig: |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 113 | fflush(stdout); |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 114 | xfgets(line, 128, stdin); |
| 115 | if (!tty_stdio) |
| 116 | printf("\n"); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 117 | return 1; |
| 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); |
| 127 | return 1; |
| 128 | default: |
| 129 | ; |
| 130 | } |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 131 | printf("%s", line); |
| 132 | return 1; |
| 133 | } |
| 134 | |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 135 | static int conf_string(struct menu *menu) |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 136 | { |
| 137 | struct symbol *sym = menu->sym; |
| 138 | const char *def; |
| 139 | |
| 140 | while (1) { |
| 141 | printf("%*s%s ", indent - 1, "", _(menu->prompt->text)); |
| 142 | printf("(%s) ", sym->name); |
| 143 | def = sym_get_string_value(sym); |
| 144 | if (sym_get_string_value(sym)) |
| 145 | printf("[%s] ", def); |
| 146 | if (!conf_askvalue(sym, def)) |
| 147 | return 0; |
| 148 | switch (line[0]) { |
| 149 | case '\n': |
| 150 | break; |
| 151 | case '?': |
| 152 | /* print help */ |
| 153 | if (line[1] == '\n') { |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 154 | print_help(menu); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 155 | def = NULL; |
| 156 | break; |
| 157 | } |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 158 | /* fall through */ |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [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; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 171 | tristate oldval, newval; |
| 172 | |
| 173 | while (1) { |
| 174 | printf("%*s%s ", indent - 1, "", _(menu->prompt->text)); |
| 175 | if (sym->name) |
| 176 | printf("(%s) ", sym->name); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [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"); |
| 196 | if (menu_has_help(menu)) |
| 197 | printf("/?"); |
| 198 | printf("] "); |
| 199 | if (!conf_askvalue(sym, sym_get_string_value(sym))) |
| 200 | return 0; |
| 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: |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 233 | print_help(menu); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 234 | } |
| 235 | } |
| 236 | |
| 237 | static int conf_choice(struct menu *menu) |
| 238 | { |
| 239 | struct symbol *sym, *def_sym; |
| 240 | struct menu *child; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 241 | bool is_new; |
| 242 | |
| 243 | sym = menu->sym; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [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: |
| 261 | printf("%*s%s\n", indent - 1, "", _(menu_get_prompt(menu))); |
| 262 | return 0; |
| 263 | case yes: |
| 264 | break; |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | while (1) { |
| 269 | int cnt, def; |
| 270 | |
| 271 | printf("%*s%s\n", indent - 1, "", _(menu_get_prompt(menu))); |
| 272 | def_sym = sym_get_choice_value(sym); |
| 273 | cnt = def = 0; |
| 274 | line[0] = 0; |
| 275 | for (child = menu->list; child; child = child->next) { |
| 276 | if (!menu_is_visible(child)) |
| 277 | continue; |
| 278 | if (!child->sym) { |
| 279 | printf("%*c %s\n", indent, '*', _(menu_get_prompt(child))); |
| 280 | continue; |
| 281 | } |
| 282 | cnt++; |
| 283 | if (child->sym == def_sym) { |
| 284 | def = cnt; |
| 285 | printf("%*c", indent, '>'); |
| 286 | } else |
| 287 | printf("%*c", indent, ' '); |
| 288 | printf(" %d. %s", cnt, _(menu_get_prompt(child))); |
| 289 | if (child->sym->name) |
| 290 | printf(" (%s)", child->sym->name); |
| 291 | if (!sym_has_value(child->sym)) |
| 292 | printf(_(" (NEW)")); |
| 293 | printf("\n"); |
| 294 | } |
| 295 | printf(_("%*schoice"), indent - 1, ""); |
| 296 | if (cnt == 1) { |
| 297 | printf("[1]: 1\n"); |
| 298 | goto conf_childs; |
| 299 | } |
| 300 | printf("[1-%d", cnt); |
| 301 | if (menu_has_help(menu)) |
| 302 | printf("?"); |
| 303 | printf("]: "); |
| 304 | switch (input_mode) { |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 305 | case oldconfig: |
| 306 | case silentoldconfig: |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 307 | if (!is_new) { |
| 308 | cnt = def; |
| 309 | printf("%d\n", cnt); |
| 310 | break; |
| 311 | } |
| 312 | check_stdin(); |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 313 | /* fall through */ |
| 314 | case oldaskconfig: |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 315 | fflush(stdout); |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 316 | xfgets(line, 128, stdin); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 317 | strip(line); |
| 318 | if (line[0] == '?') { |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 319 | print_help(menu); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [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; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 329 | default: |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 330 | break; |
| 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; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 342 | if (line[0] && line[strlen(line) - 1] == '?') { |
| 343 | print_help(child); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 344 | continue; |
| 345 | } |
| 346 | sym_set_choice_value(sym, child->sym); |
| 347 | for (child = child->list; child; child = child->next) { |
| 348 | indent += 2; |
| 349 | conf(child); |
| 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: |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 372 | if ((input_mode == silentoldconfig || |
| 373 | input_mode == listnewconfig || |
| 374 | input_mode == olddefconfig) && |
| 375 | rootEntry != menu) { |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 376 | check_conf(menu); |
| 377 | return; |
| 378 | } |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 379 | /* fall through */ |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [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, '*', |
| 385 | indent, '*', _(prompt), |
| 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; |
| 431 | if (sym && !sym_has_value(sym)) { |
| 432 | if (sym_is_changable(sym) || |
| 433 | (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)) { |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 434 | if (input_mode == listnewconfig) { |
| 435 | if (sym->name && !sym_is_choice_value(sym)) { |
| 436 | printf("%s%s\n", CONFIG_, sym->name); |
| 437 | } |
| 438 | } else if (input_mode != olddefconfig) { |
| 439 | if (!conf_cnt++) |
| 440 | printf(_("*\n* Restart config...\n*\n")); |
| 441 | rootEntry = menu_get_parent_menu(menu); |
| 442 | conf(rootEntry); |
| 443 | } |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 444 | } |
| 445 | } |
| 446 | |
| 447 | for (child = menu->list; child; child = child->next) |
| 448 | check_conf(child); |
| 449 | } |
| 450 | |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +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}, |
| 456 | {"savedefconfig", required_argument, NULL, savedefconfig}, |
| 457 | {"allnoconfig", no_argument, NULL, allnoconfig}, |
| 458 | {"allyesconfig", no_argument, NULL, allyesconfig}, |
| 459 | {"allmodconfig", no_argument, NULL, allmodconfig}, |
| 460 | {"alldefconfig", no_argument, NULL, alldefconfig}, |
| 461 | {"randconfig", no_argument, NULL, randconfig}, |
| 462 | {"listnewconfig", no_argument, NULL, listnewconfig}, |
| 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}, |
| 470 | {NULL, 0, NULL, 0} |
| 471 | }; |
| 472 | |
| 473 | static void conf_usage(const char *progname) |
| 474 | { |
| 475 | |
| 476 | printf("Usage: %s [option] <kconfig-file>\n", progname); |
| 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"); |
| 482 | printf(" --olddefconfig Same as silentoldconfig but sets new symbols to their default value\n"); |
| 483 | printf(" --oldnoconfig An alias of olddefconfig\n"); |
| 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 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 493 | int main(int ac, char **av) |
| 494 | { |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 495 | const char *progname = av[0]; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 496 | int opt; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 497 | const char *name, *defconfig_file = NULL /* gcc uninit */; |
Stefan Reinauer | 57a3131 | 2015-08-20 11:19:34 -0700 | [diff] [blame] | 498 | char *env; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 499 | struct stat tmpstat; |
| 500 | |
| 501 | setlocale(LC_ALL, ""); |
| 502 | bindtextdomain(PACKAGE, LOCALEDIR); |
| 503 | textdomain(PACKAGE); |
| 504 | |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 505 | tty_stdio = isatty(0) && isatty(1) && isatty(2); |
| 506 | |
| 507 | while ((opt = getopt_long(ac, av, "", long_opts, NULL)) != -1) { |
| 508 | input_mode = (enum input_mode)opt; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 509 | switch (opt) { |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 510 | case silentoldconfig: |
| 511 | sync_kconfig = 1; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 512 | break; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 513 | case defconfig: |
| 514 | case savedefconfig: |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 515 | defconfig_file = optarg; |
| 516 | break; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 517 | case randconfig: |
| 518 | { |
| 519 | struct timeval now; |
| 520 | unsigned int seed; |
| 521 | char *seed_env; |
| 522 | |
| 523 | /* |
| 524 | * Use microseconds derived seed, |
| 525 | * compensate for systems where it may be zero |
| 526 | */ |
| 527 | gettimeofday(&now, NULL); |
| 528 | seed = (unsigned int)((now.tv_sec + 1) * (now.tv_usec + 1)); |
| 529 | |
| 530 | seed_env = getenv("KCONFIG_SEED"); |
| 531 | if( seed_env && *seed_env ) { |
| 532 | char *endp; |
| 533 | int tmp = (int)strtol(seed_env, &endp, 0); |
| 534 | if (*endp == '\0') { |
| 535 | seed = tmp; |
| 536 | } |
| 537 | } |
| 538 | fprintf( stderr, "KCONFIG_SEED=0x%X\n", seed ); |
| 539 | srand(seed); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 540 | break; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 541 | } |
| 542 | case oldaskconfig: |
| 543 | case oldconfig: |
| 544 | case allnoconfig: |
| 545 | case allyesconfig: |
| 546 | case allmodconfig: |
| 547 | case alldefconfig: |
| 548 | case listnewconfig: |
| 549 | case olddefconfig: |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 550 | break; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 551 | case '?': |
| 552 | conf_usage(progname); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 553 | exit(1); |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 554 | break; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 555 | } |
| 556 | } |
| 557 | if (ac == optind) { |
| 558 | printf(_("%s: Kconfig file missing\n"), av[0]); |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 559 | conf_usage(progname); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 560 | exit(1); |
| 561 | } |
| 562 | name = av[optind]; |
| 563 | conf_parse(name); |
| 564 | //zconfdump(stdout); |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 565 | if (sync_kconfig) { |
| 566 | name = conf_get_configname(); |
| 567 | if (stat(name, &tmpstat)) { |
| 568 | fprintf(stderr, _("***\n" |
| 569 | "*** Configuration file \"%s\" not found!\n" |
| 570 | "***\n" |
| 571 | "*** Please run some configurator (e.g. \"make oldconfig\" or\n" |
| 572 | "*** \"make menuconfig\" or \"make xconfig\").\n" |
| 573 | "***\n"), name); |
| 574 | exit(1); |
| 575 | } |
| 576 | } |
| 577 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 578 | switch (input_mode) { |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 579 | case defconfig: |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 580 | if (!defconfig_file) |
| 581 | defconfig_file = conf_get_default_confname(); |
| 582 | if (conf_read(defconfig_file)) { |
| 583 | printf(_("***\n" |
| 584 | "*** Can't find default configuration \"%s\"!\n" |
| 585 | "***\n"), defconfig_file); |
| 586 | exit(1); |
| 587 | } |
| 588 | break; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 589 | case savedefconfig: |
| 590 | case silentoldconfig: |
| 591 | case oldaskconfig: |
| 592 | case oldconfig: |
| 593 | case listnewconfig: |
| 594 | case olddefconfig: |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 595 | conf_read(NULL); |
| 596 | break; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 597 | case allnoconfig: |
| 598 | case allyesconfig: |
| 599 | case allmodconfig: |
| 600 | case alldefconfig: |
| 601 | case randconfig: |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 602 | name = getenv("KCONFIG_ALLCONFIG"); |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 603 | if (!name) |
| 604 | break; |
| 605 | if ((strcmp(name, "") != 0) && (strcmp(name, "1") != 0)) { |
| 606 | if (conf_read_simple(name, S_DEF_USER)) { |
| 607 | fprintf(stderr, |
| 608 | _("*** Can't read seed configuration \"%s\"!\n"), |
| 609 | name); |
| 610 | exit(1); |
| 611 | } |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 612 | break; |
| 613 | } |
| 614 | switch (input_mode) { |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 615 | case allnoconfig: name = "allno.config"; break; |
| 616 | case allyesconfig: name = "allyes.config"; break; |
| 617 | case allmodconfig: name = "allmod.config"; break; |
| 618 | case alldefconfig: name = "alldef.config"; break; |
| 619 | case randconfig: name = "allrandom.config"; break; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 620 | default: break; |
| 621 | } |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 622 | if (conf_read_simple(name, S_DEF_USER) && |
| 623 | conf_read_simple("all.config", S_DEF_USER)) { |
| 624 | fprintf(stderr, |
| 625 | _("*** KCONFIG_ALLCONFIG set, but no \"%s\" or \"all.config\" file found\n"), |
| 626 | name); |
| 627 | exit(1); |
| 628 | } |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 629 | break; |
| 630 | default: |
| 631 | break; |
| 632 | } |
| 633 | |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 634 | if (sync_kconfig) { |
| 635 | if (conf_get_changed()) { |
| 636 | name = getenv("KCONFIG_NOSILENTUPDATE"); |
| 637 | if (name && *name) { |
| 638 | fprintf(stderr, |
| 639 | _("\n*** The configuration requires explicit update.\n\n")); |
| 640 | return 1; |
| 641 | } |
| 642 | } |
| 643 | valid_stdin = tty_stdio; |
| 644 | } |
| 645 | |
| 646 | switch (input_mode) { |
| 647 | case allnoconfig: |
| 648 | conf_set_all_new_symbols(def_no); |
| 649 | break; |
| 650 | case allyesconfig: |
| 651 | conf_set_all_new_symbols(def_yes); |
| 652 | break; |
| 653 | case allmodconfig: |
| 654 | conf_set_all_new_symbols(def_mod); |
| 655 | break; |
| 656 | case alldefconfig: |
| 657 | conf_set_all_new_symbols(def_default); |
| 658 | break; |
| 659 | case randconfig: |
| 660 | /* Really nothing to do in this loop */ |
| 661 | while (conf_set_all_new_symbols(def_random)) ; |
| 662 | break; |
| 663 | case defconfig: |
| 664 | conf_set_all_new_symbols(def_default); |
| 665 | break; |
| 666 | case savedefconfig: |
| 667 | break; |
| 668 | case oldaskconfig: |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 669 | rootEntry = &rootmenu; |
| 670 | conf(&rootmenu); |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 671 | input_mode = silentoldconfig; |
| 672 | /* fall through */ |
| 673 | case oldconfig: |
| 674 | case listnewconfig: |
| 675 | case olddefconfig: |
| 676 | case silentoldconfig: |
| 677 | /* Update until a loop caused no more changes */ |
| 678 | do { |
| 679 | conf_cnt = 0; |
| 680 | check_conf(&rootmenu); |
| 681 | } while (conf_cnt && |
| 682 | (input_mode != listnewconfig && |
| 683 | input_mode != olddefconfig)); |
| 684 | break; |
| 685 | } |
| 686 | |
Stefan Reinauer | 57a3131 | 2015-08-20 11:19:34 -0700 | [diff] [blame] | 687 | env = getenv("KCONFIG_STRICT"); |
| 688 | if (env && *env && kconfig_warnings) { |
| 689 | fprintf(stderr, _("\n*** ERROR: %d warnings encountered, and " |
| 690 | "warnings are errors.\n\n"), kconfig_warnings); |
| 691 | exit(1); |
| 692 | } |
| 693 | |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 694 | if (sync_kconfig) { |
| 695 | /* silentoldconfig is used during the build so we shall update autoconf. |
| 696 | * All other commands are only used to generate a config. |
| 697 | */ |
| 698 | if (conf_get_changed() && conf_write(NULL)) { |
| 699 | fprintf(stderr, _("\n*** Error during writing of the configuration.\n\n")); |
| 700 | exit(1); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 701 | } |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 702 | if (conf_write_autoconf()) { |
| 703 | fprintf(stderr, _("\n*** Error during update of the configuration.\n\n")); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 704 | return 1; |
| 705 | } |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 706 | } else if (input_mode == savedefconfig) { |
| 707 | if (conf_write_defconfig(defconfig_file)) { |
Martin Roth | c01ff74 | 2016-12-06 14:28:44 -0700 | [diff] [blame] | 708 | fprintf(stderr, _("\n*** Error while saving defconfig to: %s\n\n"), |
Stefan Reinauer | 3ec23b3 | 2015-04-06 00:59:23 +0200 | [diff] [blame] | 709 | defconfig_file); |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 710 | return 1; |
| 711 | } |
| 712 | } else if (input_mode != listnewconfig) { |
| 713 | if (conf_write(NULL)) { |
| 714 | fprintf(stderr, _("\n*** Error during writing of the configuration.\n\n")); |
| 715 | exit(1); |
| 716 | } |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 717 | } |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 718 | return 0; |
| 719 | } |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 720 | |
| 721 | /* |
| 722 | * Helper function to facilitate fgets() by Jean Sacren. |
| 723 | */ |
| 724 | void xfgets(char *str, int size, FILE *in) |
| 725 | { |
| 726 | if (fgets(str, size, in) == NULL) |
| 727 | fprintf(stderr, "\nError in reading or end of file.\n"); |
| 728 | } |