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