confdata.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807
  1. /*
  2. * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
  3. * Released under the terms of the GNU GPL v2.0.
  4. */
  5. #include <sys/stat.h>
  6. #include <ctype.h>
  7. #include <fcntl.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <time.h>
  12. #include <unistd.h>
  13. #define LKC_DIRECT_LINK
  14. #include "lkc.h"
  15. static void conf_warning(const char *fmt, ...)
  16. __attribute__ ((format (printf, 1, 2)));
  17. static const char *conf_filename;
  18. static int conf_lineno, conf_warnings, conf_unsaved;
  19. const char conf_defname[] = "extra/Configs/defconfigs/$ARCH";
  20. static void conf_warning(const char *fmt, ...)
  21. {
  22. va_list ap;
  23. va_start(ap, fmt);
  24. fprintf(stderr, "%s:%d:warning: ", conf_filename, conf_lineno);
  25. vfprintf(stderr, fmt, ap);
  26. fprintf(stderr, "\n");
  27. va_end(ap);
  28. conf_warnings++;
  29. }
  30. const char *conf_get_configname(void)
  31. {
  32. char *name = getenv("KCONFIG_CONFIG");
  33. return name ? name : ".config";
  34. }
  35. static char *conf_expand_value(const char *in)
  36. {
  37. struct symbol *sym;
  38. const char *src;
  39. static char res_value[SYMBOL_MAXLENGTH];
  40. char *dst, name[SYMBOL_MAXLENGTH];
  41. res_value[0] = 0;
  42. dst = name;
  43. while ((src = strchr(in, '$'))) {
  44. strncat(res_value, in, src - in);
  45. src++;
  46. dst = name;
  47. while (isalnum(*src) || *src == '_')
  48. *dst++ = *src++;
  49. *dst = 0;
  50. sym = sym_lookup(name, 0);
  51. sym_calc_value(sym);
  52. strcat(res_value, sym_get_string_value(sym));
  53. in = src;
  54. }
  55. strcat(res_value, in);
  56. return res_value;
  57. }
  58. char *conf_get_default_confname(void)
  59. {
  60. struct stat buf;
  61. static char fullname[PATH_MAX+1];
  62. char *env, *name;
  63. name = conf_expand_value(conf_defname);
  64. env = getenv(SRCTREE);
  65. if (env) {
  66. sprintf(fullname, "%s/%s", env, name);
  67. if (!stat(fullname, &buf))
  68. return fullname;
  69. }
  70. return name;
  71. }
  72. static int conf_set_sym_val(struct symbol *sym, int def, int def_flags, char *p)
  73. {
  74. char *p2;
  75. switch (sym->type) {
  76. case S_TRISTATE:
  77. if (p[0] == 'm') {
  78. sym->def[def].tri = mod;
  79. sym->flags |= def_flags;
  80. break;
  81. }
  82. case S_BOOLEAN:
  83. if (p[0] == 'y') {
  84. sym->def[def].tri = yes;
  85. sym->flags |= def_flags;
  86. break;
  87. }
  88. if (p[0] == 'n') {
  89. sym->def[def].tri = no;
  90. sym->flags |= def_flags;
  91. break;
  92. }
  93. conf_warning("symbol value '%s' invalid for %s", p, sym->name);
  94. break;
  95. case S_OTHER:
  96. if (*p != '"') {
  97. for (p2 = p; *p2 && !isspace(*p2); p2++)
  98. ;
  99. sym->type = S_STRING;
  100. goto done;
  101. }
  102. case S_STRING:
  103. if (*p++ != '"')
  104. break;
  105. for (p2 = p; (p2 = strpbrk(p2, "\"\\")); p2++) {
  106. if (*p2 == '"') {
  107. *p2 = 0;
  108. break;
  109. }
  110. memmove(p2, p2 + 1, strlen(p2));
  111. }
  112. if (!p2) {
  113. conf_warning("invalid string found");
  114. return 1;
  115. }
  116. case S_INT:
  117. case S_HEX:
  118. done:
  119. if (sym_string_valid(sym, p)) {
  120. sym->def[def].val = strdup(p);
  121. sym->flags |= def_flags;
  122. } else {
  123. conf_warning("symbol value '%s' invalid for %s", p, sym->name);
  124. return 1;
  125. }
  126. break;
  127. default:
  128. ;
  129. }
  130. return 0;
  131. }
  132. int conf_read_simple(const char *name, int def)
  133. {
  134. FILE *in = NULL;
  135. char line[1024];
  136. char *p, *p2;
  137. struct symbol *sym;
  138. int i, def_flags;
  139. if (name) {
  140. in = zconf_fopen(name);
  141. } else {
  142. struct property *prop;
  143. name = conf_get_configname();
  144. in = zconf_fopen(name);
  145. if (in)
  146. goto load;
  147. sym_add_change_count(1);
  148. if (!sym_defconfig_list)
  149. return 1;
  150. for_all_defaults(sym_defconfig_list, prop) {
  151. if (expr_calc_value(prop->visible.expr) == no ||
  152. prop->expr->type != E_SYMBOL)
  153. continue;
  154. name = conf_expand_value(prop->expr->left.sym->name);
  155. in = zconf_fopen(name);
  156. if (in) {
  157. printf(_("#\n"
  158. "# using defaults found in %s\n"
  159. "#\n"), name);
  160. goto load;
  161. }
  162. }
  163. }
  164. if (!in)
  165. return 1;
  166. load:
  167. conf_filename = name;
  168. conf_lineno = 0;
  169. conf_warnings = 0;
  170. conf_unsaved = 0;
  171. def_flags = SYMBOL_DEF << def;
  172. for_all_symbols(i, sym) {
  173. sym->flags |= SYMBOL_CHANGED;
  174. sym->flags &= ~(def_flags|SYMBOL_VALID);
  175. if (sym_is_choice(sym))
  176. sym->flags |= def_flags;
  177. switch (sym->type) {
  178. case S_INT:
  179. case S_HEX:
  180. case S_STRING:
  181. if (sym->def[def].val)
  182. free(sym->def[def].val);
  183. default:
  184. sym->def[def].val = NULL;
  185. sym->def[def].tri = no;
  186. }
  187. }
  188. while (fgets(line, sizeof(line), in)) {
  189. conf_lineno++;
  190. sym = NULL;
  191. switch (line[0]) {
  192. case '#':
  193. if (line[1]!=' ')
  194. continue;
  195. p = strchr(line + 2, ' ');
  196. if (!p)
  197. continue;
  198. *p++ = 0;
  199. if (strncmp(p, "is not set", 10))
  200. continue;
  201. if (def == S_DEF_USER) {
  202. sym = sym_find(line + 2);
  203. if (!sym) {
  204. conf_warning("trying to assign nonexistent symbol %s", line + 2);
  205. break;
  206. }
  207. } else {
  208. sym = sym_lookup(line + 2, 0);
  209. if (sym->type == S_UNKNOWN)
  210. sym->type = S_BOOLEAN;
  211. }
  212. if (sym->flags & def_flags) {
  213. conf_warning("override: reassigning to symbol %s", sym->name);
  214. }
  215. switch (sym->type) {
  216. case S_BOOLEAN:
  217. case S_TRISTATE:
  218. sym->def[def].tri = no;
  219. sym->flags |= def_flags;
  220. break;
  221. default:
  222. ;
  223. }
  224. break;
  225. case 'A' ... 'Z':
  226. p = strchr(line, '=');
  227. if (!p)
  228. continue;
  229. *p++ = 0;
  230. p2 = strchr(p, '\n');
  231. if (p2) {
  232. *p2-- = 0;
  233. if (*p2 == '\r')
  234. *p2 = 0;
  235. }
  236. if (def == S_DEF_USER) {
  237. sym = sym_find(line);
  238. if (!sym) {
  239. conf_warning("trying to assign nonexistent symbol %s", line);
  240. break;
  241. }
  242. } else {
  243. sym = sym_lookup(line, 0);
  244. if (sym->type == S_UNKNOWN)
  245. sym->type = S_OTHER;
  246. }
  247. if (sym->flags & def_flags) {
  248. conf_warning("override: reassigning to symbol %s", sym->name);
  249. }
  250. if (conf_set_sym_val(sym, def, def_flags, p))
  251. continue;
  252. break;
  253. case '\r':
  254. case '\n':
  255. break;
  256. default:
  257. conf_warning("unexpected data");
  258. continue;
  259. }
  260. if (sym && sym_is_choice_value(sym)) {
  261. struct symbol *cs = prop_get_symbol(sym_get_choice_prop(sym));
  262. switch (sym->def[def].tri) {
  263. case no:
  264. break;
  265. case mod:
  266. if (cs->def[def].tri == yes) {
  267. conf_warning("%s creates inconsistent choice state", sym->name);
  268. cs->flags &= ~def_flags;
  269. }
  270. break;
  271. case yes:
  272. if (cs->def[def].tri != no)
  273. conf_warning("override: %s changes choice state", sym->name);
  274. cs->def[def].val = sym;
  275. break;
  276. }
  277. cs->def[def].tri = EXPR_OR(cs->def[def].tri, sym->def[def].tri);
  278. }
  279. }
  280. fclose(in);
  281. if (modules_sym)
  282. sym_calc_value(modules_sym);
  283. return 0;
  284. }
  285. int conf_read(const char *name)
  286. {
  287. struct symbol *sym, *choice_sym;
  288. struct property *prop;
  289. struct expr *e;
  290. int i, flags;
  291. sym_set_change_count(0);
  292. if (conf_read_simple(name, S_DEF_USER))
  293. return 1;
  294. for_all_symbols(i, sym) {
  295. sym_calc_value(sym);
  296. if (sym_is_choice(sym) || (sym->flags & SYMBOL_AUTO))
  297. goto sym_ok;
  298. if (sym_has_value(sym) && (sym->flags & SYMBOL_WRITE)) {
  299. /* check that calculated value agrees with saved value */
  300. switch (sym->type) {
  301. case S_BOOLEAN:
  302. case S_TRISTATE:
  303. if (sym->def[S_DEF_USER].tri != sym_get_tristate_value(sym))
  304. break;
  305. if (!sym_is_choice(sym))
  306. goto sym_ok;
  307. default:
  308. if (!strcmp(sym->curr.val, sym->def[S_DEF_USER].val))
  309. goto sym_ok;
  310. break;
  311. }
  312. } else if (!sym_has_value(sym) && !(sym->flags & SYMBOL_WRITE))
  313. /* no previous value and not saved */
  314. goto sym_ok;
  315. conf_unsaved++;
  316. /* maybe print value in verbose mode... */
  317. sym_ok:
  318. if (!sym_is_choice(sym))
  319. continue;
  320. /* The choice symbol only has a set value (and thus is not new)
  321. * if all its visible childs have values.
  322. */
  323. prop = sym_get_choice_prop(sym);
  324. flags = sym->flags;
  325. expr_list_for_each_sym(prop->expr, e, choice_sym)
  326. if (choice_sym->visible != no)
  327. flags &= choice_sym->flags;
  328. sym->flags &= flags | ~SYMBOL_DEF_USER;
  329. }
  330. for_all_symbols(i, sym) {
  331. if (sym_has_value(sym) && !sym_is_choice_value(sym)) {
  332. /* Reset values of generates values, so they'll appear
  333. * as new, if they should become visible, but that
  334. * doesn't quite work if the Kconfig and the saved
  335. * configuration disagree.
  336. */
  337. if (sym->visible == no && !conf_unsaved)
  338. sym->flags &= ~SYMBOL_DEF_USER;
  339. switch (sym->type) {
  340. case S_STRING:
  341. case S_INT:
  342. case S_HEX:
  343. /* Reset a string value if it's out of range */
  344. if (sym_string_within_range(sym, sym->def[S_DEF_USER].val))
  345. break;
  346. sym->flags &= ~(SYMBOL_VALID|SYMBOL_DEF_USER);
  347. conf_unsaved++;
  348. break;
  349. default:
  350. break;
  351. }
  352. }
  353. }
  354. sym_add_change_count(conf_warnings || conf_unsaved);
  355. return 0;
  356. }
  357. int conf_write(const char *name)
  358. {
  359. FILE *out;
  360. struct symbol *sym;
  361. struct menu *menu;
  362. const char *basename;
  363. char dirname[128], tmpname[128], newname[128];
  364. int type, l;
  365. const char *str;
  366. time_t now;
  367. int use_timestamp = 1;
  368. char *env;
  369. dirname[0] = 0;
  370. if (name && name[0]) {
  371. struct stat st;
  372. char *slash;
  373. if (!stat(name, &st) && S_ISDIR(st.st_mode)) {
  374. strcpy(dirname, name);
  375. strcat(dirname, "/");
  376. basename = conf_get_configname();
  377. } else if ((slash = strrchr(name, '/'))) {
  378. int size = slash - name + 1;
  379. memcpy(dirname, name, size);
  380. dirname[size] = 0;
  381. if (slash[1])
  382. basename = slash + 1;
  383. else
  384. basename = conf_get_configname();
  385. } else
  386. basename = name;
  387. } else
  388. basename = conf_get_configname();
  389. sprintf(newname, "%s%s", dirname, basename);
  390. env = getenv("KCONFIG_OVERWRITECONFIG");
  391. if (!env || !*env) {
  392. sprintf(tmpname, "%s.tmpconfig.%d", dirname, (int)getpid());
  393. out = fopen(tmpname, "w");
  394. } else {
  395. *tmpname = 0;
  396. out = fopen(newname, "w");
  397. }
  398. if (!out)
  399. return 1;
  400. sym = sym_lookup("VERSION", 0);
  401. sym_calc_value(sym);
  402. time(&now);
  403. env = getenv("KCONFIG_NOTIMESTAMP");
  404. if (env && *env)
  405. use_timestamp = 0;
  406. fprintf(out, _("#\n"
  407. "# Automatically generated make config: don't edit\n"
  408. "%s%s"
  409. "#\n"),
  410. use_timestamp ? "# " : "",
  411. use_timestamp ? ctime(&now) : "");
  412. if (!conf_get_changed())
  413. sym_clear_all_valid();
  414. menu = rootmenu.list;
  415. while (menu) {
  416. sym = menu->sym;
  417. if (!sym) {
  418. if (!menu_is_visible(menu))
  419. goto next;
  420. str = menu_get_prompt(menu);
  421. fprintf(out, "\n"
  422. "#\n"
  423. "# %s\n"
  424. "#\n", str);
  425. } else if (!(sym->flags & SYMBOL_CHOICE)) {
  426. sym_calc_value(sym);
  427. if (!(sym->flags & SYMBOL_WRITE))
  428. goto next;
  429. sym->flags &= ~SYMBOL_WRITE;
  430. type = sym->type;
  431. if (type == S_TRISTATE) {
  432. sym_calc_value(modules_sym);
  433. if (modules_sym->curr.tri == no)
  434. type = S_BOOLEAN;
  435. }
  436. switch (type) {
  437. case S_BOOLEAN:
  438. case S_TRISTATE:
  439. switch (sym_get_tristate_value(sym)) {
  440. case no:
  441. fprintf(out, "# %s is not set\n", sym->name);
  442. break;
  443. case mod:
  444. fprintf(out, "%s=m\n", sym->name);
  445. break;
  446. case yes:
  447. fprintf(out, "%s=y\n", sym->name);
  448. break;
  449. }
  450. break;
  451. case S_STRING:
  452. str = sym_get_string_value(sym);
  453. fprintf(out, "%s=\"", sym->name);
  454. while (1) {
  455. l = strcspn(str, "\"\\");
  456. if (l) {
  457. fwrite(str, l, 1, out);
  458. str += l;
  459. }
  460. if (!*str)
  461. break;
  462. fprintf(out, "\\%c", *str++);
  463. }
  464. fputs("\"\n", out);
  465. break;
  466. case S_HEX:
  467. str = sym_get_string_value(sym);
  468. if (str[0] != '0' || (str[1] != 'x' && str[1] != 'X')) {
  469. fprintf(out, "%s=%s\n", sym->name, str);
  470. break;
  471. }
  472. case S_INT:
  473. str = sym_get_string_value(sym);
  474. fprintf(out, "%s=%s\n", sym->name, str);
  475. break;
  476. }
  477. }
  478. next:
  479. if (menu->list) {
  480. menu = menu->list;
  481. continue;
  482. }
  483. if (menu->next)
  484. menu = menu->next;
  485. else while ((menu = menu->parent)) {
  486. if (menu->next) {
  487. menu = menu->next;
  488. break;
  489. }
  490. }
  491. }
  492. fclose(out);
  493. if (*tmpname) {
  494. strcat(dirname, basename);
  495. strcat(dirname, ".old");
  496. rename(newname, dirname);
  497. if (rename(tmpname, newname))
  498. return 1;
  499. }
  500. printf(_("#\n"
  501. "# configuration written to %s\n"
  502. "#\n"), newname);
  503. sym_set_change_count(0);
  504. return 0;
  505. }
  506. int conf_split_config(void)
  507. {
  508. char *name, path[128];
  509. char *s, *d, c;
  510. struct symbol *sym;
  511. struct stat sb;
  512. int res, i, fd;
  513. name = getenv("KCONFIG_AUTOCONFIG");
  514. if (!name)
  515. name = "include/config/auto.conf";
  516. conf_read_simple(name, S_DEF_AUTO);
  517. if (chdir("include/config"))
  518. return 1;
  519. res = 0;
  520. for_all_symbols(i, sym) {
  521. sym_calc_value(sym);
  522. if ((sym->flags & SYMBOL_AUTO) || !sym->name)
  523. continue;
  524. if (sym->flags & SYMBOL_WRITE) {
  525. if (sym->flags & SYMBOL_DEF_AUTO) {
  526. /*
  527. * symbol has old and new value,
  528. * so compare them...
  529. */
  530. switch (sym->type) {
  531. case S_BOOLEAN:
  532. case S_TRISTATE:
  533. if (sym_get_tristate_value(sym) ==
  534. sym->def[S_DEF_AUTO].tri)
  535. continue;
  536. break;
  537. case S_STRING:
  538. case S_HEX:
  539. case S_INT:
  540. if (!strcmp(sym_get_string_value(sym),
  541. sym->def[S_DEF_AUTO].val))
  542. continue;
  543. break;
  544. default:
  545. break;
  546. }
  547. } else {
  548. /*
  549. * If there is no old value, only 'no' (unset)
  550. * is allowed as new value.
  551. */
  552. switch (sym->type) {
  553. case S_BOOLEAN:
  554. case S_TRISTATE:
  555. if (sym_get_tristate_value(sym) == no)
  556. continue;
  557. break;
  558. default:
  559. break;
  560. }
  561. }
  562. } else if (!(sym->flags & SYMBOL_DEF_AUTO))
  563. /* There is neither an old nor a new value. */
  564. continue;
  565. /* else
  566. * There is an old value, but no new value ('no' (unset)
  567. * isn't saved in auto.conf, so the old value is always
  568. * different from 'no').
  569. */
  570. /* Replace all '_' and append ".h" */
  571. s = sym->name;
  572. d = path;
  573. while ((c = *s++)) {
  574. c = tolower(c);
  575. *d++ = (c == '_') ? '/' : c;
  576. }
  577. strcpy(d, ".h");
  578. /* Assume directory path already exists. */
  579. fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
  580. if (fd == -1) {
  581. if (errno != ENOENT) {
  582. res = 1;
  583. break;
  584. }
  585. /*
  586. * Create directory components,
  587. * unless they exist already.
  588. */
  589. d = path;
  590. while ((d = strchr(d, '/'))) {
  591. *d = 0;
  592. if (stat(path, &sb) && mkdir(path, 0755)) {
  593. res = 1;
  594. goto out;
  595. }
  596. *d++ = '/';
  597. }
  598. /* Try it again. */
  599. fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
  600. if (fd == -1) {
  601. res = 1;
  602. break;
  603. }
  604. }
  605. close(fd);
  606. }
  607. out:
  608. if (chdir("../.."))
  609. return 1;
  610. return res;
  611. }
  612. int conf_write_autoconf(void)
  613. {
  614. struct symbol *sym;
  615. const char *str;
  616. char *name;
  617. FILE *out, *out_h;
  618. time_t now;
  619. int i, l;
  620. return 0;
  621. sym_clear_all_valid();
  622. file_write_dep("include/config/auto.conf.cmd");
  623. if (conf_split_config())
  624. return 1;
  625. out = fopen(".tmpconfig", "w");
  626. if (!out)
  627. return 1;
  628. out_h = fopen(".tmpconfig.h", "w");
  629. if (!out_h) {
  630. fclose(out);
  631. return 1;
  632. }
  633. sym = sym_lookup("VERSION", 0);
  634. sym_calc_value(sym);
  635. time(&now);
  636. fprintf(out, "#\n"
  637. "# Automatically generated make config: don't edit\n"
  638. "# %s"
  639. "#\n",
  640. ctime(&now));
  641. fprintf(out_h, "/*\n"
  642. " * Automatically generated C config: don't edit\n"
  643. " * %s"
  644. " */\n",
  645. ctime(&now));
  646. for_all_symbols(i, sym) {
  647. sym_calc_value(sym);
  648. if (!(sym->flags & SYMBOL_WRITE) || !sym->name)
  649. continue;
  650. switch (sym->type) {
  651. case S_BOOLEAN:
  652. case S_TRISTATE:
  653. switch (sym_get_tristate_value(sym)) {
  654. case no:
  655. break;
  656. case mod:
  657. fprintf(out, "%s=m\n", sym->name);
  658. fprintf(out_h, "#define %s_MODULE 1\n", sym->name);
  659. break;
  660. case yes:
  661. fprintf(out, "%s=y\n", sym->name);
  662. fprintf(out_h, "#define %s 1\n", sym->name);
  663. break;
  664. }
  665. break;
  666. case S_STRING:
  667. str = sym_get_string_value(sym);
  668. fprintf(out, "%s=\"", sym->name);
  669. fprintf(out_h, "#define %s \"", sym->name);
  670. while (1) {
  671. l = strcspn(str, "\"\\");
  672. if (l) {
  673. fwrite(str, l, 1, out);
  674. fwrite(str, l, 1, out_h);
  675. str += l;
  676. }
  677. if (!*str)
  678. break;
  679. fprintf(out, "\\%c", *str);
  680. fprintf(out_h, "\\%c", *str);
  681. str++;
  682. }
  683. fputs("\"\n", out);
  684. fputs("\"\n", out_h);
  685. break;
  686. case S_HEX:
  687. str = sym_get_string_value(sym);
  688. if (str[0] != '0' || (str[1] != 'x' && str[1] != 'X')) {
  689. fprintf(out, "%s=%s\n", sym->name, str);
  690. fprintf(out_h, "#define %s 0x%s\n", sym->name, str);
  691. break;
  692. }
  693. case S_INT:
  694. str = sym_get_string_value(sym);
  695. fprintf(out, "%s=%s\n", sym->name, str);
  696. fprintf(out_h, "#define %s %s\n", sym->name, str);
  697. break;
  698. default:
  699. break;
  700. }
  701. }
  702. fclose(out);
  703. fclose(out_h);
  704. name = getenv("KCONFIG_AUTOHEADER");
  705. if (!name)
  706. name = "include/linux/autoconf.h";
  707. if (rename(".tmpconfig.h", name))
  708. return 1;
  709. name = getenv("KCONFIG_AUTOCONFIG");
  710. if (!name)
  711. name = "include/config/auto.conf";
  712. /*
  713. * This must be the last step, kbuild has a dependency on auto.conf
  714. * and this marks the successful completion of the previous steps.
  715. */
  716. if (rename(".tmpconfig", name))
  717. return 1;
  718. return 0;
  719. }
  720. static int sym_change_count;
  721. static void (*conf_changed_callback)(void);
  722. void sym_set_change_count(int count)
  723. {
  724. int _sym_change_count = sym_change_count;
  725. sym_change_count = count;
  726. if (conf_changed_callback &&
  727. (bool)_sym_change_count != (bool)count)
  728. conf_changed_callback();
  729. }
  730. void sym_add_change_count(int count)
  731. {
  732. sym_set_change_count(count + sym_change_count);
  733. }
  734. bool conf_get_changed(void)
  735. {
  736. return sym_change_count;
  737. }
  738. void conf_set_changed_callback(void (*fn)(void))
  739. {
  740. conf_changed_callback = fn;
  741. }