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 | |
Roman Zippel | f82f3f9 | 2007-08-30 05:06:17 +0200 | [diff] [blame] | 115 | static int conf_askvalue(struct symbol *sym, const char *def) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | if (!sym_has_value(sym)) |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 118 | printf("(NEW) "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
| 120 | line[0] = '\n'; |
| 121 | line[1] = 0; |
| 122 | |
Marco Ammon | baa23ec | 2019-07-04 12:50:41 +0200 | [diff] [blame] | 123 | if (!sym_is_changeable(sym)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | printf("%s\n", def); |
| 125 | line[0] = '\n'; |
| 126 | line[1] = 0; |
Roman Zippel | f82f3f9 | 2007-08-30 05:06:17 +0200 | [diff] [blame] | 127 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | switch (input_mode) { |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 131 | case oldconfig: |
Masahiro Yamada | 911a91c | 2018-03-01 15:34:37 +0900 | [diff] [blame] | 132 | case syncconfig: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | if (sym_has_value(sym)) { |
| 134 | printf("%s\n", def); |
Roman Zippel | f82f3f9 | 2007-08-30 05:06:17 +0200 | [diff] [blame] | 135 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | } |
Arnaud Lacombe | d8fc320 | 2011-05-31 12:30:26 -0400 | [diff] [blame] | 137 | /* fall through */ |
Masahiro Yamada | 102a1a7 | 2021-02-21 18:26:23 +0900 | [diff] [blame] | 138 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | fflush(stdout); |
Markus Mayer | 74dba80 | 2015-12-09 14:56:12 -0800 | [diff] [blame] | 140 | xfgets(line, sizeof(line), stdin); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | break; |
| 142 | } |
| 143 | |
Roman Zippel | f82f3f9 | 2007-08-30 05:06:17 +0200 | [diff] [blame] | 144 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | } |
| 146 | |
Trevor Keith | 4356f48 | 2009-09-18 12:49:23 -0700 | [diff] [blame] | 147 | static int conf_string(struct menu *menu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | { |
| 149 | struct symbol *sym = menu->sym; |
Sam Ravnborg | 03d2912 | 2007-07-21 00:00:36 +0200 | [diff] [blame] | 150 | const char *def; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
| 152 | while (1) { |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 153 | printf("%*s%s ", indent - 1, "", menu->prompt->text); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | printf("(%s) ", sym->name); |
| 155 | def = sym_get_string_value(sym); |
Mickaël Salaün | f82bd80 | 2021-02-15 19:15:09 +0100 | [diff] [blame] | 156 | if (def) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | printf("[%s] ", def); |
Roman Zippel | f82f3f9 | 2007-08-30 05:06:17 +0200 | [diff] [blame] | 158 | if (!conf_askvalue(sym, def)) |
| 159 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | switch (line[0]) { |
| 161 | case '\n': |
| 162 | break; |
| 163 | case '?': |
| 164 | /* print help */ |
| 165 | if (line[1] == '\n') { |
Cheng Renquan | 66c4bd8 | 2009-07-12 16:11:48 +0800 | [diff] [blame] | 166 | print_help(menu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | def = NULL; |
| 168 | break; |
| 169 | } |
Arnaud Lacombe | d8fc320 | 2011-05-31 12:30:26 -0400 | [diff] [blame] | 170 | /* fall through */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | default: |
| 172 | line[strlen(line)-1] = 0; |
| 173 | def = line; |
| 174 | } |
| 175 | if (def && sym_set_string_value(sym, def)) |
| 176 | return 0; |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | static int conf_sym(struct menu *menu) |
| 181 | { |
| 182 | struct symbol *sym = menu->sym; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | tristate oldval, newval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | |
| 185 | while (1) { |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 186 | printf("%*s%s ", indent - 1, "", menu->prompt->text); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | if (sym->name) |
| 188 | printf("(%s) ", sym->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | putchar('['); |
| 190 | oldval = sym_get_tristate_value(sym); |
| 191 | switch (oldval) { |
| 192 | case no: |
| 193 | putchar('N'); |
| 194 | break; |
| 195 | case mod: |
| 196 | putchar('M'); |
| 197 | break; |
| 198 | case yes: |
| 199 | putchar('Y'); |
| 200 | break; |
| 201 | } |
| 202 | if (oldval != no && sym_tristate_within_range(sym, no)) |
| 203 | printf("/n"); |
| 204 | if (oldval != mod && sym_tristate_within_range(sym, mod)) |
| 205 | printf("/m"); |
| 206 | if (oldval != yes && sym_tristate_within_range(sym, yes)) |
| 207 | printf("/y"); |
Masahiro Yamada | 4f208f3 | 2018-02-06 09:34:43 +0900 | [diff] [blame] | 208 | printf("/?] "); |
Roman Zippel | f82f3f9 | 2007-08-30 05:06:17 +0200 | [diff] [blame] | 209 | if (!conf_askvalue(sym, sym_get_string_value(sym))) |
| 210 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | strip(line); |
| 212 | |
| 213 | switch (line[0]) { |
| 214 | case 'n': |
| 215 | case 'N': |
| 216 | newval = no; |
| 217 | if (!line[1] || !strcmp(&line[1], "o")) |
| 218 | break; |
| 219 | continue; |
| 220 | case 'm': |
| 221 | case 'M': |
| 222 | newval = mod; |
| 223 | if (!line[1]) |
| 224 | break; |
| 225 | continue; |
| 226 | case 'y': |
| 227 | case 'Y': |
| 228 | newval = yes; |
| 229 | if (!line[1] || !strcmp(&line[1], "es")) |
| 230 | break; |
| 231 | continue; |
| 232 | case 0: |
| 233 | newval = oldval; |
| 234 | break; |
| 235 | case '?': |
| 236 | goto help; |
| 237 | default: |
| 238 | continue; |
| 239 | } |
| 240 | if (sym_set_tristate_value(sym, newval)) |
| 241 | return 0; |
| 242 | help: |
Cheng Renquan | 66c4bd8 | 2009-07-12 16:11:48 +0800 | [diff] [blame] | 243 | print_help(menu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | } |
| 245 | } |
| 246 | |
| 247 | static int conf_choice(struct menu *menu) |
| 248 | { |
| 249 | struct symbol *sym, *def_sym; |
| 250 | struct menu *child; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | bool is_new; |
| 252 | |
| 253 | sym = menu->sym; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | is_new = !sym_has_value(sym); |
Marco Ammon | baa23ec | 2019-07-04 12:50:41 +0200 | [diff] [blame] | 255 | if (sym_is_changeable(sym)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | conf_sym(menu); |
| 257 | sym_calc_value(sym); |
| 258 | switch (sym_get_tristate_value(sym)) { |
| 259 | case no: |
| 260 | return 1; |
| 261 | case mod: |
| 262 | return 0; |
| 263 | case yes: |
| 264 | break; |
| 265 | } |
| 266 | } else { |
| 267 | switch (sym_get_tristate_value(sym)) { |
| 268 | case no: |
| 269 | return 1; |
| 270 | case mod: |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 271 | printf("%*s%s\n", indent - 1, "", menu_get_prompt(menu)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | return 0; |
| 273 | case yes: |
| 274 | break; |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | while (1) { |
| 279 | int cnt, def; |
| 280 | |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 281 | printf("%*s%s\n", indent - 1, "", menu_get_prompt(menu)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | def_sym = sym_get_choice_value(sym); |
| 283 | cnt = def = 0; |
Roman Zippel | 40aee72 | 2006-04-09 17:26:39 +0200 | [diff] [blame] | 284 | line[0] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | for (child = menu->list; child; child = child->next) { |
| 286 | if (!menu_is_visible(child)) |
| 287 | continue; |
| 288 | if (!child->sym) { |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 289 | printf("%*c %s\n", indent, '*', menu_get_prompt(child)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | continue; |
| 291 | } |
| 292 | cnt++; |
| 293 | if (child->sym == def_sym) { |
| 294 | def = cnt; |
| 295 | printf("%*c", indent, '>'); |
| 296 | } else |
| 297 | printf("%*c", indent, ' '); |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 298 | printf(" %d. %s", cnt, menu_get_prompt(child)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | if (child->sym->name) |
| 300 | printf(" (%s)", child->sym->name); |
| 301 | if (!sym_has_value(child->sym)) |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 302 | printf(" (NEW)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | printf("\n"); |
| 304 | } |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 305 | printf("%*schoice", indent - 1, ""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | if (cnt == 1) { |
| 307 | printf("[1]: 1\n"); |
| 308 | goto conf_childs; |
| 309 | } |
Masahiro Yamada | 4f208f3 | 2018-02-06 09:34:43 +0900 | [diff] [blame] | 310 | printf("[1-%d?]: ", cnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | switch (input_mode) { |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 312 | case oldconfig: |
Masahiro Yamada | 911a91c | 2018-03-01 15:34:37 +0900 | [diff] [blame] | 313 | case syncconfig: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | if (!is_new) { |
| 315 | cnt = def; |
| 316 | printf("%d\n", cnt); |
| 317 | break; |
| 318 | } |
Arnaud Lacombe | d8fc320 | 2011-05-31 12:30:26 -0400 | [diff] [blame] | 319 | /* fall through */ |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 320 | case oldaskconfig: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | fflush(stdout); |
Markus Mayer | 74dba80 | 2015-12-09 14:56:12 -0800 | [diff] [blame] | 322 | xfgets(line, sizeof(line), stdin); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | strip(line); |
| 324 | if (line[0] == '?') { |
Cheng Renquan | 66c4bd8 | 2009-07-12 16:11:48 +0800 | [diff] [blame] | 325 | print_help(menu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | continue; |
| 327 | } |
| 328 | if (!line[0]) |
| 329 | cnt = def; |
| 330 | else if (isdigit(line[0])) |
| 331 | cnt = atoi(line); |
| 332 | else |
| 333 | continue; |
| 334 | break; |
Sam Ravnborg | f443d2e | 2008-06-30 22:45:38 +0200 | [diff] [blame] | 335 | default: |
| 336 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | conf_childs: |
| 340 | for (child = menu->list; child; child = child->next) { |
| 341 | if (!child->sym || !menu_is_visible(child)) |
| 342 | continue; |
| 343 | if (!--cnt) |
| 344 | break; |
| 345 | } |
| 346 | if (!child) |
| 347 | continue; |
Ben Hutchings | 3ba4162 | 2011-04-23 18:42:56 +0100 | [diff] [blame] | 348 | if (line[0] && line[strlen(line) - 1] == '?') { |
Cheng Renquan | 66c4bd8 | 2009-07-12 16:11:48 +0800 | [diff] [blame] | 349 | print_help(child); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | continue; |
| 351 | } |
| 352 | sym_set_choice_value(sym, child->sym); |
Jan Beulich | f5eaa32 | 2008-01-24 11:54:23 +0000 | [diff] [blame] | 353 | for (child = child->list; child; child = child->next) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | indent += 2; |
Jan Beulich | f5eaa32 | 2008-01-24 11:54:23 +0000 | [diff] [blame] | 355 | conf(child); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | indent -= 2; |
| 357 | } |
| 358 | return 1; |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | static void conf(struct menu *menu) |
| 363 | { |
| 364 | struct symbol *sym; |
| 365 | struct property *prop; |
| 366 | struct menu *child; |
| 367 | |
| 368 | if (!menu_is_visible(menu)) |
| 369 | return; |
| 370 | |
| 371 | sym = menu->sym; |
| 372 | prop = menu->prompt; |
| 373 | if (prop) { |
| 374 | const char *prompt; |
| 375 | |
| 376 | switch (prop->type) { |
| 377 | case P_MENU: |
Masahiro Yamada | 2aad9b8 | 2018-02-28 09:15:24 +0900 | [diff] [blame] | 378 | /* |
| 379 | * Except in oldaskconfig mode, we show only menus that |
| 380 | * contain new symbols. |
| 381 | */ |
| 382 | if (input_mode != oldaskconfig && rootEntry != menu) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | check_conf(menu); |
| 384 | return; |
| 385 | } |
Arnaud Lacombe | d8fc320 | 2011-05-31 12:30:26 -0400 | [diff] [blame] | 386 | /* fall through */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | case P_COMMENT: |
| 388 | prompt = menu_get_prompt(menu); |
| 389 | if (prompt) |
| 390 | printf("%*c\n%*c %s\n%*c\n", |
| 391 | indent, '*', |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 392 | indent, '*', prompt, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | indent, '*'); |
| 394 | default: |
| 395 | ; |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | if (!sym) |
| 400 | goto conf_childs; |
| 401 | |
| 402 | if (sym_is_choice(sym)) { |
| 403 | conf_choice(menu); |
| 404 | if (sym->curr.tri != mod) |
| 405 | return; |
| 406 | goto conf_childs; |
| 407 | } |
| 408 | |
| 409 | switch (sym->type) { |
| 410 | case S_INT: |
| 411 | case S_HEX: |
| 412 | case S_STRING: |
| 413 | conf_string(menu); |
| 414 | break; |
| 415 | default: |
| 416 | conf_sym(menu); |
| 417 | break; |
| 418 | } |
| 419 | |
| 420 | conf_childs: |
| 421 | if (sym) |
| 422 | indent += 2; |
| 423 | for (child = menu->list; child; child = child->next) |
| 424 | conf(child); |
| 425 | if (sym) |
| 426 | indent -= 2; |
| 427 | } |
| 428 | |
| 429 | static void check_conf(struct menu *menu) |
| 430 | { |
| 431 | struct symbol *sym; |
| 432 | struct menu *child; |
| 433 | |
| 434 | if (!menu_is_visible(menu)) |
| 435 | return; |
| 436 | |
| 437 | sym = menu->sym; |
Masahiro Yamada | a4cff32 | 2021-02-21 18:26:22 +0900 | [diff] [blame] | 438 | if (sym && !sym_has_value(sym) && |
| 439 | (sym_is_changeable(sym) || |
| 440 | (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes))) { |
Don Zickus | 17baab6 | 2018-04-11 15:15:37 -0400 | [diff] [blame] | 441 | |
Masahiro Yamada | a4cff32 | 2021-02-21 18:26:22 +0900 | [diff] [blame] | 442 | switch (input_mode) { |
| 443 | case listnewconfig: |
| 444 | if (sym->name) { |
| 445 | const char *str; |
| 446 | |
| 447 | if (sym->type == S_STRING) { |
| 448 | str = sym_get_string_value(sym); |
| 449 | str = sym_escape_string_value(str); |
| 450 | printf("%s%s=%s\n", CONFIG_, sym->name, str); |
| 451 | free((void *)str); |
| 452 | } else { |
| 453 | str = sym_get_string_value(sym); |
| 454 | printf("%s%s=%s\n", CONFIG_, sym->name, str); |
Aristeu Rozanski | f0778c8 | 2010-05-06 12:48:34 -0400 | [diff] [blame] | 455 | } |
Aristeu Rozanski | f0778c8 | 2010-05-06 12:48:34 -0400 | [diff] [blame] | 456 | } |
Masahiro Yamada | a4cff32 | 2021-02-21 18:26:22 +0900 | [diff] [blame] | 457 | break; |
| 458 | case helpnewconfig: |
| 459 | printf("-----\n"); |
| 460 | print_help(menu); |
| 461 | printf("-----\n"); |
| 462 | break; |
| 463 | default: |
| 464 | if (!conf_cnt++) |
| 465 | printf("*\n* Restart config...\n*\n"); |
| 466 | rootEntry = menu_get_parent_menu(menu); |
| 467 | conf(rootEntry); |
| 468 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | for (child = menu->list; child; child = child->next) |
| 473 | check_conf(child); |
| 474 | } |
| 475 | |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 476 | static struct option long_opts[] = { |
Masahiro Yamada | bafc479 | 2021-03-14 04:48:26 +0900 | [diff] [blame] | 477 | {"help", no_argument, NULL, 'h'}, |
| 478 | {"silent", no_argument, NULL, 's'}, |
Masahiro Yamada | ed562c5 | 2021-03-14 04:48:25 +0900 | [diff] [blame] | 479 | {"oldaskconfig", no_argument, &input_mode_opt, oldaskconfig}, |
| 480 | {"oldconfig", no_argument, &input_mode_opt, oldconfig}, |
| 481 | {"syncconfig", no_argument, &input_mode_opt, syncconfig}, |
| 482 | {"defconfig", required_argument, &input_mode_opt, defconfig}, |
| 483 | {"savedefconfig", required_argument, &input_mode_opt, savedefconfig}, |
| 484 | {"allnoconfig", no_argument, &input_mode_opt, allnoconfig}, |
| 485 | {"allyesconfig", no_argument, &input_mode_opt, allyesconfig}, |
| 486 | {"allmodconfig", no_argument, &input_mode_opt, allmodconfig}, |
| 487 | {"alldefconfig", no_argument, &input_mode_opt, alldefconfig}, |
| 488 | {"randconfig", no_argument, &input_mode_opt, randconfig}, |
| 489 | {"listnewconfig", no_argument, &input_mode_opt, listnewconfig}, |
| 490 | {"helpnewconfig", no_argument, &input_mode_opt, helpnewconfig}, |
| 491 | {"olddefconfig", no_argument, &input_mode_opt, olddefconfig}, |
| 492 | {"yes2modconfig", no_argument, &input_mode_opt, yes2modconfig}, |
| 493 | {"mod2yesconfig", no_argument, &input_mode_opt, mod2yesconfig}, |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 494 | {NULL, 0, NULL, 0} |
| 495 | }; |
| 496 | |
Arnaud Lacombe | 3254399 | 2010-11-02 00:26:33 -0400 | [diff] [blame] | 497 | static void conf_usage(const char *progname) |
| 498 | { |
Masahiro Yamada | ee4c6f0 | 2021-03-14 04:48:27 +0900 | [diff] [blame^] | 499 | printf("Usage: %s [options] <kconfig-file>\n", progname); |
| 500 | printf("\n"); |
| 501 | printf("Generic options:\n"); |
| 502 | printf(" -h, --help Print this message and exit.\n"); |
| 503 | printf(" -s, --silent Do not print log.\n"); |
| 504 | printf("\n"); |
| 505 | printf("Mode options:\n"); |
Arnaud Lacombe | 3254399 | 2010-11-02 00:26:33 -0400 | [diff] [blame] | 506 | printf(" --listnewconfig List new options\n"); |
Laura Abbott | 5d8b42a | 2019-11-04 17:10:08 -0500 | [diff] [blame] | 507 | printf(" --helpnewconfig List new options and help text\n"); |
Arnaud Lacombe | 3254399 | 2010-11-02 00:26:33 -0400 | [diff] [blame] | 508 | printf(" --oldaskconfig Start a new configuration using a line-oriented program\n"); |
| 509 | printf(" --oldconfig Update a configuration using a provided .config as base\n"); |
Masahiro Yamada | 911a91c | 2018-03-01 15:34:37 +0900 | [diff] [blame] | 510 | printf(" --syncconfig Similar to oldconfig but generates configuration in\n" |
| 511 | " include/{generated/,config/}\n"); |
Marc Herbert | cedd55d | 2018-01-26 14:59:00 -0800 | [diff] [blame] | 512 | 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] | 513 | printf(" --defconfig <file> New config with default defined in <file>\n"); |
| 514 | printf(" --savedefconfig <file> Save the minimal current configuration to <file>\n"); |
| 515 | printf(" --allnoconfig New config where all options are answered with no\n"); |
| 516 | printf(" --allyesconfig New config where all options are answered with yes\n"); |
| 517 | printf(" --allmodconfig New config where all options are answered with mod\n"); |
| 518 | printf(" --alldefconfig New config with all symbols set to default\n"); |
| 519 | printf(" --randconfig New config with random answer to all options\n"); |
Tetsuo Handa | 89b9060 | 2019-12-17 18:42:06 +0900 | [diff] [blame] | 520 | printf(" --yes2modconfig Change answers from yes to mod if possible\n"); |
| 521 | printf(" --mod2yesconfig Change answers from mod to yes if possible\n"); |
Masahiro Yamada | ae8da72 | 2021-02-21 22:03:17 +0900 | [diff] [blame] | 522 | 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] | 523 | } |
| 524 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | int main(int ac, char **av) |
| 526 | { |
Arnaud Lacombe | 3254399 | 2010-11-02 00:26:33 -0400 | [diff] [blame] | 527 | const char *progname = av[0]; |
Andres Salomon | 2f4b489 | 2007-12-17 01:34:58 -0500 | [diff] [blame] | 528 | int opt; |
Arnaud Lacombe | 275744c | 2010-10-13 20:43:28 -0400 | [diff] [blame] | 529 | const char *name, *defconfig_file = NULL /* gcc uninit */; |
Masahiro Yamada | 16952b7 | 2018-07-20 16:46:30 +0900 | [diff] [blame] | 530 | int no_conf_write = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | |
Masahiro Yamada | f3ff6fb | 2018-02-08 14:56:40 +0900 | [diff] [blame] | 532 | tty_stdio = isatty(0) && isatty(1); |
Ben Hutchings | 62dc989 | 2013-02-19 02:24:26 +0200 | [diff] [blame] | 533 | |
Masahiro Yamada | a2af62c | 2021-02-21 22:03:16 +0900 | [diff] [blame] | 534 | while ((opt = getopt_long(ac, av, "hs", long_opts, NULL)) != -1) { |
Andres Salomon | 2f4b489 | 2007-12-17 01:34:58 -0500 | [diff] [blame] | 535 | switch (opt) { |
Masahiro Yamada | a2af62c | 2021-02-21 22:03:16 +0900 | [diff] [blame] | 536 | case 'h': |
Arnaud Lacombe | 3254399 | 2010-11-02 00:26:33 -0400 | [diff] [blame] | 537 | conf_usage(progname); |
Andres Salomon | 2f4b489 | 2007-12-17 01:34:58 -0500 | [diff] [blame] | 538 | exit(1); |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 539 | break; |
Masahiro Yamada | ed562c5 | 2021-03-14 04:48:25 +0900 | [diff] [blame] | 540 | case 's': |
| 541 | conf_set_message_callback(NULL); |
| 542 | break; |
| 543 | case 0: |
| 544 | input_mode = input_mode_opt; |
| 545 | switch (input_mode) { |
| 546 | case syncconfig: |
| 547 | /* |
| 548 | * syncconfig is invoked during the build stage. |
| 549 | * Suppress distracting |
| 550 | * "configuration written to ..." |
| 551 | */ |
| 552 | conf_set_message_callback(NULL); |
| 553 | sync_kconfig = 1; |
| 554 | break; |
| 555 | case defconfig: |
| 556 | case savedefconfig: |
| 557 | defconfig_file = optarg; |
| 558 | break; |
| 559 | case randconfig: |
| 560 | set_randconfig_seed(); |
| 561 | break; |
| 562 | default: |
| 563 | break; |
| 564 | } |
| 565 | default: |
| 566 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | } |
| 568 | } |
Andres Salomon | 2f4b489 | 2007-12-17 01:34:58 -0500 | [diff] [blame] | 569 | if (ac == optind) { |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 570 | fprintf(stderr, "%s: Kconfig file missing\n", av[0]); |
Arnaud Lacombe | 3254399 | 2010-11-02 00:26:33 -0400 | [diff] [blame] | 571 | conf_usage(progname); |
Randy Dunlap | 250725a | 2006-06-08 22:12:50 -0700 | [diff] [blame] | 572 | exit(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | } |
Andres Salomon | 2f4b489 | 2007-12-17 01:34:58 -0500 | [diff] [blame] | 574 | name = av[optind]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | conf_parse(name); |
| 576 | //zconfdump(stdout); |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 577 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | switch (input_mode) { |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 579 | case defconfig: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | if (conf_read(defconfig_file)) { |
Masahiro Yamada | 9e3e10c | 2018-02-06 09:34:41 +0900 | [diff] [blame] | 581 | fprintf(stderr, |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 582 | "***\n" |
Masahiro Yamada | 9e3e10c | 2018-02-06 09:34:41 +0900 | [diff] [blame] | 583 | "*** Can't find default configuration \"%s\"!\n" |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 584 | "***\n", |
Masahiro Yamada | 9e3e10c | 2018-02-06 09:34:41 +0900 | [diff] [blame] | 585 | defconfig_file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | exit(1); |
| 587 | } |
| 588 | break; |
Sam Ravnborg | 7cf3d73 | 2010-07-31 23:35:34 +0200 | [diff] [blame] | 589 | case savedefconfig: |
Masahiro Yamada | 911a91c | 2018-03-01 15:34:37 +0900 | [diff] [blame] | 590 | case syncconfig: |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 591 | case oldaskconfig: |
| 592 | case oldconfig: |
Sam Ravnborg | 861b4ea | 2010-07-31 23:35:28 +0200 | [diff] [blame] | 593 | case listnewconfig: |
Laura Abbott | 5d8b42a | 2019-11-04 17:10:08 -0500 | [diff] [blame] | 594 | case helpnewconfig: |
Adam Lee | fb16d89 | 2012-09-01 01:05:17 +0800 | [diff] [blame] | 595 | case olddefconfig: |
Tetsuo Handa | 89b9060 | 2019-12-17 18:42:06 +0900 | [diff] [blame] | 596 | case yes2modconfig: |
| 597 | case mod2yesconfig: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | conf_read(NULL); |
| 599 | break; |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 600 | case allnoconfig: |
| 601 | case allyesconfig: |
| 602 | case allmodconfig: |
Sam Ravnborg | 0748cb3 | 2010-07-31 23:35:31 +0200 | [diff] [blame] | 603 | case alldefconfig: |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 604 | case randconfig: |
Roman Zippel | 9038916 | 2005-11-08 21:34:49 -0800 | [diff] [blame] | 605 | name = getenv("KCONFIG_ALLCONFIG"); |
Eric W. Biederman | 9f420bf | 2012-05-07 05:37:45 -0700 | [diff] [blame] | 606 | if (!name) |
| 607 | break; |
| 608 | if ((strcmp(name, "") != 0) && (strcmp(name, "1") != 0)) { |
Eric W. Biederman | 5efe241 | 2012-04-26 01:51:32 -0700 | [diff] [blame] | 609 | if (conf_read_simple(name, S_DEF_USER)) { |
| 610 | fprintf(stderr, |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 611 | "*** Can't read seed configuration \"%s\"!\n", |
Eric W. Biederman | 5efe241 | 2012-04-26 01:51:32 -0700 | [diff] [blame] | 612 | name); |
| 613 | exit(1); |
| 614 | } |
Roman Zippel | 9038916 | 2005-11-08 21:34:49 -0800 | [diff] [blame] | 615 | break; |
| 616 | } |
| 617 | switch (input_mode) { |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 618 | case allnoconfig: name = "allno.config"; break; |
| 619 | case allyesconfig: name = "allyes.config"; break; |
| 620 | case allmodconfig: name = "allmod.config"; break; |
Sam Ravnborg | 0748cb3 | 2010-07-31 23:35:31 +0200 | [diff] [blame] | 621 | case alldefconfig: name = "alldef.config"; break; |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 622 | case randconfig: name = "allrandom.config"; break; |
Roman Zippel | 9038916 | 2005-11-08 21:34:49 -0800 | [diff] [blame] | 623 | default: break; |
| 624 | } |
Eric W. Biederman | 5efe241 | 2012-04-26 01:51:32 -0700 | [diff] [blame] | 625 | if (conf_read_simple(name, S_DEF_USER) && |
| 626 | conf_read_simple("all.config", S_DEF_USER)) { |
| 627 | fprintf(stderr, |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 628 | "*** 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] | 629 | name); |
| 630 | exit(1); |
| 631 | } |
Roman Zippel | 9038916 | 2005-11-08 21:34:49 -0800 | [diff] [blame] | 632 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | default: |
| 634 | break; |
| 635 | } |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 636 | |
| 637 | if (sync_kconfig) { |
Masahiro Yamada | 16952b7 | 2018-07-20 16:46:30 +0900 | [diff] [blame] | 638 | name = getenv("KCONFIG_NOSILENTUPDATE"); |
| 639 | if (name && *name) { |
| 640 | if (conf_get_changed()) { |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 641 | fprintf(stderr, |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 642 | "\n*** The configuration requires explicit update.\n\n"); |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 643 | return 1; |
| 644 | } |
Masahiro Yamada | 16952b7 | 2018-07-20 16:46:30 +0900 | [diff] [blame] | 645 | no_conf_write = 1; |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 646 | } |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 647 | } |
| 648 | |
Sam Ravnborg | f443d2e | 2008-06-30 22:45:38 +0200 | [diff] [blame] | 649 | switch (input_mode) { |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 650 | case allnoconfig: |
Sam Ravnborg | f443d2e | 2008-06-30 22:45:38 +0200 | [diff] [blame] | 651 | conf_set_all_new_symbols(def_no); |
| 652 | break; |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 653 | case allyesconfig: |
Sam Ravnborg | f443d2e | 2008-06-30 22:45:38 +0200 | [diff] [blame] | 654 | conf_set_all_new_symbols(def_yes); |
| 655 | break; |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 656 | case allmodconfig: |
Sam Ravnborg | f443d2e | 2008-06-30 22:45:38 +0200 | [diff] [blame] | 657 | conf_set_all_new_symbols(def_mod); |
| 658 | break; |
Sam Ravnborg | 0748cb3 | 2010-07-31 23:35:31 +0200 | [diff] [blame] | 659 | case alldefconfig: |
| 660 | conf_set_all_new_symbols(def_default); |
| 661 | break; |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 662 | case randconfig: |
Yann E. MORIN | 3b9a19e | 2013-04-28 22:36:38 +0200 | [diff] [blame] | 663 | /* Really nothing to do in this loop */ |
| 664 | while (conf_set_all_new_symbols(def_random)) ; |
Sam Ravnborg | f443d2e | 2008-06-30 22:45:38 +0200 | [diff] [blame] | 665 | break; |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 666 | case defconfig: |
Sam Ravnborg | 09748e1 | 2008-06-30 23:02:59 +0200 | [diff] [blame] | 667 | conf_set_all_new_symbols(def_default); |
| 668 | break; |
Sam Ravnborg | 7cf3d73 | 2010-07-31 23:35:34 +0200 | [diff] [blame] | 669 | case savedefconfig: |
| 670 | break; |
Tetsuo Handa | 89b9060 | 2019-12-17 18:42:06 +0900 | [diff] [blame] | 671 | case yes2modconfig: |
| 672 | conf_rewrite_mod_or_yes(def_y2m); |
| 673 | break; |
| 674 | case mod2yesconfig: |
| 675 | conf_rewrite_mod_or_yes(def_m2y); |
| 676 | break; |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 677 | case oldaskconfig: |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 678 | rootEntry = &rootmenu; |
| 679 | conf(&rootmenu); |
Masahiro Yamada | 2aad9b8 | 2018-02-28 09:15:24 +0900 | [diff] [blame] | 680 | input_mode = oldconfig; |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 681 | /* fall through */ |
Sam Ravnborg | 1482834 | 2010-08-06 07:13:54 +0200 | [diff] [blame] | 682 | case oldconfig: |
Sam Ravnborg | 861b4ea | 2010-07-31 23:35:28 +0200 | [diff] [blame] | 683 | case listnewconfig: |
Laura Abbott | 5d8b42a | 2019-11-04 17:10:08 -0500 | [diff] [blame] | 684 | case helpnewconfig: |
Masahiro Yamada | 911a91c | 2018-03-01 15:34:37 +0900 | [diff] [blame] | 685 | case syncconfig: |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 686 | /* Update until a loop caused no more changes */ |
| 687 | do { |
| 688 | conf_cnt = 0; |
| 689 | check_conf(&rootmenu); |
Masahiro Yamada | 99f0b65 | 2018-02-28 09:15:23 +0900 | [diff] [blame] | 690 | } while (conf_cnt); |
Masahiro Yamada | 59a80b5 | 2018-02-28 09:15:21 +0900 | [diff] [blame] | 691 | break; |
| 692 | case olddefconfig: |
| 693 | default: |
Sam Ravnborg | f443d2e | 2008-06-30 22:45:38 +0200 | [diff] [blame] | 694 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | } |
Sam Ravnborg | f443d2e | 2008-06-30 22:45:38 +0200 | [diff] [blame] | 696 | |
Masahiro Yamada | 00c864f | 2018-07-20 16:46:31 +0900 | [diff] [blame] | 697 | if (input_mode == savedefconfig) { |
Sam Ravnborg | 7cf3d73 | 2010-07-31 23:35:34 +0200 | [diff] [blame] | 698 | if (conf_write_defconfig(defconfig_file)) { |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 699 | fprintf(stderr, "n*** Error while saving defconfig to: %s\n\n", |
Masahiro Yamada | bb66fc6 | 2014-06-10 19:08:13 +0900 | [diff] [blame] | 700 | defconfig_file); |
Sam Ravnborg | 7cf3d73 | 2010-07-31 23:35:34 +0200 | [diff] [blame] | 701 | return 1; |
| 702 | } |
Laura Abbott | 5d8b42a | 2019-11-04 17:10:08 -0500 | [diff] [blame] | 703 | } else if (input_mode != listnewconfig && input_mode != helpnewconfig) { |
Masahiro Yamada | 00c864f | 2018-07-20 16:46:31 +0900 | [diff] [blame] | 704 | if (!no_conf_write && conf_write(NULL)) { |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 705 | 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] | 706 | exit(1); |
| 707 | } |
Masahiro Yamada | 00c864f | 2018-07-20 16:46:31 +0900 | [diff] [blame] | 708 | |
| 709 | /* |
| 710 | * Create auto.conf if it does not exist. |
| 711 | * This prevents GNU Make 4.1 or older from emitting |
| 712 | * "include/config/auto.conf: No such file or directory" |
| 713 | * in the top-level Makefile |
| 714 | * |
| 715 | * syncconfig always creates or updates auto.conf because it is |
| 716 | * used during the build. |
| 717 | */ |
| 718 | if (conf_write_autoconf(sync_kconfig) && sync_kconfig) { |
| 719 | fprintf(stderr, |
| 720 | "\n*** Error during sync of the configuration.\n\n"); |
| 721 | return 1; |
| 722 | } |
Roman Zippel | c955cca | 2006-06-08 22:12:39 -0700 | [diff] [blame] | 723 | } |
Sam Ravnborg | 861b4ea | 2010-07-31 23:35:28 +0200 | [diff] [blame] | 724 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | } |