1
0

conf.c 20 KB

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