conf.c 18 KB

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