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.c121
1 files changed, 119 insertions, 2 deletions
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index ca693fcd023f..e28cd0c2ca08 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 <fcntl.h>
8#include <stdio.h> 9#include <stdio.h>
9#include <stdlib.h> 10#include <stdlib.h>
10#include <string.h> 11#include <string.h>
@@ -520,6 +521,119 @@ int conf_write(const char *name)
520 return 0; 521 return 0;
521} 522}
522 523
524int conf_split_config(void)
525{
526 char *name, path[128];
527 char *s, *d, c;
528 struct symbol *sym;
529 struct stat sb;
530 int res, i, fd;
531
532 name = getenv("KCONFIG_AUTOCONFIG");
533 if (!name)
534 name = "include/config/auto.conf";
535 conf_read_simple(name, S_DEF_AUTO);
536
537 if (chdir("include/config"))
538 return 1;
539
540 res = 0;
541 for_all_symbols(i, sym) {
542 sym_calc_value(sym);
543 if ((sym->flags & SYMBOL_AUTO) || !sym->name)
544 continue;
545 if (sym->flags & SYMBOL_WRITE) {
546 if (sym->flags & SYMBOL_DEF_AUTO) {
547 /*
548 * symbol has old and new value,
549 * so compare them...
550 */
551 switch (sym->type) {
552 case S_BOOLEAN:
553 case S_TRISTATE:
554 if (sym_get_tristate_value(sym) ==
555 sym->def[S_DEF_AUTO].tri)
556 continue;
557 break;
558 case S_STRING:
559 case S_HEX:
560 case S_INT:
561 if (!strcmp(sym_get_string_value(sym),
562 sym->def[S_DEF_AUTO].val))
563 continue;
564 break;
565 default:
566 break;
567 }
568 } else {
569 /*
570 * If there is no old value, only 'no' (unset)
571 * is allowed as new value.
572 */
573 switch (sym->type) {
574 case S_BOOLEAN:
575 case S_TRISTATE:
576 if (sym_get_tristate_value(sym) == no)
577 continue;
578 break;
579 default:
580 break;
581 }
582 }
583 } else if (!(sym->flags & SYMBOL_DEF_AUTO))
584 /* There is neither an old nor a new value. */
585 continue;
586 /* else
587 * There is an old value, but no new value ('no' (unset)
588 * isn't saved in auto.conf, so the old value is always
589 * different from 'no').
590 */
591
592 /* Replace all '_' and append ".h" */
593 s = sym->name;
594 d = path;
595 while ((c = *s++)) {
596 c = tolower(c);
597 *d++ = (c == '_') ? '/' : c;
598 }
599 strcpy(d, ".h");
600
601 /* Assume directory path already exists. */
602 fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
603 if (fd == -1) {
604 if (errno != ENOENT) {
605 res = 1;
606 break;
607 }
608 /*
609 * Create directory components,
610 * unless they exist already.
611 */
612 d = path;
613 while ((d = strchr(d, '/'))) {
614 *d = 0;
615 if (stat(path, &sb) && mkdir(path, 0755)) {
616 res = 1;
617 goto out;
618 }
619 *d++ = '/';
620 }
621 /* Try it again. */
622 fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
623 if (fd == -1) {
624 res = 1;
625 break;
626 }
627 }
628 close(fd);
629 }
630out:
631 if (chdir("../.."))
632 return 1;
633
634 return res;
635}
636
523int conf_write_autoconf(void) 637int conf_write_autoconf(void)
524{ 638{
525 struct symbol *sym; 639 struct symbol *sym;
@@ -529,8 +643,13 @@ int conf_write_autoconf(void)
529 time_t now; 643 time_t now;
530 int i, l; 644 int i, l;
531 645
646 sym_clear_all_valid();
647
532 file_write_dep("include/config/auto.conf.cmd"); 648 file_write_dep("include/config/auto.conf.cmd");
533 649
650 if (conf_split_config())
651 return 1;
652
534 out = fopen(".tmpconfig", "w"); 653 out = fopen(".tmpconfig", "w");
535 if (!out) 654 if (!out)
536 return 1; 655 return 1;
@@ -558,8 +677,6 @@ int conf_write_autoconf(void)
558 "#define AUTOCONF_INCLUDED\n", 677 "#define AUTOCONF_INCLUDED\n",
559 sym_get_string_value(sym), ctime(&now)); 678 sym_get_string_value(sym), ctime(&now));
560 679
561 sym_clear_all_valid();
562
563 for_all_symbols(i, sym) { 680 for_all_symbols(i, sym) {
564 sym_calc_value(sym); 681 sym_calc_value(sym);
565 if (!(sym->flags & SYMBOL_WRITE) || !sym->name) 682 if (!(sym->flags & SYMBOL_WRITE) || !sym->name)