aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/kconfig/confdata.c
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/kconfig/confdata.c')
-rw-r--r--scripts/kconfig/confdata.c241
1 files changed, 146 insertions, 95 deletions
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index f81f263b64f2..9df80114b47b 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -5,6 +5,7 @@
5 5
6#include <sys/stat.h> 6#include <sys/stat.h>
7#include <ctype.h> 7#include <ctype.h>
8#include <errno.h>
8#include <fcntl.h> 9#include <fcntl.h>
9#include <stdio.h> 10#include <stdio.h>
10#include <stdlib.h> 11#include <stdlib.h>
@@ -18,6 +19,9 @@
18static void conf_warning(const char *fmt, ...) 19static void conf_warning(const char *fmt, ...)
19 __attribute__ ((format (printf, 1, 2))); 20 __attribute__ ((format (printf, 1, 2)));
20 21
22static void conf_message(const char *fmt, ...)
23 __attribute__ ((format (printf, 1, 2)));
24
21static const char *conf_filename; 25static const char *conf_filename;
22static int conf_lineno, conf_warnings, conf_unsaved; 26static int conf_lineno, conf_warnings, conf_unsaved;
23 27
@@ -34,6 +38,29 @@ static void conf_warning(const char *fmt, ...)
34 conf_warnings++; 38 conf_warnings++;
35} 39}
36 40
41static void conf_default_message_callback(const char *fmt, va_list ap)
42{
43 printf("#\n# ");
44 vprintf(fmt, ap);
45 printf("\n#\n");
46}
47
48static void (*conf_message_callback) (const char *fmt, va_list ap) =
49 conf_default_message_callback;
50void conf_set_message_callback(void (*fn) (const char *fmt, va_list ap))
51{
52 conf_message_callback = fn;
53}
54
55static void conf_message(const char *fmt, ...)
56{
57 va_list ap;
58
59 va_start(ap, fmt);
60 if (conf_message_callback)
61 conf_message_callback(fmt, ap);
62}
63
37const char *conf_get_configname(void) 64const char *conf_get_configname(void)
38{ 65{
39 char *name = getenv("KCONFIG_CONFIG"); 66 char *name = getenv("KCONFIG_CONFIG");
@@ -183,9 +210,8 @@ int conf_read_simple(const char *name, int def)
183 name = conf_expand_value(prop->expr->left.sym->name); 210 name = conf_expand_value(prop->expr->left.sym->name);
184 in = zconf_fopen(name); 211 in = zconf_fopen(name);
185 if (in) { 212 if (in) {
186 printf(_("#\n" 213 conf_message(_("using defaults found in %s"),
187 "# using defaults found in %s\n" 214 name);
188 "#\n"), name);
189 goto load; 215 goto load;
190 } 216 }
191 } 217 }
@@ -220,24 +246,23 @@ load:
220 while (fgets(line, sizeof(line), in)) { 246 while (fgets(line, sizeof(line), in)) {
221 conf_lineno++; 247 conf_lineno++;
222 sym = NULL; 248 sym = NULL;
223 switch (line[0]) { 249 if (line[0] == '#') {
224 case '#': 250 if (memcmp(line + 2, CONFIG_, strlen(CONFIG_)))
225 if (memcmp(line + 2, "CONFIG_", 7))
226 continue; 251 continue;
227 p = strchr(line + 9, ' '); 252 p = strchr(line + 2 + strlen(CONFIG_), ' ');
228 if (!p) 253 if (!p)
229 continue; 254 continue;
230 *p++ = 0; 255 *p++ = 0;
231 if (strncmp(p, "is not set", 10)) 256 if (strncmp(p, "is not set", 10))
232 continue; 257 continue;
233 if (def == S_DEF_USER) { 258 if (def == S_DEF_USER) {
234 sym = sym_find(line + 9); 259 sym = sym_find(line + 2 + strlen(CONFIG_));
235 if (!sym) { 260 if (!sym) {
236 sym_add_change_count(1); 261 sym_add_change_count(1);
237 break; 262 goto setsym;
238 } 263 }
239 } else { 264 } else {
240 sym = sym_lookup(line + 9, 0); 265 sym = sym_lookup(line + 2 + strlen(CONFIG_), 0);
241 if (sym->type == S_UNKNOWN) 266 if (sym->type == S_UNKNOWN)
242 sym->type = S_BOOLEAN; 267 sym->type = S_BOOLEAN;
243 } 268 }
@@ -253,13 +278,8 @@ load:
253 default: 278 default:
254 ; 279 ;
255 } 280 }
256 break; 281 } else if (memcmp(line, CONFIG_, strlen(CONFIG_)) == 0) {
257 case 'C': 282 p = strchr(line + strlen(CONFIG_), '=');
258 if (memcmp(line, "CONFIG_", 7)) {
259 conf_warning("unexpected data");
260 continue;
261 }
262 p = strchr(line + 7, '=');
263 if (!p) 283 if (!p)
264 continue; 284 continue;
265 *p++ = 0; 285 *p++ = 0;
@@ -270,13 +290,13 @@ load:
270 *p2 = 0; 290 *p2 = 0;
271 } 291 }
272 if (def == S_DEF_USER) { 292 if (def == S_DEF_USER) {
273 sym = sym_find(line + 7); 293 sym = sym_find(line + strlen(CONFIG_));
274 if (!sym) { 294 if (!sym) {
275 sym_add_change_count(1); 295 sym_add_change_count(1);
276 break; 296 goto setsym;
277 } 297 }
278 } else { 298 } else {
279 sym = sym_lookup(line + 7, 0); 299 sym = sym_lookup(line + strlen(CONFIG_), 0);
280 if (sym->type == S_UNKNOWN) 300 if (sym->type == S_UNKNOWN)
281 sym->type = S_OTHER; 301 sym->type = S_OTHER;
282 } 302 }
@@ -285,14 +305,12 @@ load:
285 } 305 }
286 if (conf_set_sym_val(sym, def, def_flags, p)) 306 if (conf_set_sym_val(sym, def, def_flags, p))
287 continue; 307 continue;
288 break; 308 } else {
289 case '\r': 309 if (line[0] != '\r' && line[0] != '\n')
290 case '\n': 310 conf_warning("unexpected data");
291 break;
292 default:
293 conf_warning("unexpected data");
294 continue; 311 continue;
295 } 312 }
313setsym:
296 if (sym && sym_is_choice_value(sym)) { 314 if (sym && sym_is_choice_value(sym)) {
297 struct symbol *cs = prop_get_symbol(sym_get_choice_prop(sym)); 315 struct symbol *cs = prop_get_symbol(sym_get_choice_prop(sym));
298 switch (sym->def[def].tri) { 316 switch (sym->def[def].tri) {
@@ -405,14 +423,14 @@ static void conf_write_string(bool headerfile, const char *name,
405{ 423{
406 int l; 424 int l;
407 if (headerfile) 425 if (headerfile)
408 fprintf(out, "#define CONFIG_%s \"", name); 426 fprintf(out, "#define %s%s \"", CONFIG_, name);
409 else 427 else
410 fprintf(out, "CONFIG_%s=\"", name); 428 fprintf(out, "%s%s=\"", CONFIG_, name);
411 429
412 while (1) { 430 while (1) {
413 l = strcspn(str, "\"\\"); 431 l = strcspn(str, "\"\\");
414 if (l) { 432 if (l) {
415 fwrite(str, l, 1, out); 433 xfwrite(str, l, 1, out);
416 str += l; 434 str += l;
417 } 435 }
418 if (!*str) 436 if (!*str)
@@ -433,13 +451,14 @@ static void conf_write_symbol(struct symbol *sym, enum symbol_type type,
433 switch (sym_get_tristate_value(sym)) { 451 switch (sym_get_tristate_value(sym)) {
434 case no: 452 case no:
435 if (write_no) 453 if (write_no)
436 fprintf(out, "# CONFIG_%s is not set\n", sym->name); 454 fprintf(out, "# %s%s is not set\n",
455 CONFIG_, sym->name);
437 break; 456 break;
438 case mod: 457 case mod:
439 fprintf(out, "CONFIG_%s=m\n", sym->name); 458 fprintf(out, "%s%s=m\n", CONFIG_, sym->name);
440 break; 459 break;
441 case yes: 460 case yes:
442 fprintf(out, "CONFIG_%s=y\n", sym->name); 461 fprintf(out, "%s%s=y\n", CONFIG_, sym->name);
443 break; 462 break;
444 } 463 }
445 break; 464 break;
@@ -449,7 +468,7 @@ static void conf_write_symbol(struct symbol *sym, enum symbol_type type,
449 case S_HEX: 468 case S_HEX:
450 case S_INT: 469 case S_INT:
451 str = sym_get_string_value(sym); 470 str = sym_get_string_value(sym);
452 fprintf(out, "CONFIG_%s=%s\n", sym->name, str); 471 fprintf(out, "%s%s=%s\n", CONFIG_, sym->name, str);
453 break; 472 break;
454 case S_OTHER: 473 case S_OTHER:
455 case S_UNKNOWN: 474 case S_UNKNOWN:
@@ -497,7 +516,9 @@ int conf_write_defconfig(const char *filename)
497 /* 516 /*
498 * If symbol is a choice value and equals to the 517 * If symbol is a choice value and equals to the
499 * default for a choice - skip. 518 * default for a choice - skip.
500 * But only if value equal to "y". 519 * But only if value is bool and equal to "y" and
520 * choice is not "optional".
521 * (If choice is "optional" then all values can be "n")
501 */ 522 */
502 if (sym_is_choice_value(sym)) { 523 if (sym_is_choice_value(sym)) {
503 struct symbol *cs; 524 struct symbol *cs;
@@ -505,10 +526,9 @@ int conf_write_defconfig(const char *filename)
505 526
506 cs = prop_get_symbol(sym_get_choice_prop(sym)); 527 cs = prop_get_symbol(sym_get_choice_prop(sym));
507 ds = sym_choice_default(cs); 528 ds = sym_choice_default(cs);
508 if (sym == ds) { 529 if (!sym_is_optional(cs) && sym == ds) {
509 if ((sym->type == S_BOOLEAN || 530 if ((sym->type == S_BOOLEAN) &&
510 sym->type == S_TRISTATE) && 531 sym_get_tristate_value(sym) == yes)
511 sym_get_tristate_value(sym) == yes)
512 goto next_menu; 532 goto next_menu;
513 } 533 }
514 } 534 }
@@ -540,7 +560,7 @@ int conf_write(const char *name)
540 struct menu *menu; 560 struct menu *menu;
541 const char *basename; 561 const char *basename;
542 const char *str; 562 const char *str;
543 char dirname[128], tmpname[128], newname[128]; 563 char dirname[PATH_MAX+1], tmpname[PATH_MAX+1], newname[PATH_MAX+1];
544 enum symbol_type type; 564 enum symbol_type type;
545 time_t now; 565 time_t now;
546 int use_timestamp = 1; 566 int use_timestamp = 1;
@@ -580,8 +600,6 @@ int conf_write(const char *name)
580 if (!out) 600 if (!out)
581 return 1; 601 return 1;
582 602
583 sym = sym_lookup("KERNELVERSION", 0);
584 sym_calc_value(sym);
585 time(&now); 603 time(&now);
586 env = getenv("KCONFIG_NOTIMESTAMP"); 604 env = getenv("KCONFIG_NOTIMESTAMP");
587 if (env && *env) 605 if (env && *env)
@@ -589,10 +607,10 @@ int conf_write(const char *name)
589 607
590 fprintf(out, _("#\n" 608 fprintf(out, _("#\n"
591 "# Automatically generated make config: don't edit\n" 609 "# Automatically generated make config: don't edit\n"
592 "# Linux kernel version: %s\n" 610 "# %s\n"
593 "%s%s" 611 "%s%s"
594 "#\n"), 612 "#\n"),
595 sym_get_string_value(sym), 613 rootmenu.prompt->text,
596 use_timestamp ? "# " : "", 614 use_timestamp ? "# " : "",
597 use_timestamp ? ctime(&now) : ""); 615 use_timestamp ? ctime(&now) : "");
598 616
@@ -649,9 +667,7 @@ next:
649 return 1; 667 return 1;
650 } 668 }
651 669
652 printf(_("#\n" 670 conf_message(_("configuration written to %s"), newname);
653 "# configuration written to %s\n"
654 "#\n"), newname);
655 671
656 sym_set_change_count(0); 672 sym_set_change_count(0);
657 673
@@ -661,7 +677,7 @@ next:
661static int conf_split_config(void) 677static int conf_split_config(void)
662{ 678{
663 const char *name; 679 const char *name;
664 char path[128]; 680 char path[PATH_MAX+1];
665 char *s, *d, c; 681 char *s, *d, c;
666 struct symbol *sym; 682 struct symbol *sym;
667 struct stat sb; 683 struct stat sb;
@@ -803,25 +819,23 @@ int conf_write_autoconf(void)
803 return 1; 819 return 1;
804 } 820 }
805 821
806 sym = sym_lookup("KERNELVERSION", 0);
807 sym_calc_value(sym);
808 time(&now); 822 time(&now);
809 fprintf(out, "#\n" 823 fprintf(out, "#\n"
810 "# Automatically generated make config: don't edit\n" 824 "# Automatically generated make config: don't edit\n"
811 "# Linux kernel version: %s\n" 825 "# %s\n"
812 "# %s" 826 "# %s"
813 "#\n", 827 "#\n",
814 sym_get_string_value(sym), ctime(&now)); 828 rootmenu.prompt->text, ctime(&now));
815 fprintf(tristate, "#\n" 829 fprintf(tristate, "#\n"
816 "# Automatically generated - do not edit\n" 830 "# Automatically generated - do not edit\n"
817 "\n"); 831 "\n");
818 fprintf(out_h, "/*\n" 832 fprintf(out_h, "/*\n"
819 " * Automatically generated C config: don't edit\n" 833 " * Automatically generated C config: don't edit\n"
820 " * Linux kernel version: %s\n" 834 " * %s\n"
821 " * %s" 835 " * %s"
822 " */\n" 836 " */\n"
823 "#define AUTOCONF_INCLUDED\n", 837 "#define AUTOCONF_INCLUDED\n",
824 sym_get_string_value(sym), ctime(&now)); 838 rootmenu.prompt->text, ctime(&now));
825 839
826 for_all_symbols(i, sym) { 840 for_all_symbols(i, sym) {
827 sym_calc_value(sym); 841 sym_calc_value(sym);
@@ -839,14 +853,17 @@ int conf_write_autoconf(void)
839 case no: 853 case no:
840 break; 854 break;
841 case mod: 855 case mod:
842 fprintf(tristate, "CONFIG_%s=M\n", sym->name); 856 fprintf(tristate, "%s%s=M\n",
843 fprintf(out_h, "#define CONFIG_%s_MODULE 1\n", sym->name); 857 CONFIG_, sym->name);
858 fprintf(out_h, "#define %s%s_MODULE 1\n",
859 CONFIG_, sym->name);
844 break; 860 break;
845 case yes: 861 case yes:
846 if (sym->type == S_TRISTATE) 862 if (sym->type == S_TRISTATE)
847 fprintf(tristate, "CONFIG_%s=Y\n", 863 fprintf(tristate,"%s%s=Y\n",
848 sym->name); 864 CONFIG_, sym->name);
849 fprintf(out_h, "#define CONFIG_%s 1\n", sym->name); 865 fprintf(out_h, "#define %s%s 1\n",
866 CONFIG_, sym->name);
850 break; 867 break;
851 } 868 }
852 break; 869 break;
@@ -856,12 +873,14 @@ int conf_write_autoconf(void)
856 case S_HEX: 873 case S_HEX:
857 str = sym_get_string_value(sym); 874 str = sym_get_string_value(sym);
858 if (str[0] != '0' || (str[1] != 'x' && str[1] != 'X')) { 875 if (str[0] != '0' || (str[1] != 'x' && str[1] != 'X')) {
859 fprintf(out_h, "#define CONFIG_%s 0x%s\n", sym->name, str); 876 fprintf(out_h, "#define %s%s 0x%s\n",
877 CONFIG_, sym->name, str);
860 break; 878 break;
861 } 879 }
862 case S_INT: 880 case S_INT:
863 str = sym_get_string_value(sym); 881 str = sym_get_string_value(sym);
864 fprintf(out_h, "#define CONFIG_%s %s\n", sym->name, str); 882 fprintf(out_h, "#define %s%s %s\n",
883 CONFIG_, sym->name, str);
865 break; 884 break;
866 default: 885 default:
867 break; 886 break;
@@ -919,13 +938,73 @@ void conf_set_changed_callback(void (*fn)(void))
919 conf_changed_callback = fn; 938 conf_changed_callback = fn;
920} 939}
921 940
941static void randomize_choice_values(struct symbol *csym)
942{
943 struct property *prop;
944 struct symbol *sym;
945 struct expr *e;
946 int cnt, def;
922 947
923void conf_set_all_new_symbols(enum conf_def_mode mode) 948 /*
949 * If choice is mod then we may have more items slected
950 * and if no then no-one.
951 * In both cases stop.
952 */
953 if (csym->curr.tri != yes)
954 return;
955
956 prop = sym_get_choice_prop(csym);
957
958 /* count entries in choice block */
959 cnt = 0;
960 expr_list_for_each_sym(prop->expr, e, sym)
961 cnt++;
962
963 /*
964 * find a random value and set it to yes,
965 * set the rest to no so we have only one set
966 */
967 def = (rand() % cnt);
968
969 cnt = 0;
970 expr_list_for_each_sym(prop->expr, e, sym) {
971 if (def == cnt++) {
972 sym->def[S_DEF_USER].tri = yes;
973 csym->def[S_DEF_USER].val = sym;
974 }
975 else {
976 sym->def[S_DEF_USER].tri = no;
977 }
978 }
979 csym->flags |= SYMBOL_DEF_USER;
980 /* clear VALID to get value calculated */
981 csym->flags &= ~(SYMBOL_VALID);
982}
983
984static void set_all_choice_values(struct symbol *csym)
924{ 985{
925 struct symbol *sym, *csym;
926 struct property *prop; 986 struct property *prop;
987 struct symbol *sym;
927 struct expr *e; 988 struct expr *e;
928 int i, cnt, def; 989
990 prop = sym_get_choice_prop(csym);
991
992 /*
993 * Set all non-assinged choice values to no
994 */
995 expr_list_for_each_sym(prop->expr, e, sym) {
996 if (!sym_has_value(sym))
997 sym->def[S_DEF_USER].tri = no;
998 }
999 csym->flags |= SYMBOL_DEF_USER;
1000 /* clear VALID to get value calculated */
1001 csym->flags &= ~(SYMBOL_VALID);
1002}
1003
1004void conf_set_all_new_symbols(enum conf_def_mode mode)
1005{
1006 struct symbol *sym, *csym;
1007 int i, cnt;
929 1008
930 for_all_symbols(i, sym) { 1009 for_all_symbols(i, sym) {
931 if (sym_has_value(sym)) 1010 if (sym_has_value(sym))
@@ -961,8 +1040,6 @@ void conf_set_all_new_symbols(enum conf_def_mode mode)
961 1040
962 sym_clear_all_valid(); 1041 sym_clear_all_valid();
963 1042
964 if (mode != def_random)
965 return;
966 /* 1043 /*
967 * We have different type of choice blocks. 1044 * We have different type of choice blocks.
968 * If curr.tri equal to mod then we can select several 1045 * If curr.tri equal to mod then we can select several
@@ -977,35 +1054,9 @@ void conf_set_all_new_symbols(enum conf_def_mode mode)
977 continue; 1054 continue;
978 1055
979 sym_calc_value(csym); 1056 sym_calc_value(csym);
980 1057 if (mode == def_random)
981 if (csym->curr.tri != yes) 1058 randomize_choice_values(csym);
982 continue; 1059 else
983 1060 set_all_choice_values(csym);
984 prop = sym_get_choice_prop(csym);
985
986 /* count entries in choice block */
987 cnt = 0;
988 expr_list_for_each_sym(prop->expr, e, sym)
989 cnt++;
990
991 /*
992 * find a random value and set it to yes,
993 * set the rest to no so we have only one set
994 */
995 def = (rand() % cnt);
996
997 cnt = 0;
998 expr_list_for_each_sym(prop->expr, e, sym) {
999 if (def == cnt++) {
1000 sym->def[S_DEF_USER].tri = yes;
1001 csym->def[S_DEF_USER].val = sym;
1002 }
1003 else {
1004 sym->def[S_DEF_USER].tri = no;
1005 }
1006 }
1007 csym->flags |= SYMBOL_DEF_USER;
1008 /* clear VALID to get value calculated */
1009 csym->flags &= ~(SYMBOL_VALID);
1010 } 1061 }
1011} 1062}