Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 6 | #include <ctype.h> |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 7 | #include <limits.h> |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 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 | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 14 | #include <sys/time.h> |
| 15 | #include <errno.h> |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 16 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 17 | #include "lkc.h" |
| 18 | |
Stefan Reinauer | 57a3131 | 2015-08-20 11:19:34 -0700 | [diff] [blame] | 19 | int kconfig_warnings = 0; |
| 20 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 21 | static void conf(struct menu *menu); |
| 22 | static void check_conf(struct menu *menu); |
| 23 | |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 24 | enum input_mode { |
| 25 | oldaskconfig, |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 26 | syncconfig, |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 27 | oldconfig, |
| 28 | allnoconfig, |
| 29 | allyesconfig, |
| 30 | allmodconfig, |
| 31 | alldefconfig, |
| 32 | randconfig, |
| 33 | defconfig, |
| 34 | savedefconfig, |
| 35 | listnewconfig, |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 36 | helpnewconfig, |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 37 | olddefconfig, |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 38 | yes2modconfig, |
| 39 | mod2yesconfig, |
| 40 | }; |
| 41 | static enum input_mode input_mode = oldaskconfig; |
| 42 | static int input_mode_opt; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 43 | static int indent = 1; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 44 | static int tty_stdio; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 45 | static int sync_kconfig; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 46 | static int conf_cnt; |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 47 | static char line[PATH_MAX]; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 48 | static struct menu *rootEntry; |
| 49 | |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 50 | static void print_help(struct menu *menu) |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 51 | { |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [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); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | static void strip(char *str) |
| 61 | { |
| 62 | char *p = str; |
| 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 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 77 | /* Helper function to facilitate fgets() by Jean Sacren. */ |
| 78 | static void xfgets(char *str, int size, FILE *in) |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 79 | { |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 80 | if (!fgets(str, size, in)) |
| 81 | fprintf(stderr, "\nError in reading or end of file.\n"); |
| 82 | |
| 83 | if (!tty_stdio) |
| 84 | printf("%s", str); |
| 85 | } |
| 86 | |
| 87 | static void set_randconfig_seed(void) |
| 88 | { |
| 89 | unsigned int seed; |
| 90 | char *env; |
| 91 | bool seed_set = false; |
| 92 | |
| 93 | env = getenv("KCONFIG_SEED"); |
| 94 | if (env && *env) { |
| 95 | char *endp; |
| 96 | |
| 97 | seed = strtol(env, &endp, 0); |
| 98 | if (*endp == '\0') |
| 99 | seed_set = true; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 100 | } |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 101 | |
| 102 | if (!seed_set) { |
| 103 | struct timeval now; |
| 104 | |
| 105 | /* |
| 106 | * Use microseconds derived seed, compensate for systems where it may |
| 107 | * be zero. |
| 108 | */ |
| 109 | gettimeofday(&now, NULL); |
| 110 | seed = (now.tv_sec + 1) * (now.tv_usec + 1); |
| 111 | } |
| 112 | |
| 113 | printf("KCONFIG_SEED=0x%X\n", seed); |
| 114 | srand(seed); |
| 115 | } |
| 116 | |
| 117 | static bool randomize_choice_values(struct symbol *csym) |
| 118 | { |
| 119 | struct property *prop; |
| 120 | struct symbol *sym; |
| 121 | struct expr *e; |
| 122 | int cnt, def; |
| 123 | |
| 124 | /* |
| 125 | * If choice is mod then we may have more items selected |
| 126 | * and if no then no-one. |
| 127 | * In both cases stop. |
| 128 | */ |
| 129 | if (csym->curr.tri != yes) |
| 130 | return false; |
| 131 | |
| 132 | prop = sym_get_choice_prop(csym); |
| 133 | |
| 134 | /* count entries in choice block */ |
| 135 | cnt = 0; |
| 136 | expr_list_for_each_sym(prop->expr, e, sym) |
| 137 | cnt++; |
| 138 | |
| 139 | /* |
| 140 | * find a random value and set it to yes, |
| 141 | * set the rest to no so we have only one set |
| 142 | */ |
| 143 | def = rand() % cnt; |
| 144 | |
| 145 | cnt = 0; |
| 146 | expr_list_for_each_sym(prop->expr, e, sym) { |
| 147 | if (def == cnt++) { |
| 148 | sym->def[S_DEF_USER].tri = yes; |
| 149 | csym->def[S_DEF_USER].val = sym; |
| 150 | } else { |
| 151 | sym->def[S_DEF_USER].tri = no; |
| 152 | } |
| 153 | sym->flags |= SYMBOL_DEF_USER; |
| 154 | /* clear VALID to get value calculated */ |
| 155 | sym->flags &= ~SYMBOL_VALID; |
| 156 | } |
| 157 | csym->flags |= SYMBOL_DEF_USER; |
| 158 | /* clear VALID to get value calculated */ |
| 159 | csym->flags &= ~SYMBOL_VALID; |
| 160 | |
| 161 | return true; |
| 162 | } |
| 163 | |
| 164 | enum conf_def_mode { |
| 165 | def_default, |
| 166 | def_yes, |
| 167 | def_mod, |
| 168 | def_y2m, |
| 169 | def_m2y, |
| 170 | def_no, |
| 171 | def_random |
| 172 | }; |
| 173 | |
| 174 | static bool conf_set_all_new_symbols(enum conf_def_mode mode) |
| 175 | { |
| 176 | struct symbol *sym, *csym; |
| 177 | int i, cnt; |
| 178 | /* |
| 179 | * can't go as the default in switch-case below, otherwise gcc whines |
| 180 | * about -Wmaybe-uninitialized |
| 181 | */ |
| 182 | int pby = 50; /* probability of bool = y */ |
| 183 | int pty = 33; /* probability of tristate = y */ |
| 184 | int ptm = 33; /* probability of tristate = m */ |
| 185 | bool has_changed = false; |
| 186 | |
| 187 | if (mode == def_random) { |
| 188 | int n, p[3]; |
| 189 | char *env = getenv("KCONFIG_PROBABILITY"); |
| 190 | |
| 191 | n = 0; |
| 192 | while (env && *env) { |
| 193 | char *endp; |
| 194 | int tmp = strtol(env, &endp, 10); |
| 195 | |
| 196 | if (tmp >= 0 && tmp <= 100) { |
| 197 | p[n++] = tmp; |
| 198 | } else { |
| 199 | errno = ERANGE; |
| 200 | perror("KCONFIG_PROBABILITY"); |
| 201 | exit(1); |
| 202 | } |
| 203 | env = (*endp == ':') ? endp + 1 : endp; |
| 204 | if (n >= 3) |
| 205 | break; |
| 206 | } |
| 207 | switch (n) { |
| 208 | case 1: |
| 209 | pby = p[0]; |
| 210 | ptm = pby / 2; |
| 211 | pty = pby - ptm; |
| 212 | break; |
| 213 | case 2: |
| 214 | pty = p[0]; |
| 215 | ptm = p[1]; |
| 216 | pby = pty + ptm; |
| 217 | break; |
| 218 | case 3: |
| 219 | pby = p[0]; |
| 220 | pty = p[1]; |
| 221 | ptm = p[2]; |
| 222 | break; |
| 223 | } |
| 224 | |
| 225 | if (pty + ptm > 100) { |
| 226 | errno = ERANGE; |
| 227 | perror("KCONFIG_PROBABILITY"); |
| 228 | exit(1); |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | for_all_symbols(i, sym) { |
| 233 | if (sym_has_value(sym) || sym->flags & SYMBOL_VALID) |
| 234 | continue; |
| 235 | switch (sym_get_type(sym)) { |
| 236 | case S_BOOLEAN: |
| 237 | case S_TRISTATE: |
| 238 | has_changed = true; |
| 239 | switch (mode) { |
| 240 | case def_yes: |
| 241 | sym->def[S_DEF_USER].tri = yes; |
| 242 | break; |
| 243 | case def_mod: |
| 244 | sym->def[S_DEF_USER].tri = mod; |
| 245 | break; |
| 246 | case def_no: |
| 247 | sym->def[S_DEF_USER].tri = no; |
| 248 | break; |
| 249 | case def_random: |
| 250 | sym->def[S_DEF_USER].tri = no; |
| 251 | cnt = rand() % 100; |
| 252 | if (sym->type == S_TRISTATE) { |
| 253 | if (cnt < pty) |
| 254 | sym->def[S_DEF_USER].tri = yes; |
| 255 | else if (cnt < pty + ptm) |
| 256 | sym->def[S_DEF_USER].tri = mod; |
| 257 | } else if (cnt < pby) |
| 258 | sym->def[S_DEF_USER].tri = yes; |
| 259 | break; |
| 260 | default: |
| 261 | continue; |
| 262 | } |
| 263 | if (!(sym_is_choice(sym) && mode == def_random)) |
| 264 | sym->flags |= SYMBOL_DEF_USER; |
| 265 | break; |
| 266 | default: |
| 267 | break; |
| 268 | } |
| 269 | |
| 270 | } |
| 271 | |
| 272 | sym_clear_all_valid(); |
| 273 | |
| 274 | /* |
| 275 | * We have different type of choice blocks. |
| 276 | * If curr.tri equals to mod then we can select several |
| 277 | * choice symbols in one block. |
| 278 | * In this case we do nothing. |
| 279 | * If curr.tri equals yes then only one symbol can be |
| 280 | * selected in a choice block and we set it to yes, |
| 281 | * and the rest to no. |
| 282 | */ |
| 283 | if (mode != def_random) { |
| 284 | for_all_symbols(i, csym) { |
| 285 | if ((sym_is_choice(csym) && !sym_has_value(csym)) || |
| 286 | sym_is_choice_value(csym)) |
| 287 | csym->flags |= SYMBOL_NEED_SET_CHOICE_VALUES; |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | for_all_symbols(i, csym) { |
| 292 | if (sym_has_value(csym) || !sym_is_choice(csym)) |
| 293 | continue; |
| 294 | |
| 295 | sym_calc_value(csym); |
| 296 | if (mode == def_random) |
| 297 | has_changed |= randomize_choice_values(csym); |
| 298 | else { |
| 299 | set_all_choice_values(csym); |
| 300 | has_changed = true; |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | return has_changed; |
| 305 | } |
| 306 | |
| 307 | static void conf_rewrite_mod_or_yes(enum conf_def_mode mode) |
| 308 | { |
| 309 | struct symbol *sym; |
| 310 | int i; |
| 311 | tristate old_val = (mode == def_y2m) ? yes : mod; |
| 312 | tristate new_val = (mode == def_y2m) ? mod : yes; |
| 313 | |
| 314 | for_all_symbols(i, sym) { |
| 315 | if (sym_get_type(sym) == S_TRISTATE && |
| 316 | sym->def[S_DEF_USER].tri == old_val) |
| 317 | sym->def[S_DEF_USER].tri = new_val; |
| 318 | } |
| 319 | sym_clear_all_valid(); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | static int conf_askvalue(struct symbol *sym, const char *def) |
| 323 | { |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 324 | if (!sym_has_value(sym)) |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 325 | printf("(NEW) "); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 326 | |
| 327 | line[0] = '\n'; |
| 328 | line[1] = 0; |
| 329 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 330 | if (!sym_is_changeable(sym)) { |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 331 | printf("%s\n", def); |
| 332 | line[0] = '\n'; |
| 333 | line[1] = 0; |
| 334 | return 0; |
| 335 | } |
| 336 | |
| 337 | switch (input_mode) { |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 338 | case oldconfig: |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 339 | case syncconfig: |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 340 | if (sym_has_value(sym)) { |
| 341 | printf("%s\n", def); |
| 342 | return 0; |
| 343 | } |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 344 | /* fall through */ |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 345 | default: |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 346 | fflush(stdout); |
| 347 | xfgets(line, sizeof(line), stdin); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 348 | break; |
| 349 | } |
| 350 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 351 | return 1; |
| 352 | } |
| 353 | |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 354 | static int conf_string(struct menu *menu) |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 355 | { |
| 356 | struct symbol *sym = menu->sym; |
| 357 | const char *def; |
| 358 | |
| 359 | while (1) { |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 360 | printf("%*s%s ", indent - 1, "", menu->prompt->text); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 361 | printf("(%s) ", sym->name); |
| 362 | def = sym_get_string_value(sym); |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 363 | if (def) |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 364 | printf("[%s] ", def); |
| 365 | if (!conf_askvalue(sym, def)) |
| 366 | return 0; |
| 367 | switch (line[0]) { |
| 368 | case '\n': |
| 369 | break; |
| 370 | case '?': |
| 371 | /* print help */ |
| 372 | if (line[1] == '\n') { |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 373 | print_help(menu); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 374 | def = NULL; |
| 375 | break; |
| 376 | } |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 377 | /* fall through */ |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 378 | default: |
| 379 | line[strlen(line)-1] = 0; |
| 380 | def = line; |
| 381 | } |
| 382 | if (def && sym_set_string_value(sym, def)) |
| 383 | return 0; |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | static int conf_sym(struct menu *menu) |
| 388 | { |
| 389 | struct symbol *sym = menu->sym; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 390 | tristate oldval, newval; |
| 391 | |
| 392 | while (1) { |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 393 | printf("%*s%s ", indent - 1, "", menu->prompt->text); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 394 | if (sym->name) |
| 395 | printf("(%s) ", sym->name); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 396 | putchar('['); |
| 397 | oldval = sym_get_tristate_value(sym); |
| 398 | switch (oldval) { |
| 399 | case no: |
| 400 | putchar('N'); |
| 401 | break; |
| 402 | case mod: |
| 403 | putchar('M'); |
| 404 | break; |
| 405 | case yes: |
| 406 | putchar('Y'); |
| 407 | break; |
| 408 | } |
| 409 | if (oldval != no && sym_tristate_within_range(sym, no)) |
| 410 | printf("/n"); |
| 411 | if (oldval != mod && sym_tristate_within_range(sym, mod)) |
| 412 | printf("/m"); |
| 413 | if (oldval != yes && sym_tristate_within_range(sym, yes)) |
| 414 | printf("/y"); |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 415 | printf("/?] "); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 416 | if (!conf_askvalue(sym, sym_get_string_value(sym))) |
| 417 | return 0; |
| 418 | strip(line); |
| 419 | |
| 420 | switch (line[0]) { |
| 421 | case 'n': |
| 422 | case 'N': |
| 423 | newval = no; |
| 424 | if (!line[1] || !strcmp(&line[1], "o")) |
| 425 | break; |
| 426 | continue; |
| 427 | case 'm': |
| 428 | case 'M': |
| 429 | newval = mod; |
| 430 | if (!line[1]) |
| 431 | break; |
| 432 | continue; |
| 433 | case 'y': |
| 434 | case 'Y': |
| 435 | newval = yes; |
| 436 | if (!line[1] || !strcmp(&line[1], "es")) |
| 437 | break; |
| 438 | continue; |
| 439 | case 0: |
| 440 | newval = oldval; |
| 441 | break; |
| 442 | case '?': |
| 443 | goto help; |
| 444 | default: |
| 445 | continue; |
| 446 | } |
| 447 | if (sym_set_tristate_value(sym, newval)) |
| 448 | return 0; |
| 449 | help: |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 450 | print_help(menu); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 451 | } |
| 452 | } |
| 453 | |
| 454 | static int conf_choice(struct menu *menu) |
| 455 | { |
| 456 | struct symbol *sym, *def_sym; |
| 457 | struct menu *child; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 458 | bool is_new; |
| 459 | |
| 460 | sym = menu->sym; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 461 | is_new = !sym_has_value(sym); |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 462 | if (sym_is_changeable(sym)) { |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 463 | conf_sym(menu); |
| 464 | sym_calc_value(sym); |
| 465 | switch (sym_get_tristate_value(sym)) { |
| 466 | case no: |
| 467 | return 1; |
| 468 | case mod: |
| 469 | return 0; |
| 470 | case yes: |
| 471 | break; |
| 472 | } |
| 473 | } else { |
| 474 | switch (sym_get_tristate_value(sym)) { |
| 475 | case no: |
| 476 | return 1; |
| 477 | case mod: |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 478 | printf("%*s%s\n", indent - 1, "", menu_get_prompt(menu)); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 479 | return 0; |
| 480 | case yes: |
| 481 | break; |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | while (1) { |
| 486 | int cnt, def; |
| 487 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 488 | printf("%*s%s\n", indent - 1, "", menu_get_prompt(menu)); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 489 | def_sym = sym_get_choice_value(sym); |
| 490 | cnt = def = 0; |
| 491 | line[0] = 0; |
| 492 | for (child = menu->list; child; child = child->next) { |
| 493 | if (!menu_is_visible(child)) |
| 494 | continue; |
| 495 | if (!child->sym) { |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 496 | printf("%*c %s\n", indent, '*', menu_get_prompt(child)); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 497 | continue; |
| 498 | } |
| 499 | cnt++; |
| 500 | if (child->sym == def_sym) { |
| 501 | def = cnt; |
| 502 | printf("%*c", indent, '>'); |
| 503 | } else |
| 504 | printf("%*c", indent, ' '); |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 505 | printf(" %d. %s", cnt, menu_get_prompt(child)); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 506 | if (child->sym->name) |
| 507 | printf(" (%s)", child->sym->name); |
| 508 | if (!sym_has_value(child->sym)) |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 509 | printf(" (NEW)"); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 510 | printf("\n"); |
| 511 | } |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 512 | printf("%*schoice", indent - 1, ""); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 513 | if (cnt == 1) { |
| 514 | printf("[1]: 1\n"); |
| 515 | goto conf_childs; |
| 516 | } |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 517 | printf("[1-%d?]: ", cnt); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 518 | switch (input_mode) { |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 519 | case oldconfig: |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 520 | case syncconfig: |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 521 | if (!is_new) { |
| 522 | cnt = def; |
| 523 | printf("%d\n", cnt); |
| 524 | break; |
| 525 | } |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 526 | /* fall through */ |
| 527 | case oldaskconfig: |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 528 | fflush(stdout); |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 529 | xfgets(line, sizeof(line), stdin); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 530 | strip(line); |
| 531 | if (line[0] == '?') { |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 532 | print_help(menu); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 533 | continue; |
| 534 | } |
| 535 | if (!line[0]) |
| 536 | cnt = def; |
| 537 | else if (isdigit(line[0])) |
| 538 | cnt = atoi(line); |
| 539 | else |
| 540 | continue; |
| 541 | break; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 542 | default: |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 543 | break; |
| 544 | } |
| 545 | |
| 546 | conf_childs: |
| 547 | for (child = menu->list; child; child = child->next) { |
| 548 | if (!child->sym || !menu_is_visible(child)) |
| 549 | continue; |
| 550 | if (!--cnt) |
| 551 | break; |
| 552 | } |
| 553 | if (!child) |
| 554 | continue; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 555 | if (line[0] && line[strlen(line) - 1] == '?') { |
| 556 | print_help(child); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 557 | continue; |
| 558 | } |
| 559 | sym_set_choice_value(sym, child->sym); |
| 560 | for (child = child->list; child; child = child->next) { |
| 561 | indent += 2; |
| 562 | conf(child); |
| 563 | indent -= 2; |
| 564 | } |
| 565 | return 1; |
| 566 | } |
| 567 | } |
| 568 | |
| 569 | static void conf(struct menu *menu) |
| 570 | { |
| 571 | struct symbol *sym; |
| 572 | struct property *prop; |
| 573 | struct menu *child; |
| 574 | |
| 575 | if (!menu_is_visible(menu)) |
| 576 | return; |
| 577 | |
| 578 | sym = menu->sym; |
| 579 | prop = menu->prompt; |
| 580 | if (prop) { |
| 581 | const char *prompt; |
| 582 | |
| 583 | switch (prop->type) { |
| 584 | case P_MENU: |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 585 | /* |
| 586 | * Except in oldaskconfig mode, we show only menus that |
| 587 | * contain new symbols. |
| 588 | */ |
| 589 | if (input_mode != oldaskconfig && rootEntry != menu) { |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 590 | check_conf(menu); |
| 591 | return; |
| 592 | } |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 593 | /* fall through */ |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 594 | case P_COMMENT: |
| 595 | prompt = menu_get_prompt(menu); |
| 596 | if (prompt) |
| 597 | printf("%*c\n%*c %s\n%*c\n", |
| 598 | indent, '*', |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 599 | indent, '*', prompt, |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 600 | indent, '*'); |
| 601 | default: |
| 602 | ; |
| 603 | } |
| 604 | } |
| 605 | |
| 606 | if (!sym) |
| 607 | goto conf_childs; |
| 608 | |
| 609 | if (sym_is_choice(sym)) { |
| 610 | conf_choice(menu); |
| 611 | if (sym->curr.tri != mod) |
| 612 | return; |
| 613 | goto conf_childs; |
| 614 | } |
| 615 | |
| 616 | switch (sym->type) { |
| 617 | case S_INT: |
| 618 | case S_HEX: |
| 619 | case S_STRING: |
| 620 | conf_string(menu); |
| 621 | break; |
| 622 | default: |
| 623 | conf_sym(menu); |
| 624 | break; |
| 625 | } |
| 626 | |
| 627 | conf_childs: |
| 628 | if (sym) |
| 629 | indent += 2; |
| 630 | for (child = menu->list; child; child = child->next) |
| 631 | conf(child); |
| 632 | if (sym) |
| 633 | indent -= 2; |
| 634 | } |
| 635 | |
| 636 | static void check_conf(struct menu *menu) |
| 637 | { |
| 638 | struct symbol *sym; |
| 639 | struct menu *child; |
| 640 | |
| 641 | if (!menu_is_visible(menu)) |
| 642 | return; |
| 643 | |
| 644 | sym = menu->sym; |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 645 | if (sym && !sym_has_value(sym) && |
| 646 | (sym_is_changeable(sym) || |
| 647 | (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes))) { |
| 648 | |
| 649 | switch (input_mode) { |
| 650 | case listnewconfig: |
| 651 | if (sym->name) { |
| 652 | const char *str; |
| 653 | |
| 654 | if (sym->type == S_STRING) { |
| 655 | str = sym_get_string_value(sym); |
| 656 | str = sym_escape_string_value(str); |
| 657 | printf("%s%s=%s\n", CONFIG_, sym->name, str); |
| 658 | free((void *)str); |
| 659 | } else { |
| 660 | str = sym_get_string_value(sym); |
| 661 | printf("%s%s=%s\n", CONFIG_, sym->name, str); |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 662 | } |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 663 | } |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 664 | break; |
| 665 | case helpnewconfig: |
| 666 | printf("-----\n"); |
| 667 | print_help(menu); |
| 668 | printf("-----\n"); |
| 669 | break; |
| 670 | default: |
| 671 | if (!conf_cnt++) |
| 672 | printf("*\n* Restart config...\n*\n"); |
| 673 | rootEntry = menu_get_parent_menu(menu); |
| 674 | conf(rootEntry); |
| 675 | break; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 676 | } |
| 677 | } |
| 678 | |
| 679 | for (child = menu->list; child; child = child->next) |
| 680 | check_conf(child); |
| 681 | } |
| 682 | |
Patrick Georgi | 9f7c78b | 2021-09-23 14:15:40 +0200 | [diff] [blame] | 683 | static const struct option long_opts[] = { |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 684 | {"help", no_argument, NULL, 'h'}, |
| 685 | {"silent", no_argument, NULL, 's'}, |
| 686 | {"oldaskconfig", no_argument, &input_mode_opt, oldaskconfig}, |
| 687 | {"oldconfig", no_argument, &input_mode_opt, oldconfig}, |
| 688 | {"syncconfig", no_argument, &input_mode_opt, syncconfig}, |
| 689 | {"defconfig", required_argument, &input_mode_opt, defconfig}, |
| 690 | {"savedefconfig", required_argument, &input_mode_opt, savedefconfig}, |
| 691 | {"allnoconfig", no_argument, &input_mode_opt, allnoconfig}, |
| 692 | {"allyesconfig", no_argument, &input_mode_opt, allyesconfig}, |
| 693 | {"allmodconfig", no_argument, &input_mode_opt, allmodconfig}, |
| 694 | {"alldefconfig", no_argument, &input_mode_opt, alldefconfig}, |
| 695 | {"randconfig", no_argument, &input_mode_opt, randconfig}, |
| 696 | {"listnewconfig", no_argument, &input_mode_opt, listnewconfig}, |
| 697 | {"helpnewconfig", no_argument, &input_mode_opt, helpnewconfig}, |
| 698 | {"olddefconfig", no_argument, &input_mode_opt, olddefconfig}, |
| 699 | {"yes2modconfig", no_argument, &input_mode_opt, yes2modconfig}, |
| 700 | {"mod2yesconfig", no_argument, &input_mode_opt, mod2yesconfig}, |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 701 | {NULL, 0, NULL, 0} |
| 702 | }; |
| 703 | |
| 704 | static void conf_usage(const char *progname) |
| 705 | { |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 706 | printf("Usage: %s [options] <kconfig-file>\n", progname); |
| 707 | printf("\n"); |
| 708 | printf("Generic options:\n"); |
| 709 | printf(" -h, --help Print this message and exit.\n"); |
| 710 | printf(" -s, --silent Do not print log.\n"); |
| 711 | printf("\n"); |
| 712 | printf("Mode options:\n"); |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 713 | printf(" --listnewconfig List new options\n"); |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 714 | printf(" --helpnewconfig List new options and help text\n"); |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 715 | printf(" --oldaskconfig Start a new configuration using a line-oriented program\n"); |
| 716 | printf(" --oldconfig Update a configuration using a provided .config as base\n"); |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 717 | printf(" --syncconfig Similar to oldconfig but generates configuration in\n" |
| 718 | " include/{generated/,config/}\n"); |
| 719 | printf(" --olddefconfig Same as oldconfig but sets new symbols to their default value\n"); |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 720 | printf(" --defconfig <file> New config with default defined in <file>\n"); |
| 721 | printf(" --savedefconfig <file> Save the minimal current configuration to <file>\n"); |
| 722 | printf(" --allnoconfig New config where all options are answered with no\n"); |
| 723 | printf(" --allyesconfig New config where all options are answered with yes\n"); |
| 724 | printf(" --allmodconfig New config where all options are answered with mod\n"); |
| 725 | printf(" --alldefconfig New config with all symbols set to default\n"); |
| 726 | printf(" --randconfig New config with random answer to all options\n"); |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 727 | printf(" --yes2modconfig Change answers from yes to mod if possible\n"); |
| 728 | printf(" --mod2yesconfig Change answers from mod to yes if possible\n"); |
| 729 | printf(" (If none of the above is given, --oldaskconfig is the default)\n"); |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 730 | } |
| 731 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 732 | int main(int ac, char **av) |
| 733 | { |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 734 | const char *progname = av[0]; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 735 | int opt; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 736 | const char *name, *defconfig_file = NULL /* gcc uninit */; |
Stefan Reinauer | 57a3131 | 2015-08-20 11:19:34 -0700 | [diff] [blame] | 737 | char *env; |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 738 | int no_conf_write = 0; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 739 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 740 | tty_stdio = isatty(0) && isatty(1); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 741 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 742 | while ((opt = getopt_long(ac, av, "hs", long_opts, NULL)) != -1) { |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 743 | switch (opt) { |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 744 | case 'h': |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 745 | conf_usage(progname); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 746 | exit(1); |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 747 | break; |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 748 | case 's': |
| 749 | conf_set_message_callback(NULL); |
| 750 | break; |
| 751 | case 0: |
| 752 | input_mode = input_mode_opt; |
| 753 | switch (input_mode) { |
| 754 | case syncconfig: |
| 755 | /* |
| 756 | * syncconfig is invoked during the build stage. |
| 757 | * Suppress distracting |
| 758 | * "configuration written to ..." |
| 759 | */ |
| 760 | conf_set_message_callback(NULL); |
| 761 | sync_kconfig = 1; |
| 762 | break; |
| 763 | case defconfig: |
| 764 | case savedefconfig: |
| 765 | defconfig_file = optarg; |
| 766 | break; |
| 767 | case randconfig: |
| 768 | set_randconfig_seed(); |
| 769 | break; |
| 770 | default: |
| 771 | break; |
| 772 | } |
| 773 | default: |
| 774 | break; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 775 | } |
| 776 | } |
| 777 | if (ac == optind) { |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 778 | fprintf(stderr, "%s: Kconfig file missing\n", av[0]); |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 779 | conf_usage(progname); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 780 | exit(1); |
| 781 | } |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 782 | conf_parse(av[optind]); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 783 | //zconfdump(stdout); |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 784 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 785 | switch (input_mode) { |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 786 | case defconfig: |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 787 | if (conf_read(defconfig_file)) { |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 788 | fprintf(stderr, |
| 789 | "***\n" |
| 790 | "*** Can't find default configuration \"%s\"!\n" |
| 791 | "***\n", |
| 792 | defconfig_file); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 793 | exit(1); |
| 794 | } |
| 795 | break; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 796 | case savedefconfig: |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 797 | case syncconfig: |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 798 | case oldaskconfig: |
| 799 | case oldconfig: |
| 800 | case listnewconfig: |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 801 | case helpnewconfig: |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 802 | case olddefconfig: |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 803 | case yes2modconfig: |
| 804 | case mod2yesconfig: |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 805 | conf_read(NULL); |
| 806 | break; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 807 | case allnoconfig: |
| 808 | case allyesconfig: |
| 809 | case allmodconfig: |
| 810 | case alldefconfig: |
| 811 | case randconfig: |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 812 | name = getenv("KCONFIG_ALLCONFIG"); |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 813 | if (!name) |
| 814 | break; |
| 815 | if ((strcmp(name, "") != 0) && (strcmp(name, "1") != 0)) { |
| 816 | if (conf_read_simple(name, S_DEF_USER)) { |
| 817 | fprintf(stderr, |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 818 | "*** Can't read seed configuration \"%s\"!\n", |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 819 | name); |
| 820 | exit(1); |
| 821 | } |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 822 | break; |
| 823 | } |
| 824 | switch (input_mode) { |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 825 | case allnoconfig: name = "allno.config"; break; |
| 826 | case allyesconfig: name = "allyes.config"; break; |
| 827 | case allmodconfig: name = "allmod.config"; break; |
| 828 | case alldefconfig: name = "alldef.config"; break; |
| 829 | case randconfig: name = "allrandom.config"; break; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 830 | default: break; |
| 831 | } |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 832 | if (conf_read_simple(name, S_DEF_USER) && |
| 833 | conf_read_simple("all.config", S_DEF_USER)) { |
| 834 | fprintf(stderr, |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 835 | "*** KCONFIG_ALLCONFIG set, but no \"%s\" or \"all.config\" file found\n", |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 836 | name); |
| 837 | exit(1); |
| 838 | } |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 839 | break; |
| 840 | default: |
| 841 | break; |
| 842 | } |
| 843 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 844 | env = getenv("KCONFIG_STRICT"); |
| 845 | if (env && *env && kconfig_warnings) { |
| 846 | fprintf(stderr, "\n*** ERROR: %d warnings encountered, and " |
| 847 | "warnings are errors.\n\n", kconfig_warnings); |
| 848 | exit(1); |
| 849 | } |
| 850 | |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 851 | if (sync_kconfig) { |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 852 | name = getenv("KCONFIG_NOSILENTUPDATE"); |
| 853 | if (name && *name) { |
| 854 | if (conf_get_changed()) { |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 855 | fprintf(stderr, |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 856 | "\n*** The configuration requires explicit update.\n\n"); |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 857 | return 1; |
| 858 | } |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 859 | no_conf_write = 1; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 860 | } |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 861 | } |
| 862 | |
| 863 | switch (input_mode) { |
| 864 | case allnoconfig: |
| 865 | conf_set_all_new_symbols(def_no); |
| 866 | break; |
| 867 | case allyesconfig: |
| 868 | conf_set_all_new_symbols(def_yes); |
| 869 | break; |
| 870 | case allmodconfig: |
| 871 | conf_set_all_new_symbols(def_mod); |
| 872 | break; |
| 873 | case alldefconfig: |
| 874 | conf_set_all_new_symbols(def_default); |
| 875 | break; |
| 876 | case randconfig: |
| 877 | /* Really nothing to do in this loop */ |
| 878 | while (conf_set_all_new_symbols(def_random)) ; |
| 879 | break; |
| 880 | case defconfig: |
| 881 | conf_set_all_new_symbols(def_default); |
| 882 | break; |
| 883 | case savedefconfig: |
| 884 | break; |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 885 | case yes2modconfig: |
| 886 | conf_rewrite_mod_or_yes(def_y2m); |
| 887 | break; |
| 888 | case mod2yesconfig: |
| 889 | conf_rewrite_mod_or_yes(def_m2y); |
| 890 | break; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 891 | case oldaskconfig: |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 892 | rootEntry = &rootmenu; |
| 893 | conf(&rootmenu); |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 894 | input_mode = oldconfig; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 895 | /* fall through */ |
| 896 | case oldconfig: |
| 897 | case listnewconfig: |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 898 | case helpnewconfig: |
| 899 | case syncconfig: |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 900 | /* Update until a loop caused no more changes */ |
| 901 | do { |
| 902 | conf_cnt = 0; |
| 903 | check_conf(&rootmenu); |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 904 | } while (conf_cnt); |
| 905 | break; |
| 906 | case olddefconfig: |
| 907 | default: |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 908 | break; |
| 909 | } |
| 910 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 911 | if (input_mode == savedefconfig) { |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 912 | if (conf_write_defconfig(defconfig_file)) { |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 913 | fprintf(stderr, "\n*** Error while saving defconfig to: %s\n\n", |
Stefan Reinauer | 3ec23b3 | 2015-04-06 00:59:23 +0200 | [diff] [blame] | 914 | defconfig_file); |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 915 | return 1; |
| 916 | } |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 917 | } else if (input_mode != listnewconfig && input_mode != helpnewconfig) { |
| 918 | if (!no_conf_write && conf_write(NULL)) { |
| 919 | fprintf(stderr, "\n*** Error during writing of the configuration.\n\n"); |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 920 | exit(1); |
| 921 | } |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 922 | |
| 923 | /* |
| 924 | * Create auto.conf if it does not exist. |
| 925 | * This prevents GNU Make 4.1 or older from emitting |
| 926 | * "include/config/auto.conf: No such file or directory" |
| 927 | * in the top-level Makefile |
| 928 | * |
| 929 | * syncconfig always creates or updates auto.conf because it is |
| 930 | * used during the build. |
| 931 | */ |
| 932 | if (conf_write_autoconf(sync_kconfig) && sync_kconfig) { |
| 933 | fprintf(stderr, |
| 934 | "\n*** Error during sync of the configuration.\n\n"); |
| 935 | return 1; |
| 936 | } |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 937 | } |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 938 | return 0; |
| 939 | } |