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