diff options
Diffstat (limited to 'scripts/kconfig/confdata.c')
| -rw-r--r-- | scripts/kconfig/confdata.c | 221 |
1 files changed, 152 insertions, 69 deletions
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index c4dec80cfd8e..f81f263b64f2 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c | |||
| @@ -170,8 +170,11 @@ int conf_read_simple(const char *name, int def) | |||
| 170 | if (in) | 170 | if (in) |
| 171 | goto load; | 171 | goto load; |
| 172 | sym_add_change_count(1); | 172 | sym_add_change_count(1); |
| 173 | if (!sym_defconfig_list) | 173 | if (!sym_defconfig_list) { |
| 174 | if (modules_sym) | ||
| 175 | sym_calc_value(modules_sym); | ||
| 174 | return 1; | 176 | return 1; |
| 177 | } | ||
| 175 | 178 | ||
| 176 | for_all_defaults(sym_defconfig_list, prop) { | 179 | for_all_defaults(sym_defconfig_list, prop) { |
| 177 | if (expr_calc_value(prop->visible.expr) == no || | 180 | if (expr_calc_value(prop->visible.expr) == no || |
| @@ -396,15 +399,149 @@ int conf_read(const char *name) | |||
| 396 | return 0; | 399 | return 0; |
| 397 | } | 400 | } |
| 398 | 401 | ||
| 402 | /* Write a S_STRING */ | ||
| 403 | static void conf_write_string(bool headerfile, const char *name, | ||
| 404 | const char *str, FILE *out) | ||
| 405 | { | ||
| 406 | int l; | ||
| 407 | if (headerfile) | ||
| 408 | fprintf(out, "#define CONFIG_%s \"", name); | ||
| 409 | else | ||
| 410 | fprintf(out, "CONFIG_%s=\"", name); | ||
| 411 | |||
| 412 | while (1) { | ||
| 413 | l = strcspn(str, "\"\\"); | ||
| 414 | if (l) { | ||
| 415 | fwrite(str, l, 1, out); | ||
| 416 | str += l; | ||
| 417 | } | ||
| 418 | if (!*str) | ||
| 419 | break; | ||
| 420 | fprintf(out, "\\%c", *str++); | ||
| 421 | } | ||
| 422 | fputs("\"\n", out); | ||
| 423 | } | ||
| 424 | |||
| 425 | static void conf_write_symbol(struct symbol *sym, enum symbol_type type, | ||
| 426 | FILE *out, bool write_no) | ||
| 427 | { | ||
| 428 | const char *str; | ||
| 429 | |||
| 430 | switch (type) { | ||
| 431 | case S_BOOLEAN: | ||
| 432 | case S_TRISTATE: | ||
| 433 | switch (sym_get_tristate_value(sym)) { | ||
| 434 | case no: | ||
| 435 | if (write_no) | ||
| 436 | fprintf(out, "# CONFIG_%s is not set\n", sym->name); | ||
| 437 | break; | ||
| 438 | case mod: | ||
| 439 | fprintf(out, "CONFIG_%s=m\n", sym->name); | ||
| 440 | break; | ||
| 441 | case yes: | ||
| 442 | fprintf(out, "CONFIG_%s=y\n", sym->name); | ||
| 443 | break; | ||
| 444 | } | ||
| 445 | break; | ||
| 446 | case S_STRING: | ||
| 447 | conf_write_string(false, sym->name, sym_get_string_value(sym), out); | ||
| 448 | break; | ||
| 449 | case S_HEX: | ||
| 450 | case S_INT: | ||
| 451 | str = sym_get_string_value(sym); | ||
| 452 | fprintf(out, "CONFIG_%s=%s\n", sym->name, str); | ||
| 453 | break; | ||
| 454 | case S_OTHER: | ||
| 455 | case S_UNKNOWN: | ||
| 456 | break; | ||
| 457 | } | ||
| 458 | } | ||
| 459 | |||
| 460 | /* | ||
| 461 | * Write out a minimal config. | ||
| 462 | * All values that has default values are skipped as this is redundant. | ||
| 463 | */ | ||
| 464 | int conf_write_defconfig(const char *filename) | ||
| 465 | { | ||
| 466 | struct symbol *sym; | ||
| 467 | struct menu *menu; | ||
| 468 | FILE *out; | ||
| 469 | |||
| 470 | out = fopen(filename, "w"); | ||
| 471 | if (!out) | ||
| 472 | return 1; | ||
| 473 | |||
| 474 | sym_clear_all_valid(); | ||
| 475 | |||
| 476 | /* Traverse all menus to find all relevant symbols */ | ||
| 477 | menu = rootmenu.list; | ||
| 478 | |||
| 479 | while (menu != NULL) | ||
| 480 | { | ||
| 481 | sym = menu->sym; | ||
| 482 | if (sym == NULL) { | ||
| 483 | if (!menu_is_visible(menu)) | ||
| 484 | goto next_menu; | ||
| 485 | } else if (!sym_is_choice(sym)) { | ||
| 486 | sym_calc_value(sym); | ||
| 487 | if (!(sym->flags & SYMBOL_WRITE)) | ||
| 488 | goto next_menu; | ||
| 489 | sym->flags &= ~SYMBOL_WRITE; | ||
| 490 | /* If we cannot change the symbol - skip */ | ||
| 491 | if (!sym_is_changable(sym)) | ||
| 492 | goto next_menu; | ||
| 493 | /* If symbol equals to default value - skip */ | ||
| 494 | if (strcmp(sym_get_string_value(sym), sym_get_string_default(sym)) == 0) | ||
| 495 | goto next_menu; | ||
| 496 | |||
| 497 | /* | ||
| 498 | * If symbol is a choice value and equals to the | ||
| 499 | * default for a choice - skip. | ||
| 500 | * But only if value equal to "y". | ||
| 501 | */ | ||
| 502 | if (sym_is_choice_value(sym)) { | ||
| 503 | struct symbol *cs; | ||
| 504 | struct symbol *ds; | ||
| 505 | |||
| 506 | cs = prop_get_symbol(sym_get_choice_prop(sym)); | ||
| 507 | ds = sym_choice_default(cs); | ||
| 508 | if (sym == ds) { | ||
| 509 | if ((sym->type == S_BOOLEAN || | ||
| 510 | sym->type == S_TRISTATE) && | ||
| 511 | sym_get_tristate_value(sym) == yes) | ||
| 512 | goto next_menu; | ||
| 513 | } | ||
| 514 | } | ||
| 515 | conf_write_symbol(sym, sym->type, out, true); | ||
| 516 | } | ||
| 517 | next_menu: | ||
| 518 | if (menu->list != NULL) { | ||
| 519 | menu = menu->list; | ||
| 520 | } | ||
| 521 | else if (menu->next != NULL) { | ||
| 522 | menu = menu->next; | ||
| 523 | } else { | ||
| 524 | while ((menu = menu->parent)) { | ||
| 525 | if (menu->next != NULL) { | ||
| 526 | menu = menu->next; | ||
| 527 | break; | ||
| 528 | } | ||
| 529 | } | ||
| 530 | } | ||
| 531 | } | ||
| 532 | fclose(out); | ||
| 533 | return 0; | ||
| 534 | } | ||
| 535 | |||
| 399 | int conf_write(const char *name) | 536 | int conf_write(const char *name) |
| 400 | { | 537 | { |
| 401 | FILE *out; | 538 | FILE *out; |
| 402 | struct symbol *sym; | 539 | struct symbol *sym; |
| 403 | struct menu *menu; | 540 | struct menu *menu; |
| 404 | const char *basename; | 541 | const char *basename; |
| 405 | char dirname[128], tmpname[128], newname[128]; | ||
| 406 | int type, l; | ||
| 407 | const char *str; | 542 | const char *str; |
| 543 | char dirname[128], tmpname[128], newname[128]; | ||
| 544 | enum symbol_type type; | ||
| 408 | time_t now; | 545 | time_t now; |
| 409 | int use_timestamp = 1; | 546 | int use_timestamp = 1; |
| 410 | char *env; | 547 | char *env; |
| @@ -484,50 +621,11 @@ int conf_write(const char *name) | |||
| 484 | if (modules_sym->curr.tri == no) | 621 | if (modules_sym->curr.tri == no) |
| 485 | type = S_BOOLEAN; | 622 | type = S_BOOLEAN; |
| 486 | } | 623 | } |
| 487 | switch (type) { | 624 | /* Write config symbol to file */ |
| 488 | case S_BOOLEAN: | 625 | conf_write_symbol(sym, type, out, true); |
| 489 | case S_TRISTATE: | ||
| 490 | switch (sym_get_tristate_value(sym)) { | ||
| 491 | case no: | ||
| 492 | fprintf(out, "# CONFIG_%s is not set\n", sym->name); | ||
| 493 | break; | ||
| 494 | case mod: | ||
| 495 | fprintf(out, "CONFIG_%s=m\n", sym->name); | ||
| 496 | break; | ||
| 497 | case yes: | ||
| 498 | fprintf(out, "CONFIG_%s=y\n", sym->name); | ||
| 499 | break; | ||
| 500 | } | ||
| 501 | break; | ||
| 502 | case S_STRING: | ||
| 503 | str = sym_get_string_value(sym); | ||
| 504 | fprintf(out, "CONFIG_%s=\"", sym->name); | ||
| 505 | while (1) { | ||
| 506 | l = strcspn(str, "\"\\"); | ||
| 507 | if (l) { | ||
| 508 | fwrite(str, l, 1, out); | ||
| 509 | str += l; | ||
| 510 | } | ||
| 511 | if (!*str) | ||
| 512 | break; | ||
| 513 | fprintf(out, "\\%c", *str++); | ||
| 514 | } | ||
| 515 | fputs("\"\n", out); | ||
| 516 | break; | ||
| 517 | case S_HEX: | ||
| 518 | str = sym_get_string_value(sym); | ||
| 519 | if (str[0] != '0' || (str[1] != 'x' && str[1] != 'X')) { | ||
| 520 | fprintf(out, "CONFIG_%s=%s\n", sym->name, str); | ||
| 521 | break; | ||
| 522 | } | ||
| 523 | case S_INT: | ||
| 524 | str = sym_get_string_value(sym); | ||
| 525 | fprintf(out, "CONFIG_%s=%s\n", sym->name, str); | ||
| 526 | break; | ||
| 527 | } | ||
| 528 | } | 626 | } |
| 529 | 627 | ||
| 530 | next: | 628 | next: |
| 531 | if (menu->list) { | 629 | if (menu->list) { |
| 532 | menu = menu->list; | 630 | menu = menu->list; |
| 533 | continue; | 631 | continue; |
| @@ -679,7 +777,7 @@ int conf_write_autoconf(void) | |||
| 679 | const char *name; | 777 | const char *name; |
| 680 | FILE *out, *tristate, *out_h; | 778 | FILE *out, *tristate, *out_h; |
| 681 | time_t now; | 779 | time_t now; |
| 682 | int i, l; | 780 | int i; |
| 683 | 781 | ||
| 684 | sym_clear_all_valid(); | 782 | sym_clear_all_valid(); |
| 685 | 783 | ||
| @@ -729,6 +827,11 @@ int conf_write_autoconf(void) | |||
| 729 | sym_calc_value(sym); | 827 | sym_calc_value(sym); |
| 730 | if (!(sym->flags & SYMBOL_WRITE) || !sym->name) | 828 | if (!(sym->flags & SYMBOL_WRITE) || !sym->name) |
| 731 | continue; | 829 | continue; |
| 830 | |||
| 831 | /* write symbol to config file */ | ||
| 832 | conf_write_symbol(sym, sym->type, out, false); | ||
| 833 | |||
| 834 | /* update autoconf and tristate files */ | ||
| 732 | switch (sym->type) { | 835 | switch (sym->type) { |
| 733 | case S_BOOLEAN: | 836 | case S_BOOLEAN: |
| 734 | case S_TRISTATE: | 837 | case S_TRISTATE: |
| @@ -736,12 +839,10 @@ int conf_write_autoconf(void) | |||
| 736 | case no: | 839 | case no: |
| 737 | break; | 840 | break; |
| 738 | case mod: | 841 | case mod: |
| 739 | fprintf(out, "CONFIG_%s=m\n", sym->name); | ||
| 740 | fprintf(tristate, "CONFIG_%s=M\n", sym->name); | 842 | fprintf(tristate, "CONFIG_%s=M\n", sym->name); |
| 741 | fprintf(out_h, "#define CONFIG_%s_MODULE 1\n", sym->name); | 843 | fprintf(out_h, "#define CONFIG_%s_MODULE 1\n", sym->name); |
| 742 | break; | 844 | break; |
| 743 | case yes: | 845 | case yes: |
| 744 | fprintf(out, "CONFIG_%s=y\n", sym->name); | ||
| 745 | if (sym->type == S_TRISTATE) | 846 | if (sym->type == S_TRISTATE) |
| 746 | fprintf(tristate, "CONFIG_%s=Y\n", | 847 | fprintf(tristate, "CONFIG_%s=Y\n", |
| 747 | sym->name); | 848 | sym->name); |
| @@ -750,35 +851,16 @@ int conf_write_autoconf(void) | |||
| 750 | } | 851 | } |
| 751 | break; | 852 | break; |
| 752 | case S_STRING: | 853 | case S_STRING: |
| 753 | str = sym_get_string_value(sym); | 854 | conf_write_string(true, sym->name, sym_get_string_value(sym), out_h); |
| 754 | fprintf(out, "CONFIG_%s=\"", sym->name); | ||
| 755 | fprintf(out_h, "#define CONFIG_%s \"", sym->name); | ||
| 756 | while (1) { | ||
| 757 | l = strcspn(str, "\"\\"); | ||
| 758 | if (l) { | ||
| 759 | fwrite(str, l, 1, out); | ||
| 760 | fwrite(str, l, 1, out_h); | ||
| 761 | str += l; | ||
| 762 | } | ||
| 763 | if (!*str) | ||
| 764 | break; | ||
| 765 | fprintf(out, "\\%c", *str); | ||
| 766 | fprintf(out_h, "\\%c", *str); | ||
| 767 | str++; | ||
| 768 | } | ||
| 769 | fputs("\"\n", out); | ||
| 770 | fputs("\"\n", out_h); | ||
| 771 | break; | 855 | break; |
| 772 | case S_HEX: | 856 | case S_HEX: |
| 773 | str = sym_get_string_value(sym); | 857 | str = sym_get_string_value(sym); |
| 774 | if (str[0] != '0' || (str[1] != 'x' && str[1] != 'X')) { | 858 | if (str[0] != '0' || (str[1] != 'x' && str[1] != 'X')) { |
| 775 | fprintf(out, "CONFIG_%s=%s\n", sym->name, str); | ||
| 776 | fprintf(out_h, "#define CONFIG_%s 0x%s\n", sym->name, str); | 859 | fprintf(out_h, "#define CONFIG_%s 0x%s\n", sym->name, str); |
| 777 | break; | 860 | break; |
| 778 | } | 861 | } |
| 779 | case S_INT: | 862 | case S_INT: |
| 780 | str = sym_get_string_value(sym); | 863 | str = sym_get_string_value(sym); |
| 781 | fprintf(out, "CONFIG_%s=%s\n", sym->name, str); | ||
| 782 | fprintf(out_h, "#define CONFIG_%s %s\n", sym->name, str); | 864 | fprintf(out_h, "#define CONFIG_%s %s\n", sym->name, str); |
| 783 | break; | 865 | break; |
| 784 | default: | 866 | default: |
| @@ -862,7 +944,8 @@ void conf_set_all_new_symbols(enum conf_def_mode mode) | |||
| 862 | sym->def[S_DEF_USER].tri = no; | 944 | sym->def[S_DEF_USER].tri = no; |
| 863 | break; | 945 | break; |
| 864 | case def_random: | 946 | case def_random: |
| 865 | sym->def[S_DEF_USER].tri = (tristate)(rand() % 3); | 947 | cnt = sym_get_type(sym) == S_TRISTATE ? 3 : 2; |
| 948 | sym->def[S_DEF_USER].tri = (tristate)(rand() % cnt); | ||
| 866 | break; | 949 | break; |
| 867 | default: | 950 | default: |
| 868 | continue; | 951 | continue; |
