diff options
Diffstat (limited to 'scripts/kconfig/confdata.c')
-rw-r--r-- | scripts/kconfig/confdata.c | 126 |
1 files changed, 72 insertions, 54 deletions
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index 515253fe46cf..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 @@ | |||
18 | static void conf_warning(const char *fmt, ...) | 19 | static void conf_warning(const char *fmt, ...) |
19 | __attribute__ ((format (printf, 1, 2))); | 20 | __attribute__ ((format (printf, 1, 2))); |
20 | 21 | ||
22 | static void conf_message(const char *fmt, ...) | ||
23 | __attribute__ ((format (printf, 1, 2))); | ||
24 | |||
21 | static const char *conf_filename; | 25 | static const char *conf_filename; |
22 | static int conf_lineno, conf_warnings, conf_unsaved; | 26 | static 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 | ||
41 | static 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 | |||
48 | static void (*conf_message_callback) (const char *fmt, va_list ap) = | ||
49 | conf_default_message_callback; | ||
50 | void conf_set_message_callback(void (*fn) (const char *fmt, va_list ap)) | ||
51 | { | ||
52 | conf_message_callback = fn; | ||
53 | } | ||
54 | |||
55 | static 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 | |||
37 | const char *conf_get_configname(void) | 64 | const 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 | } |
313 | setsym: | ||
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,9 +423,9 @@ 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, "\"\\"); |
@@ -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: |
@@ -541,7 +560,7 @@ int conf_write(const char *name) | |||
541 | struct menu *menu; | 560 | struct menu *menu; |
542 | const char *basename; | 561 | const char *basename; |
543 | const char *str; | 562 | const char *str; |
544 | char dirname[128], tmpname[128], newname[128]; | 563 | char dirname[PATH_MAX+1], tmpname[PATH_MAX+1], newname[PATH_MAX+1]; |
545 | enum symbol_type type; | 564 | enum symbol_type type; |
546 | time_t now; | 565 | time_t now; |
547 | int use_timestamp = 1; | 566 | int use_timestamp = 1; |
@@ -581,8 +600,6 @@ int conf_write(const char *name) | |||
581 | if (!out) | 600 | if (!out) |
582 | return 1; | 601 | return 1; |
583 | 602 | ||
584 | sym = sym_lookup("KERNELVERSION", 0); | ||
585 | sym_calc_value(sym); | ||
586 | time(&now); | 603 | time(&now); |
587 | env = getenv("KCONFIG_NOTIMESTAMP"); | 604 | env = getenv("KCONFIG_NOTIMESTAMP"); |
588 | if (env && *env) | 605 | if (env && *env) |
@@ -590,10 +607,10 @@ int conf_write(const char *name) | |||
590 | 607 | ||
591 | fprintf(out, _("#\n" | 608 | fprintf(out, _("#\n" |
592 | "# Automatically generated make config: don't edit\n" | 609 | "# Automatically generated make config: don't edit\n" |
593 | "# Linux kernel version: %s\n" | 610 | "# %s\n" |
594 | "%s%s" | 611 | "%s%s" |
595 | "#\n"), | 612 | "#\n"), |
596 | sym_get_string_value(sym), | 613 | rootmenu.prompt->text, |
597 | use_timestamp ? "# " : "", | 614 | use_timestamp ? "# " : "", |
598 | use_timestamp ? ctime(&now) : ""); | 615 | use_timestamp ? ctime(&now) : ""); |
599 | 616 | ||
@@ -650,9 +667,7 @@ next: | |||
650 | return 1; | 667 | return 1; |
651 | } | 668 | } |
652 | 669 | ||
653 | printf(_("#\n" | 670 | conf_message(_("configuration written to %s"), newname); |
654 | "# configuration written to %s\n" | ||
655 | "#\n"), newname); | ||
656 | 671 | ||
657 | sym_set_change_count(0); | 672 | sym_set_change_count(0); |
658 | 673 | ||
@@ -662,7 +677,7 @@ next: | |||
662 | static int conf_split_config(void) | 677 | static int conf_split_config(void) |
663 | { | 678 | { |
664 | const char *name; | 679 | const char *name; |
665 | char path[128]; | 680 | char path[PATH_MAX+1]; |
666 | char *s, *d, c; | 681 | char *s, *d, c; |
667 | struct symbol *sym; | 682 | struct symbol *sym; |
668 | struct stat sb; | 683 | struct stat sb; |
@@ -804,25 +819,23 @@ int conf_write_autoconf(void) | |||
804 | return 1; | 819 | return 1; |
805 | } | 820 | } |
806 | 821 | ||
807 | sym = sym_lookup("KERNELVERSION", 0); | ||
808 | sym_calc_value(sym); | ||
809 | time(&now); | 822 | time(&now); |
810 | fprintf(out, "#\n" | 823 | fprintf(out, "#\n" |
811 | "# Automatically generated make config: don't edit\n" | 824 | "# Automatically generated make config: don't edit\n" |
812 | "# Linux kernel version: %s\n" | 825 | "# %s\n" |
813 | "# %s" | 826 | "# %s" |
814 | "#\n", | 827 | "#\n", |
815 | sym_get_string_value(sym), ctime(&now)); | 828 | rootmenu.prompt->text, ctime(&now)); |
816 | fprintf(tristate, "#\n" | 829 | fprintf(tristate, "#\n" |
817 | "# Automatically generated - do not edit\n" | 830 | "# Automatically generated - do not edit\n" |
818 | "\n"); | 831 | "\n"); |
819 | fprintf(out_h, "/*\n" | 832 | fprintf(out_h, "/*\n" |
820 | " * Automatically generated C config: don't edit\n" | 833 | " * Automatically generated C config: don't edit\n" |
821 | " * Linux kernel version: %s\n" | 834 | " * %s\n" |
822 | " * %s" | 835 | " * %s" |
823 | " */\n" | 836 | " */\n" |
824 | "#define AUTOCONF_INCLUDED\n", | 837 | "#define AUTOCONF_INCLUDED\n", |
825 | sym_get_string_value(sym), ctime(&now)); | 838 | rootmenu.prompt->text, ctime(&now)); |
826 | 839 | ||
827 | for_all_symbols(i, sym) { | 840 | for_all_symbols(i, sym) { |
828 | sym_calc_value(sym); | 841 | sym_calc_value(sym); |
@@ -840,14 +853,17 @@ int conf_write_autoconf(void) | |||
840 | case no: | 853 | case no: |
841 | break; | 854 | break; |
842 | case mod: | 855 | case mod: |
843 | fprintf(tristate, "CONFIG_%s=M\n", sym->name); | 856 | fprintf(tristate, "%s%s=M\n", |
844 | 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); | ||
845 | break; | 860 | break; |
846 | case yes: | 861 | case yes: |
847 | if (sym->type == S_TRISTATE) | 862 | if (sym->type == S_TRISTATE) |
848 | fprintf(tristate, "CONFIG_%s=Y\n", | 863 | fprintf(tristate,"%s%s=Y\n", |
849 | sym->name); | 864 | CONFIG_, sym->name); |
850 | fprintf(out_h, "#define CONFIG_%s 1\n", sym->name); | 865 | fprintf(out_h, "#define %s%s 1\n", |
866 | CONFIG_, sym->name); | ||
851 | break; | 867 | break; |
852 | } | 868 | } |
853 | break; | 869 | break; |
@@ -857,12 +873,14 @@ int conf_write_autoconf(void) | |||
857 | case S_HEX: | 873 | case S_HEX: |
858 | str = sym_get_string_value(sym); | 874 | str = sym_get_string_value(sym); |
859 | if (str[0] != '0' || (str[1] != 'x' && str[1] != 'X')) { | 875 | if (str[0] != '0' || (str[1] != 'x' && str[1] != 'X')) { |
860 | 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); | ||
861 | break; | 878 | break; |
862 | } | 879 | } |
863 | case S_INT: | 880 | case S_INT: |
864 | str = sym_get_string_value(sym); | 881 | str = sym_get_string_value(sym); |
865 | 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); | ||
866 | break; | 884 | break; |
867 | default: | 885 | default: |
868 | break; | 886 | break; |