2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
19 static void conf_warning(const char *fmt
, ...)
20 __attribute__ ((format (printf
, 1, 2)));
22 static void conf_message(const char *fmt
, ...)
23 __attribute__ ((format (printf
, 1, 2)));
25 static const char *conf_filename
;
26 static int conf_lineno
, conf_warnings
, conf_unsaved
;
28 const char conf_defname
[] = "arch/$ARCH/defconfig";
31 #define mkdir(_n,_p) mkdir((_n))
34 static void conf_warning(const char *fmt
, ...)
38 fprintf(stderr
, "%s:%d:warning: ", conf_filename
, conf_lineno
);
39 vfprintf(stderr
, fmt
, ap
);
40 fprintf(stderr
, "\n");
45 static void conf_notice(const char *fmt
, ...)
49 fprintf(stderr
, "%s:%d:notice: ", conf_filename
, conf_lineno
);
50 vfprintf(stderr
, fmt
, ap
);
51 fprintf(stderr
, "\n");
55 static void conf_default_message_callback(const char *fmt
, va_list ap
)
62 static void (*conf_message_callback
) (const char *fmt
, va_list ap
) =
63 conf_default_message_callback
;
64 void conf_set_message_callback(void (*fn
) (const char *fmt
, va_list ap
))
66 conf_message_callback
= fn
;
69 static void conf_message(const char *fmt
, ...)
74 if (conf_message_callback
)
75 conf_message_callback(fmt
, ap
);
79 const char *conf_get_configname(void)
81 char *name
= getenv("KCONFIG_CONFIG");
83 return name
? name
: ".config";
86 const char *conf_get_autoconfig_name(void)
88 char *name
= getenv("KCONFIG_AUTOCONFIG");
90 return name
? name
: "include/config/auto.conf";
93 static char *conf_expand_value(const char *in
)
97 static char res_value
[SYMBOL_MAXLENGTH
];
98 char *dst
, name
[SYMBOL_MAXLENGTH
];
102 while ((src
= strchr(in
, '$'))) {
103 strncat(res_value
, in
, src
- in
);
106 while (isalnum(*src
) || *src
== '_')
109 sym
= sym_lookup(name
, 0);
111 strcat(res_value
, sym_get_string_value(sym
));
114 strcat(res_value
, in
);
119 char *conf_get_default_confname(void)
122 static char fullname
[PATH_MAX
+1];
125 name
= conf_expand_value(conf_defname
);
126 env
= getenv(SRCTREE
);
128 sprintf(fullname
, "%s/%s", env
, name
);
129 if (!stat(fullname
, &buf
))
135 static int conf_set_sym_val(struct symbol
*sym
, int def
, int def_flags
, char *p
)
142 sym
->def
[def
].tri
= mod
;
143 sym
->flags
|= def_flags
;
149 sym
->def
[def
].tri
= yes
;
150 sym
->flags
|= def_flags
;
154 sym
->def
[def
].tri
= no
;
155 sym
->flags
|= def_flags
;
158 if (def
!= S_DEF_AUTO
)
159 conf_warning("symbol value '%s' invalid for %s",
164 for (p2
= p
; *p2
&& !isspace(*p2
); p2
++)
166 sym
->type
= S_STRING
;
173 for (p2
= p
; (p2
= strpbrk(p2
, "\"\\")); p2
++) {
178 memmove(p2
, p2
+ 1, strlen(p2
));
181 if (def
!= S_DEF_AUTO
)
182 conf_warning("invalid string found");
189 if (sym_string_valid(sym
, p
)) {
190 sym
->def
[def
].val
= strdup(p
);
191 sym
->flags
|= def_flags
;
193 if (def
!= S_DEF_AUTO
)
194 conf_warning("symbol value '%s' invalid for %s",
205 #define LINE_GROWTH 16
206 static int add_byte(int c
, char **lineptr
, size_t slen
, size_t *n
)
209 size_t new_size
= slen
+ 1;
211 new_size
+= LINE_GROWTH
- 1;
213 nline
= realloc(*lineptr
, new_size
);
221 (*lineptr
)[slen
] = c
;
226 static ssize_t
compat_getline(char **lineptr
, size_t *n
, FILE *stream
)
228 char *line
= *lineptr
;
232 int c
= getc(stream
);
236 if (add_byte(c
, &line
, slen
, n
) < 0)
241 if (add_byte('\0', &line
, slen
, n
) < 0)
248 if (add_byte(c
, &line
, slen
, n
) < 0)
260 int conf_read_simple(const char *name
, int def
)
264 size_t line_asize
= 0;
270 in
= zconf_fopen(name
);
272 struct property
*prop
;
274 name
= conf_get_configname();
275 in
= zconf_fopen(name
);
278 sym_add_change_count(1);
279 if (!sym_defconfig_list
) {
281 sym_calc_value(modules_sym
);
285 for_all_defaults(sym_defconfig_list
, prop
) {
286 if (expr_calc_value(prop
->visible
.expr
) == no
||
287 prop
->expr
->type
!= E_SYMBOL
)
289 name
= conf_expand_value(prop
->expr
->left
.sym
->name
);
290 in
= zconf_fopen(name
);
292 conf_message(_("using defaults found in %s"),
302 conf_filename
= name
;
307 def_flags
= SYMBOL_DEF
<< def
;
308 for_all_symbols(i
, sym
) {
309 sym
->flags
|= SYMBOL_CHANGED
;
310 sym
->flags
&= ~(def_flags
|SYMBOL_VALID
);
311 if (sym_is_choice(sym
))
312 sym
->flags
|= def_flags
;
317 if (sym
->def
[def
].val
)
318 free(sym
->def
[def
].val
);
321 sym
->def
[def
].val
= NULL
;
322 sym
->def
[def
].tri
= no
;
326 while (compat_getline(&line
, &line_asize
, in
) != -1) {
329 if (line
[0] == '#') {
330 if (memcmp(line
+ 2, CONFIG_
, strlen(CONFIG_
)))
332 p
= strchr(line
+ 2 + strlen(CONFIG_
), ' ');
336 if (strncmp(p
, "is not set", 10))
338 if (def
== S_DEF_USER
) {
339 sym
= sym_find(line
+ 2 + strlen(CONFIG_
));
341 sym_add_change_count(1);
345 sym
= sym_lookup(line
+ 2 + strlen(CONFIG_
), 0);
346 if (sym
->type
== S_UNKNOWN
)
347 sym
->type
= S_BOOLEAN
;
349 if (sym
->flags
& def_flags
) {
350 conf_notice("override: reassigning to symbol %s", sym
->name
);
355 sym
->def
[def
].tri
= no
;
356 sym
->flags
|= def_flags
;
361 } else if (memcmp(line
, CONFIG_
, strlen(CONFIG_
)) == 0) {
362 p
= strchr(line
+ strlen(CONFIG_
), '=');
366 p2
= strchr(p
, '\n');
372 if (def
== S_DEF_USER
) {
373 sym
= sym_find(line
+ strlen(CONFIG_
));
376 "ignoring nonexistent symbol %s",
377 line
+ strlen(CONFIG_
));
378 sym_add_change_count(1);
382 sym
= sym_lookup(line
+ strlen(CONFIG_
), 0);
383 if (sym
->type
== S_UNKNOWN
)
386 if (sym
->flags
& def_flags
) {
387 conf_notice("override: reassigning to symbol %s", sym
->name
);
389 if (conf_set_sym_val(sym
, def
, def_flags
, p
))
392 if (line
[0] != '\r' && line
[0] != '\n')
393 conf_warning("unexpected data");
397 if (sym
&& sym_is_choice_value(sym
)) {
398 struct symbol
*cs
= prop_get_symbol(sym_get_choice_prop(sym
));
399 switch (sym
->def
[def
].tri
) {
403 if (cs
->def
[def
].tri
== yes
) {
404 conf_warning("%s creates inconsistent choice state", sym
->name
);
405 cs
->flags
&= ~def_flags
;
409 if (cs
->def
[def
].tri
!= no
)
410 conf_notice("override: %s changes choice state", sym
->name
);
411 cs
->def
[def
].val
= sym
;
414 cs
->def
[def
].tri
= EXPR_OR(cs
->def
[def
].tri
, sym
->def
[def
].tri
);
421 sym_calc_value(modules_sym
);
423 kconfig_warnings
+= conf_warnings
;
428 int conf_read(const char *name
)
433 sym_set_change_count(0);
435 if (conf_read_simple(name
, S_DEF_USER
))
438 for_all_symbols(i
, sym
) {
440 if (sym_is_choice(sym
) || (sym
->flags
& SYMBOL_AUTO
))
442 if (sym_has_value(sym
) && (sym
->flags
& SYMBOL_WRITE
)) {
443 /* check that calculated value agrees with saved value */
447 if (sym
->def
[S_DEF_USER
].tri
!= sym_get_tristate_value(sym
))
449 if (!sym_is_choice(sym
))
453 if (!strcmp(sym
->curr
.val
, sym
->def
[S_DEF_USER
].val
))
457 } else if (!sym_has_value(sym
) && !(sym
->flags
& SYMBOL_WRITE
))
458 /* no previous value and not saved */
461 /* maybe print value in verbose mode... */
464 for_all_symbols(i
, sym
) {
465 if (sym_has_value(sym
) && !sym_is_choice_value(sym
)) {
466 /* Reset values of generates values, so they'll appear
467 * as new, if they should become visible, but that
468 * doesn't quite work if the Kconfig and the saved
469 * configuration disagree.
471 if (sym
->visible
== no
&& !conf_unsaved
)
472 sym
->flags
&= ~SYMBOL_DEF_USER
;
477 /* Reset a string value if it's out of range */
478 if (sym_string_within_range(sym
, sym
->def
[S_DEF_USER
].val
))
480 sym
->flags
&= ~(SYMBOL_VALID
|SYMBOL_DEF_USER
);
489 sym_add_change_count(conf_warnings
|| conf_unsaved
);
495 * Kconfig configuration printer
497 * This printer is used when generating the resulting configuration after
498 * kconfig invocation and `defconfig' files. Unset symbol might be omitted by
499 * passing a non-NULL argument to the printer.
503 kconfig_print_symbol(FILE *fp
, struct symbol
*sym
, const char *value
, void *arg
)
510 bool skip_unset
= (arg
!= NULL
);
513 fprintf(fp
, "# %s%s is not set\n",
522 fprintf(fp
, "%s%s=%s\n", CONFIG_
, sym
->name
, value
);
526 kconfig_print_comment(FILE *fp
, const char *value
, void *arg
)
528 const char *p
= value
;
532 l
= strcspn(p
, "\n");
536 xfwrite(p
, l
, 1, fp
);
545 static struct conf_printer kconfig_printer_cb
=
547 .print_symbol
= kconfig_print_symbol
,
548 .print_comment
= kconfig_print_comment
,
554 * This printer is used when generating the `include/generated/autoconf.h' file.
557 header_print_symbol(FILE *fp
, struct symbol
*sym
, const char *value
, void *arg
)
563 const char *suffix
= "";
567 if (getenv("KCONFIG_NEGATIVES")) {
568 fprintf(fp
, "#define %s%s%s 0\n",
569 CONFIG_
, sym
->name
, suffix
);
576 fprintf(fp
, "#define %s%s%s 1\n",
577 CONFIG_
, sym
->name
, suffix
);
582 const char *prefix
= "";
584 if (!value
|| (value
[0] == '\0')) {
587 if (value
[0] != '0' || (value
[1] != 'x' && value
[1] != 'X'))
589 fprintf(fp
, "#define %s%s %s%s\n",
590 CONFIG_
, sym
->name
, prefix
, value
);
594 if (!value
|| (value
[0] == '\0')) {
599 fprintf(fp
, "#define %s%s %s\n",
600 CONFIG_
, sym
->name
, value
);
609 header_print_comment(FILE *fp
, const char *value
, void *arg
)
611 const char *p
= value
;
616 l
= strcspn(p
, "\n");
620 xfwrite(p
, l
, 1, fp
);
627 fprintf(fp
, " */\n");
630 static struct conf_printer header_printer_cb
=
632 .print_symbol
= header_print_symbol
,
633 .print_comment
= header_print_comment
,
639 * This printer is used when generating the `include/config/tristate.conf' file.
642 tristate_print_symbol(FILE *fp
, struct symbol
*sym
, const char *value
, void *arg
)
645 if (sym
->type
== S_TRISTATE
&& (*value
!= 'n' || arg
== NULL
))
646 fprintf(fp
, "%s%s=%c\n", CONFIG_
, sym
->name
, (char)toupper(*value
));
649 static struct conf_printer tristate_printer_cb
=
651 .print_symbol
= tristate_print_symbol
,
652 .print_comment
= kconfig_print_comment
,
655 static void conf_write_symbol(FILE *fp
, struct symbol
*sym
,
656 struct conf_printer
*printer
, void *printer_arg
)
665 str
= sym_get_string_value(sym
);
666 str
= sym_escape_string_value(str
);
667 printer
->print_symbol(fp
, sym
, str
, printer_arg
);
671 str
= sym_get_string_value(sym
);
672 printer
->print_symbol(fp
, sym
, str
, printer_arg
);
677 conf_write_heading(FILE *fp
, struct conf_printer
*printer
, void *printer_arg
)
681 snprintf(buf
, sizeof(buf
),
683 "Automatically generated file; DO NOT EDIT.\n"
685 rootmenu
.prompt
->text
);
687 printer
->print_comment(fp
, buf
, printer_arg
);
691 * Write out a minimal config.
692 * All values that has default values are skipped as this is redundant.
694 int conf_write_defconfig(const char *filename
)
700 out
= fopen(filename
, "w");
704 sym_clear_all_valid();
706 /* Traverse all menus to find all relevant symbols */
707 menu
= rootmenu
.list
;
713 if (!menu_is_visible(menu
))
715 } else if (!sym_is_choice(sym
)) {
717 if (!(sym
->flags
& SYMBOL_WRITE
))
719 sym
->flags
&= ~SYMBOL_WRITE
;
720 /* If we cannot change the symbol - skip */
721 if (!sym_is_changable(sym
))
723 /* If symbol equals to default value - skip */
724 if (strcmp(sym_get_string_value(sym
), sym_get_string_default(sym
)) == 0)
728 * If symbol is a choice value and equals to the
729 * default for a choice - skip.
730 * But only if value is bool and equal to "y" and
731 * choice is not "optional".
732 * (If choice is "optional" then all values can be "n")
734 if (sym_is_choice_value(sym
)) {
738 cs
= prop_get_symbol(sym_get_choice_prop(sym
));
739 ds
= sym_choice_default(cs
);
740 if (!sym_is_optional(cs
) && sym
== ds
) {
741 if ((sym
->type
== S_BOOLEAN
) &&
742 sym_get_tristate_value(sym
) == yes
)
746 conf_write_symbol(out
, sym
, &kconfig_printer_cb
, NULL
);
749 if (menu
->list
!= NULL
) {
752 else if (menu
->next
!= NULL
) {
755 while ((menu
= menu
->parent
)) {
756 if (menu
->next
!= NULL
) {
767 int conf_write(const char *name
)
772 const char *basename
;
774 char dirname
[PATH_MAX
+1], tmpname
[PATH_MAX
+1], newname
[PATH_MAX
+1];
778 if (name
&& name
[0]) {
782 if (!stat(name
, &st
) && S_ISDIR(st
.st_mode
)) {
783 strcpy(dirname
, name
);
784 strcat(dirname
, "/");
785 basename
= conf_get_configname();
786 } else if ((slash
= strrchr(name
, '/'))) {
787 int size
= slash
- name
+ 1;
788 memcpy(dirname
, name
, size
);
791 basename
= slash
+ 1;
793 basename
= conf_get_configname();
797 basename
= conf_get_configname();
799 sprintf(newname
, "%s%s", dirname
, basename
);
800 env
= getenv("KCONFIG_OVERWRITECONFIG");
802 sprintf(tmpname
, "%s.tmpconfig.%d", dirname
, (int)getpid());
803 out
= fopen(tmpname
, "w");
806 out
= fopen(newname
, "w");
811 conf_write_heading(out
, &kconfig_printer_cb
, NULL
);
813 if (!conf_get_changed())
814 sym_clear_all_valid();
816 menu
= rootmenu
.list
;
820 if (!menu_is_visible(menu
))
822 str
= menu_get_prompt(menu
);
827 } else if (!(sym
->flags
& SYMBOL_CHOICE
)) {
829 if (!(sym
->flags
& SYMBOL_WRITE
))
831 sym
->flags
&= ~SYMBOL_WRITE
;
833 conf_write_symbol(out
, sym
, &kconfig_printer_cb
, NULL
);
843 else while ((menu
= menu
->parent
)) {
853 strcat(dirname
, basename
);
854 strcat(dirname
, ".old");
855 rename(newname
, dirname
);
856 if (rename(tmpname
, newname
))
860 conf_message(_("configuration written to %s"), newname
);
862 sym_set_change_count(0);
867 static int conf_split_config(void)
870 char path
[PATH_MAX
+1];
871 char pwd
[PATH_MAX
+1];
877 name
= conf_get_autoconfig_name();
878 conf_read_simple(name
, S_DEF_AUTO
);
880 getcwd(pwd
, sizeof(pwd
));
881 name
= getenv("KCONFIG_SPLITCONFIG");
883 name
= "include/config";
888 for_all_symbols(i
, sym
) {
890 if ((sym
->flags
& SYMBOL_AUTO
) || !sym
->name
)
892 if (sym
->flags
& SYMBOL_WRITE
) {
893 if (sym
->flags
& SYMBOL_DEF_AUTO
) {
895 * symbol has old and new value,
901 if (sym_get_tristate_value(sym
) ==
902 sym
->def
[S_DEF_AUTO
].tri
)
908 if (!strcmp(sym_get_string_value(sym
),
909 sym
->def
[S_DEF_AUTO
].val
))
917 * If there is no old value, only 'no' (unset)
918 * is allowed as new value.
923 if (sym_get_tristate_value(sym
) == no
)
930 } else if (!(sym
->flags
& SYMBOL_DEF_AUTO
))
931 /* There is neither an old nor a new value. */
934 * There is an old value, but no new value ('no' (unset)
935 * isn't saved in auto.conf, so the old value is always
936 * different from 'no').
939 /* Replace all '_' and append ".h" */
944 *d
++ = (c
== '_') ? '/' : c
;
948 /* Assume directory path already exists. */
949 fd
= open(path
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0644);
951 if (errno
!= ENOENT
) {
956 * Create directory components,
957 * unless they exist already.
960 while ((d
= strchr(d
, '/'))) {
962 if (stat(path
, &sb
) && mkdir(path
, 0755)) {
969 fd
= open(path
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0644);
984 int conf_write_autoconf(void)
988 FILE *out
, *tristate
, *out_h
;
992 print_negatives
= getenv("KCONFIG_NEGATIVES") != NULL
;
994 sym_clear_all_valid();
996 char *dep_file
= getenv("KCONFIG_DEPENDENCIES");
998 dep_file
= "include/config/auto.conf.cmd";
999 file_write_dep(dep_file
);
1001 if (conf_split_config())
1004 char *tmpconfig_name
= malloc(PATH_MAX
);
1005 if (getenv("COREBOOT_BUILD_DIR")) {
1006 sprintf(tmpconfig_name
, "%s/.tmpconfig.XXXXXX",
1007 getenv("COREBOOT_BUILD_DIR"));
1009 tmpconfig_name
= strdup(".tmpconfig.XXXXXX");
1011 if ((i
= mkstemp(tmpconfig_name
)) == -1)
1013 out
= fdopen(i
, "w");
1017 char *tmpconfig_triname
= malloc(PATH_MAX
);
1018 if (getenv("COREBOOT_BUILD_DIR")) {
1019 sprintf(tmpconfig_triname
, "%s/.tmpconfig_tristate.XXXXXX",
1020 getenv("COREBOOT_BUILD_DIR"));
1022 tmpconfig_triname
= strdup(".tmpconfig_tristate.XXXXXX");
1024 if ((i
= mkstemp(tmpconfig_triname
)) == -1)
1026 tristate
= fdopen(i
, "w");
1032 char *tmpconfig_h
= malloc(PATH_MAX
);
1033 if (getenv("COREBOOT_BUILD_DIR")) {
1034 sprintf(tmpconfig_h
, "%s/.tmpconfig_tristate.XXXXXX",
1035 getenv("COREBOOT_BUILD_DIR"));
1037 tmpconfig_h
= strdup(".tmpconfig_tristate.XXXXXX");
1039 if ((i
= mkstemp(tmpconfig_h
)) == -1)
1041 out_h
= fdopen(i
, "w");
1048 conf_write_heading(out
, &kconfig_printer_cb
, NULL
);
1050 conf_write_heading(tristate
, &tristate_printer_cb
, NULL
);
1052 conf_write_heading(out_h
, &header_printer_cb
, NULL
);
1054 for_all_symbols(i
, sym
) {
1055 sym_calc_value(sym
);
1059 if (!(sym
->flags
& SYMBOL_WRITE
) && !print_negatives
)
1062 /* these are safe to write out, so do it all the time */
1063 if (!(sym
->flags
& SYMBOL_WRITE
) &&
1064 !(sym
->type
== S_BOOLEAN
||
1065 sym
->type
== S_HEX
||
1066 sym
->type
== S_INT
))
1069 /* write symbol to auto.conf, tristate and header files */
1070 conf_write_symbol(out
, sym
, &kconfig_printer_cb
, print_negatives
?NULL
:(void *)1);
1072 conf_write_symbol(tristate
, sym
, &tristate_printer_cb
, print_negatives
?NULL
:(void *)1);
1074 conf_write_symbol(out_h
, sym
, &header_printer_cb
, NULL
);
1080 name
= getenv("KCONFIG_AUTOHEADER");
1082 name
= "include/generated/autoconf.h";
1083 if (rename(tmpconfig_h
, name
))
1085 name
= getenv("KCONFIG_TRISTATE");
1087 name
= "include/config/tristate.conf";
1088 if (rename(tmpconfig_triname
, name
))
1090 name
= conf_get_autoconfig_name();
1092 * This must be the last step, kbuild has a dependency on auto.conf
1093 * and this marks the successful completion of the previous steps.
1095 if (rename(tmpconfig_name
, name
))
1101 static int sym_change_count
;
1102 static void (*conf_changed_callback
)(void);
1104 void sym_set_change_count(int count
)
1106 int _sym_change_count
= sym_change_count
;
1107 sym_change_count
= count
;
1108 if (conf_changed_callback
&&
1109 (bool)_sym_change_count
!= (bool)count
)
1110 conf_changed_callback();
1113 void sym_add_change_count(int count
)
1115 sym_set_change_count(count
+ sym_change_count
);
1118 bool conf_get_changed(void)
1120 return sym_change_count
;
1123 void conf_set_changed_callback(void (*fn
)(void))
1125 conf_changed_callback
= fn
;
1128 static bool randomize_choice_values(struct symbol
*csym
)
1130 struct property
*prop
;
1136 * If choice is mod then we may have more items selected
1137 * and if no then no-one.
1138 * In both cases stop.
1140 if (csym
->curr
.tri
!= yes
)
1143 prop
= sym_get_choice_prop(csym
);
1145 /* count entries in choice block */
1147 expr_list_for_each_sym(prop
->expr
, e
, sym
)
1151 * find a random value and set it to yes,
1152 * set the rest to no so we have only one set
1154 def
= (rand() % cnt
);
1157 expr_list_for_each_sym(prop
->expr
, e
, sym
) {
1159 sym
->def
[S_DEF_USER
].tri
= yes
;
1160 csym
->def
[S_DEF_USER
].val
= sym
;
1163 sym
->def
[S_DEF_USER
].tri
= no
;
1165 sym
->flags
|= SYMBOL_DEF_USER
;
1166 /* clear VALID to get value calculated */
1167 sym
->flags
&= ~SYMBOL_VALID
;
1169 csym
->flags
|= SYMBOL_DEF_USER
;
1170 /* clear VALID to get value calculated */
1171 csym
->flags
&= ~(SYMBOL_VALID
);
1176 void set_all_choice_values(struct symbol
*csym
)
1178 struct property
*prop
;
1182 prop
= sym_get_choice_prop(csym
);
1185 * Set all non-assinged choice values to no
1187 expr_list_for_each_sym(prop
->expr
, e
, sym
) {
1188 if (!sym_has_value(sym
))
1189 sym
->def
[S_DEF_USER
].tri
= no
;
1191 csym
->flags
|= SYMBOL_DEF_USER
;
1192 /* clear VALID to get value calculated */
1193 csym
->flags
&= ~(SYMBOL_VALID
| SYMBOL_NEED_SET_CHOICE_VALUES
);
1196 bool conf_set_all_new_symbols(enum conf_def_mode mode
)
1198 struct symbol
*sym
, *csym
;
1199 int i
, cnt
, pby
, pty
, ptm
; /* pby: probability of boolean = y
1200 * pty: probability of tristate = y
1201 * ptm: probability of tristate = m
1204 pby
= 50; pty
= ptm
= 33; /* can't go as the default in switch-case
1205 * below, otherwise gcc whines about
1206 * -Wmaybe-uninitialized */
1207 if (mode
== def_random
) {
1209 char *env
= getenv("KCONFIG_PROBABILITY");
1211 while( env
&& *env
) {
1213 int tmp
= strtol( env
, &endp
, 10 );
1214 if( tmp
>= 0 && tmp
<= 100 ) {
1218 perror( "KCONFIG_PROBABILITY" );
1221 env
= (*endp
== ':') ? endp
+1 : endp
;
1228 pby
= p
[0]; ptm
= pby
/2; pty
= pby
-ptm
;
1231 pty
= p
[0]; ptm
= p
[1]; pby
= pty
+ ptm
;
1234 pby
= p
[0]; pty
= p
[1]; ptm
= p
[2];
1238 if( pty
+ptm
> 100 ) {
1240 perror( "KCONFIG_PROBABILITY" );
1244 bool has_changed
= false;
1246 for_all_symbols(i
, sym
) {
1247 if (sym_has_value(sym
) || (sym
->flags
& SYMBOL_VALID
))
1249 switch (sym_get_type(sym
)) {
1255 sym
->def
[S_DEF_USER
].tri
= yes
;
1258 sym
->def
[S_DEF_USER
].tri
= mod
;
1261 if (sym
->flags
& SYMBOL_ALLNOCONFIG_Y
)
1262 sym
->def
[S_DEF_USER
].tri
= yes
;
1264 sym
->def
[S_DEF_USER
].tri
= no
;
1267 sym
->def
[S_DEF_USER
].tri
= no
;
1269 if (sym
->type
== S_TRISTATE
) {
1271 sym
->def
[S_DEF_USER
].tri
= yes
;
1272 else if (cnt
< (pty
+ptm
))
1273 sym
->def
[S_DEF_USER
].tri
= mod
;
1274 } else if (cnt
< pby
)
1275 sym
->def
[S_DEF_USER
].tri
= yes
;
1280 if (!(sym_is_choice(sym
) && mode
== def_random
))
1281 sym
->flags
|= SYMBOL_DEF_USER
;
1289 sym_clear_all_valid();
1292 * We have different type of choice blocks.
1293 * If curr.tri equals to mod then we can select several
1294 * choice symbols in one block.
1295 * In this case we do nothing.
1296 * If curr.tri equals yes then only one symbol can be
1297 * selected in a choice block and we set it to yes,
1298 * and the rest to no.
1300 if (mode
!= def_random
) {
1301 for_all_symbols(i
, csym
) {
1302 if ((sym_is_choice(csym
) && !sym_has_value(csym
)) ||
1303 sym_is_choice_value(csym
))
1304 csym
->flags
|= SYMBOL_NEED_SET_CHOICE_VALUES
;
1308 for_all_symbols(i
, csym
) {
1309 if (sym_has_value(csym
) || !sym_is_choice(csym
))
1312 sym_calc_value(csym
);
1313 if (mode
== def_random
)
1314 has_changed
= randomize_choice_values(csym
);
1316 set_all_choice_values(csym
);