2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
10 #include <sys/utsname.h>
14 struct symbol symbol_yes
= {
17 .flags
= SYMBOL_CONST
|SYMBOL_VALID
,
21 .flags
= SYMBOL_CONST
|SYMBOL_VALID
,
25 .flags
= SYMBOL_CONST
|SYMBOL_VALID
,
29 .flags
= SYMBOL_VALID
,
32 struct symbol
*sym_defconfig_list
;
33 struct symbol
*modules_sym
;
36 enum symbol_type
sym_get_type(struct symbol
*sym
)
38 enum symbol_type type
= sym
->type
;
40 if (type
== S_TRISTATE
) {
41 if (sym_is_choice_value(sym
) && sym
->visible
== yes
)
43 else if (modules_val
== no
)
49 const char *sym_type_name(enum symbol_type type
)
70 struct property
*sym_get_choice_prop(struct symbol
*sym
)
72 struct property
*prop
;
74 for_all_choices(sym
, prop
)
79 struct property
*sym_get_env_prop(struct symbol
*sym
)
81 struct property
*prop
;
83 for_all_properties(sym
, prop
, P_ENV
)
88 static struct property
*sym_get_default_prop(struct symbol
*sym
)
90 struct property
*prop
;
92 for_all_defaults(sym
, prop
) {
93 prop
->visible
.tri
= expr_calc_value(prop
->visible
.expr
);
94 if (prop
->visible
.tri
!= no
)
100 static struct property
*sym_get_range_prop(struct symbol
*sym
)
102 struct property
*prop
;
104 for_all_properties(sym
, prop
, P_RANGE
) {
105 prop
->visible
.tri
= expr_calc_value(prop
->visible
.expr
);
106 if (prop
->visible
.tri
!= no
)
112 static long long sym_get_range_val(struct symbol
*sym
, int base
)
125 return strtoll(sym
->curr
.val
, NULL
, base
);
128 static void sym_validate_range(struct symbol
*sym
)
130 struct property
*prop
;
145 prop
= sym_get_range_prop(sym
);
148 val
= strtoll(sym
->curr
.val
, NULL
, base
);
149 val2
= sym_get_range_val(prop
->expr
->left
.sym
, base
);
151 val2
= sym_get_range_val(prop
->expr
->right
.sym
, base
);
155 if (sym
->type
== S_INT
)
156 sprintf(str
, "%lld", val2
);
158 sprintf(str
, "0x%llx", val2
);
159 sym
->curr
.val
= xstrdup(str
);
162 static void sym_set_changed(struct symbol
*sym
)
164 struct property
*prop
;
166 sym
->flags
|= SYMBOL_CHANGED
;
167 for (prop
= sym
->prop
; prop
; prop
= prop
->next
) {
169 prop
->menu
->flags
|= MENU_CHANGED
;
173 static void sym_set_all_changed(void)
178 for_all_symbols(i
, sym
)
179 sym_set_changed(sym
);
182 static void sym_calc_visibility(struct symbol
*sym
)
184 struct property
*prop
;
185 struct symbol
*choice_sym
= NULL
;
188 /* any prompt visible? */
191 if (sym_is_choice_value(sym
))
192 choice_sym
= prop_get_symbol(sym_get_choice_prop(sym
));
194 for_all_prompts(sym
, prop
) {
195 prop
->visible
.tri
= expr_calc_value(prop
->visible
.expr
);
197 * Tristate choice_values with visibility 'mod' are
198 * not visible if the corresponding choice's value is
201 if (choice_sym
&& sym
->type
== S_TRISTATE
&&
202 prop
->visible
.tri
== mod
&& choice_sym
->curr
.tri
== yes
)
203 prop
->visible
.tri
= no
;
205 tri
= EXPR_OR(tri
, prop
->visible
.tri
);
207 if (tri
== mod
&& (sym
->type
!= S_TRISTATE
|| modules_val
== no
))
209 if (sym
->visible
!= tri
) {
211 sym_set_changed(sym
);
213 if (sym_is_choice_value(sym
))
215 /* defaulting to "yes" if no explicit "depends on" are given */
217 if (sym
->dir_dep
.expr
)
218 tri
= expr_calc_value(sym
->dir_dep
.expr
);
219 if (tri
== mod
&& sym_get_type(sym
) == S_BOOLEAN
)
221 if (sym
->dir_dep
.tri
!= tri
) {
222 sym
->dir_dep
.tri
= tri
;
223 sym_set_changed(sym
);
226 if (sym
->rev_dep
.expr
)
227 tri
= expr_calc_value(sym
->rev_dep
.expr
);
228 if (tri
== mod
&& sym_get_type(sym
) == S_BOOLEAN
)
230 if (sym
->rev_dep
.tri
!= tri
) {
231 sym
->rev_dep
.tri
= tri
;
232 sym_set_changed(sym
);
235 if (sym
->implied
.expr
&& sym
->dir_dep
.tri
!= no
)
236 tri
= expr_calc_value(sym
->implied
.expr
);
237 if (tri
== mod
&& sym_get_type(sym
) == S_BOOLEAN
)
239 if (sym
->implied
.tri
!= tri
) {
240 sym
->implied
.tri
= tri
;
241 sym_set_changed(sym
);
246 * Find the default symbol for a choice.
247 * First try the default values for the choice symbol
248 * Next locate the first visible choice value
249 * Return NULL if none was found
251 struct symbol
*sym_choice_default(struct symbol
*sym
)
253 struct symbol
*def_sym
;
254 struct property
*prop
;
257 /* any of the defaults visible? */
258 for_all_defaults(sym
, prop
) {
259 prop
->visible
.tri
= expr_calc_value(prop
->visible
.expr
);
260 if (prop
->visible
.tri
== no
)
262 def_sym
= prop_get_symbol(prop
);
263 if (def_sym
->visible
!= no
)
267 /* just get the first visible value */
268 prop
= sym_get_choice_prop(sym
);
269 expr_list_for_each_sym(prop
->expr
, e
, def_sym
)
270 if (def_sym
->visible
!= no
)
273 /* failed to locate any defaults */
277 static struct symbol
*sym_calc_choice(struct symbol
*sym
)
279 struct symbol
*def_sym
;
280 struct property
*prop
;
284 /* first calculate all choice values' visibilities */
286 prop
= sym_get_choice_prop(sym
);
287 expr_list_for_each_sym(prop
->expr
, e
, def_sym
) {
288 sym_calc_visibility(def_sym
);
289 if (def_sym
->visible
!= no
)
290 flags
&= def_sym
->flags
;
293 sym
->flags
&= flags
| ~SYMBOL_DEF_USER
;
295 /* is the user choice visible? */
296 def_sym
= sym
->def
[S_DEF_USER
].val
;
297 if (def_sym
&& def_sym
->visible
!= no
)
300 def_sym
= sym_choice_default(sym
);
303 /* no choice? reset tristate value */
309 static void sym_warn_unmet_dep(struct symbol
*sym
)
311 struct gstr gs
= str_new();
314 "\nWARNING: unmet direct dependencies detected for %s\n",
317 " Depends on [%c]: ",
318 sym
->dir_dep
.tri
== mod
? 'm' : 'n');
319 expr_gstr_print(sym
->dir_dep
.expr
, &gs
);
320 str_printf(&gs
, "\n");
322 expr_gstr_print_revdep(sym
->rev_dep
.expr
, &gs
, yes
,
323 " Selected by [y]:\n");
324 expr_gstr_print_revdep(sym
->rev_dep
.expr
, &gs
, mod
,
325 " Selected by [m]:\n");
327 fputs(str_get(&gs
), stderr
);
330 void sym_calc_value(struct symbol
*sym
)
332 struct symbol_value newval
, oldval
;
333 struct property
*prop
;
339 if (sym
->flags
& SYMBOL_VALID
)
342 if (sym_is_choice_value(sym
) &&
343 sym
->flags
& SYMBOL_NEED_SET_CHOICE_VALUES
) {
344 sym
->flags
&= ~SYMBOL_NEED_SET_CHOICE_VALUES
;
345 prop
= sym_get_choice_prop(sym
);
346 sym_calc_value(prop_get_symbol(prop
));
349 sym
->flags
|= SYMBOL_VALID
;
357 newval
= symbol_empty
.curr
;
361 newval
= symbol_no
.curr
;
364 sym
->curr
.val
= sym
->name
;
368 sym
->flags
&= ~SYMBOL_WRITE
;
370 sym_calc_visibility(sym
);
372 if (sym
->visible
!= no
)
373 sym
->flags
|= SYMBOL_WRITE
;
375 /* set default if recursively called */
378 switch (sym_get_type(sym
)) {
381 if (sym_is_choice_value(sym
) && sym
->visible
== yes
) {
382 prop
= sym_get_choice_prop(sym
);
383 newval
.tri
= (prop_get_symbol(prop
)->curr
.val
== sym
) ? yes
: no
;
385 if (sym
->visible
!= no
) {
386 /* if the symbol is visible use the user value
387 * if available, otherwise try the default value
389 if (sym_has_value(sym
)) {
390 newval
.tri
= EXPR_AND(sym
->def
[S_DEF_USER
].tri
,
395 if (sym
->rev_dep
.tri
!= no
)
396 sym
->flags
|= SYMBOL_WRITE
;
397 if (!sym_is_choice(sym
)) {
398 prop
= sym_get_default_prop(sym
);
400 newval
.tri
= EXPR_AND(expr_calc_value(prop
->expr
),
402 if (newval
.tri
!= no
)
403 sym
->flags
|= SYMBOL_WRITE
;
405 if (sym
->implied
.tri
!= no
) {
406 sym
->flags
|= SYMBOL_WRITE
;
407 newval
.tri
= EXPR_OR(newval
.tri
, sym
->implied
.tri
);
411 if (sym
->dir_dep
.tri
< sym
->rev_dep
.tri
)
412 sym_warn_unmet_dep(sym
);
413 newval
.tri
= EXPR_OR(newval
.tri
, sym
->rev_dep
.tri
);
415 if (newval
.tri
== mod
&&
416 (sym_get_type(sym
) == S_BOOLEAN
|| sym
->implied
.tri
== yes
))
422 if (sym
->visible
!= no
&& sym_has_value(sym
)) {
423 newval
.val
= sym
->def
[S_DEF_USER
].val
;
426 prop
= sym_get_default_prop(sym
);
428 struct symbol
*ds
= prop_get_symbol(prop
);
430 sym
->flags
|= SYMBOL_WRITE
;
432 newval
.val
= ds
->curr
.val
;
441 if (sym_is_choice(sym
) && newval
.tri
== yes
)
442 sym
->curr
.val
= sym_calc_choice(sym
);
443 sym_validate_range(sym
);
445 if (memcmp(&oldval
, &sym
->curr
, sizeof(oldval
))) {
446 sym_set_changed(sym
);
447 if (modules_sym
== sym
) {
448 sym_set_all_changed();
449 modules_val
= modules_sym
->curr
.tri
;
453 if (sym_is_choice(sym
)) {
454 struct symbol
*choice_sym
;
456 prop
= sym_get_choice_prop(sym
);
457 expr_list_for_each_sym(prop
->expr
, e
, choice_sym
) {
458 if ((sym
->flags
& SYMBOL_WRITE
) &&
459 choice_sym
->visible
!= no
)
460 choice_sym
->flags
|= SYMBOL_WRITE
;
461 if (sym
->flags
& SYMBOL_CHANGED
)
462 sym_set_changed(choice_sym
);
466 if (sym
->flags
& SYMBOL_AUTO
)
467 sym
->flags
&= ~SYMBOL_WRITE
;
469 if (sym
->flags
& SYMBOL_NEED_SET_CHOICE_VALUES
)
470 set_all_choice_values(sym
);
473 void sym_clear_all_valid(void)
478 for_all_symbols(i
, sym
)
479 sym
->flags
&= ~SYMBOL_VALID
;
480 sym_add_change_count(1);
481 sym_calc_value(modules_sym
);
484 bool sym_tristate_within_range(struct symbol
*sym
, tristate val
)
486 int type
= sym_get_type(sym
);
488 if (sym
->visible
== no
)
491 if (type
!= S_BOOLEAN
&& type
!= S_TRISTATE
)
494 if (type
== S_BOOLEAN
&& val
== mod
)
496 if (sym
->visible
<= sym
->rev_dep
.tri
)
498 if (sym
->implied
.tri
== yes
&& val
== mod
)
500 if (sym_is_choice_value(sym
) && sym
->visible
== yes
)
502 return val
>= sym
->rev_dep
.tri
&& val
<= sym
->visible
;
505 bool sym_set_tristate_value(struct symbol
*sym
, tristate val
)
507 tristate oldval
= sym_get_tristate_value(sym
);
509 if (oldval
!= val
&& !sym_tristate_within_range(sym
, val
))
512 if (!(sym
->flags
& SYMBOL_DEF_USER
)) {
513 sym
->flags
|= SYMBOL_DEF_USER
;
514 sym_set_changed(sym
);
517 * setting a choice value also resets the new flag of the choice
518 * symbol and all other choice values.
520 if (sym_is_choice_value(sym
) && val
== yes
) {
521 struct symbol
*cs
= prop_get_symbol(sym_get_choice_prop(sym
));
522 struct property
*prop
;
525 cs
->def
[S_DEF_USER
].val
= sym
;
526 cs
->flags
|= SYMBOL_DEF_USER
;
527 prop
= sym_get_choice_prop(cs
);
528 for (e
= prop
->expr
; e
; e
= e
->left
.expr
) {
529 if (e
->right
.sym
->visible
!= no
)
530 e
->right
.sym
->flags
|= SYMBOL_DEF_USER
;
534 sym
->def
[S_DEF_USER
].tri
= val
;
536 sym_clear_all_valid();
541 tristate
sym_toggle_tristate_value(struct symbol
*sym
)
543 tristate oldval
, newval
;
545 oldval
= newval
= sym_get_tristate_value(sym
);
558 if (sym_set_tristate_value(sym
, newval
))
560 } while (oldval
!= newval
);
564 bool sym_string_valid(struct symbol
*sym
, const char *str
)
577 if (ch
== '0' && *str
!= 0)
579 while ((ch
= *str
++)) {
585 if (str
[0] == '0' && (str
[1] == 'x' || str
[1] == 'X'))
591 } while ((ch
= *str
++));
607 bool sym_string_within_range(struct symbol
*sym
, const char *str
)
609 struct property
*prop
;
614 return sym_string_valid(sym
, str
);
616 if (!sym_string_valid(sym
, str
))
618 prop
= sym_get_range_prop(sym
);
621 val
= strtoll(str
, NULL
, 10);
622 return val
>= sym_get_range_val(prop
->expr
->left
.sym
, 10) &&
623 val
<= sym_get_range_val(prop
->expr
->right
.sym
, 10);
625 if (!sym_string_valid(sym
, str
))
627 prop
= sym_get_range_prop(sym
);
630 val
= strtoll(str
, NULL
, 16);
631 return val
>= sym_get_range_val(prop
->expr
->left
.sym
, 16) &&
632 val
<= sym_get_range_val(prop
->expr
->right
.sym
, 16);
637 return sym_tristate_within_range(sym
, yes
);
639 return sym_tristate_within_range(sym
, mod
);
641 return sym_tristate_within_range(sym
, no
);
649 bool sym_set_string_value(struct symbol
*sym
, const char *newval
)
660 return sym_set_tristate_value(sym
, yes
);
662 return sym_set_tristate_value(sym
, mod
);
664 return sym_set_tristate_value(sym
, no
);
671 if (!sym_string_within_range(sym
, newval
))
674 if (!(sym
->flags
& SYMBOL_DEF_USER
)) {
675 sym
->flags
|= SYMBOL_DEF_USER
;
676 sym_set_changed(sym
);
679 oldval
= sym
->def
[S_DEF_USER
].val
;
680 size
= strlen(newval
) + 1;
681 if (sym
->type
== S_HEX
&& (newval
[0] != '0' || (newval
[1] != 'x' && newval
[1] != 'X'))) {
683 sym
->def
[S_DEF_USER
].val
= val
= xmalloc(size
);
686 } else if (!oldval
|| strcmp(oldval
, newval
))
687 sym
->def
[S_DEF_USER
].val
= val
= xmalloc(size
);
692 free((void *)oldval
);
693 sym_clear_all_valid();
699 * Find the default value associated to a symbol.
700 * For tristate symbol handle the modules=n case
701 * in which case "m" becomes "y".
702 * If the symbol does not have any default then fallback
703 * to the fixed default values.
705 const char *sym_get_string_default(struct symbol
*sym
)
707 struct property
*prop
;
712 sym_calc_visibility(sym
);
713 sym_calc_value(modules_sym
);
714 val
= symbol_no
.curr
.tri
;
715 str
= symbol_empty
.curr
.val
;
717 /* If symbol has a default value look it up */
718 prop
= sym_get_default_prop(sym
);
723 /* The visibility may limit the value from yes => mod */
724 val
= EXPR_AND(expr_calc_value(prop
->expr
), prop
->visible
.tri
);
728 * The following fails to handle the situation
729 * where a default value is further limited by
732 ds
= prop_get_symbol(prop
);
735 str
= (const char *)ds
->curr
.val
;
740 /* Handle select statements */
741 val
= EXPR_OR(val
, sym
->rev_dep
.tri
);
743 /* transpose mod to yes if modules are not enabled */
745 if (!sym_is_choice_value(sym
) && modules_sym
->curr
.tri
== no
)
748 /* transpose mod to yes if type is bool */
749 if (sym
->type
== S_BOOLEAN
&& val
== mod
)
752 /* adjust the default value if this symbol is implied by another */
753 if (val
< sym
->implied
.tri
)
754 val
= sym
->implied
.tri
;
761 case mod
: return "m";
762 case yes
: return "y";
776 const char *sym_get_string_value(struct symbol
*sym
)
783 val
= sym_get_tristate_value(sym
);
788 sym_calc_value(modules_sym
);
789 return (modules_sym
->curr
.tri
== no
) ? "n" : "m";
797 return (const char *)sym
->curr
.val
;
800 bool sym_is_changable(struct symbol
*sym
)
802 return sym
->visible
> sym
->rev_dep
.tri
;
805 static unsigned strhash(const char *s
)
808 unsigned hash
= 2166136261U;
810 hash
= (hash
^ *s
) * 0x01000193;
814 struct symbol
*sym_lookup(const char *name
, int flags
)
816 struct symbol
*symbol
;
821 if (name
[0] && !name
[1]) {
823 case 'y': return &symbol_yes
;
824 case 'm': return &symbol_mod
;
825 case 'n': return &symbol_no
;
828 hash
= strhash(name
) % SYMBOL_HASHSIZE
;
830 for (symbol
= symbol_hash
[hash
]; symbol
; symbol
= symbol
->next
) {
832 !strcmp(symbol
->name
, name
) &&
833 (flags
? symbol
->flags
& flags
834 : !(symbol
->flags
& (SYMBOL_CONST
|SYMBOL_CHOICE
))))
837 new_name
= xstrdup(name
);
843 symbol
= xmalloc(sizeof(*symbol
));
844 memset(symbol
, 0, sizeof(*symbol
));
845 symbol
->name
= new_name
;
846 symbol
->type
= S_UNKNOWN
;
847 symbol
->flags
|= flags
;
849 symbol
->next
= symbol_hash
[hash
];
850 symbol_hash
[hash
] = symbol
;
855 struct symbol
*sym_find(const char *name
)
857 struct symbol
*symbol
= NULL
;
863 if (name
[0] && !name
[1]) {
865 case 'y': return &symbol_yes
;
866 case 'm': return &symbol_mod
;
867 case 'n': return &symbol_no
;
870 hash
= strhash(name
) % SYMBOL_HASHSIZE
;
872 for (symbol
= symbol_hash
[hash
]; symbol
; symbol
= symbol
->next
) {
874 !strcmp(symbol
->name
, name
) &&
875 !(symbol
->flags
& SYMBOL_CONST
))
882 const char *sym_escape_string_value(const char *in
)
889 reslen
= strlen(in
) + strlen("\"\"") + 1;
893 l
= strcspn(p
, "\"\\");
903 res
= xmalloc(reslen
);
910 l
= strcspn(p
, "\"\\");
918 strncat(res
, p
++, 1);
930 /* Compare matched symbols as thus:
931 * - first, symbols that match exactly
932 * - then, alphabetical sort
934 static int sym_rel_comp(const void *sym1
, const void *sym2
)
936 const struct sym_match
*s1
= sym1
;
937 const struct sym_match
*s2
= sym2
;
941 * - if matched length on symbol s1 is the length of that symbol,
942 * then this symbol should come first;
943 * - if matched length on symbol s2 is the length of that symbol,
944 * then this symbol should come first.
945 * Note: since the search can be a regexp, both symbols may match
946 * exactly; if this is the case, we can't decide which comes first,
947 * and we fallback to sorting alphabetically.
949 exact1
= (s1
->eo
- s1
->so
) == strlen(s1
->sym
->name
);
950 exact2
= (s2
->eo
- s2
->so
) == strlen(s2
->sym
->name
);
951 if (exact1
&& !exact2
)
953 if (!exact1
&& exact2
)
956 /* As a fallback, sort symbols alphabetically */
957 return strcmp(s1
->sym
->name
, s2
->sym
->name
);
960 struct symbol
**sym_re_search(const char *pattern
)
962 struct symbol
*sym
, **sym_arr
= NULL
;
963 struct sym_match
*sym_match_arr
= NULL
;
970 if (strlen(pattern
) == 0)
972 if (regcomp(&re
, pattern
, REG_EXTENDED
|REG_ICASE
))
975 for_all_symbols(i
, sym
) {
976 if (sym
->flags
& SYMBOL_CONST
|| !sym
->name
)
978 if (regexec(&re
, sym
->name
, 1, match
, 0))
983 tmp
= realloc(sym_match_arr
, size
* sizeof(struct sym_match
));
985 goto sym_re_search_free
;
989 /* As regexec returned 0, we know we have a match, so
990 * we can use match[0].rm_[se]o without further checks
992 sym_match_arr
[cnt
].so
= match
[0].rm_so
;
993 sym_match_arr
[cnt
].eo
= match
[0].rm_eo
;
994 sym_match_arr
[cnt
++].sym
= sym
;
997 qsort(sym_match_arr
, cnt
, sizeof(struct sym_match
), sym_rel_comp
);
998 sym_arr
= malloc((cnt
+1) * sizeof(struct symbol
*));
1000 goto sym_re_search_free
;
1001 for (i
= 0; i
< cnt
; i
++)
1002 sym_arr
[i
] = sym_match_arr
[i
].sym
;
1003 sym_arr
[cnt
] = NULL
;
1006 /* sym_match_arr can be NULL if no match, but free(NULL) is OK */
1007 free(sym_match_arr
);
1014 * When we check for recursive dependencies we use a stack to save
1015 * current state so we can print out relevant info to user.
1016 * The entries are located on the call stack so no need to free memory.
1017 * Note insert() remove() must always match to properly clear the stack.
1019 static struct dep_stack
{
1020 struct dep_stack
*prev
, *next
;
1022 struct property
*prop
;
1026 static void dep_stack_insert(struct dep_stack
*stack
, struct symbol
*sym
)
1028 memset(stack
, 0, sizeof(*stack
));
1030 check_top
->next
= stack
;
1031 stack
->prev
= check_top
;
1036 static void dep_stack_remove(void)
1038 check_top
= check_top
->prev
;
1040 check_top
->next
= NULL
;
1044 * Called when we have detected a recursive dependency.
1045 * check_top point to the top of the stact so we use
1046 * the ->prev pointer to locate the bottom of the stack.
1048 static void sym_check_print_recursive(struct symbol
*last_sym
)
1050 struct dep_stack
*stack
;
1051 struct symbol
*sym
, *next_sym
;
1052 struct menu
*menu
= NULL
;
1053 struct property
*prop
;
1054 struct dep_stack cv_stack
;
1056 if (sym_is_choice_value(last_sym
)) {
1057 dep_stack_insert(&cv_stack
, last_sym
);
1058 last_sym
= prop_get_symbol(sym_get_choice_prop(last_sym
));
1061 for (stack
= check_top
; stack
!= NULL
; stack
= stack
->prev
)
1062 if (stack
->sym
== last_sym
)
1065 fprintf(stderr
, "unexpected recursive dependency error\n");
1069 for (; stack
; stack
= stack
->next
) {
1071 next_sym
= stack
->next
? stack
->next
->sym
: last_sym
;
1074 prop
= stack
->sym
->prop
;
1076 /* for choice values find the menu entry (used below) */
1077 if (sym_is_choice(sym
) || sym_is_choice_value(sym
)) {
1078 for (prop
= sym
->prop
; prop
; prop
= prop
->next
) {
1084 if (stack
->sym
== last_sym
)
1085 fprintf(stderr
, "%s:%d:error: recursive dependency detected!\n",
1086 prop
->file
->name
, prop
->lineno
);
1089 fprintf(stderr
, "%s:%d:\tsymbol %s %s value contains %s\n",
1090 prop
->file
->name
, prop
->lineno
,
1091 sym
->name
? sym
->name
: "<choice>",
1092 prop_get_type_name(prop
->type
),
1093 next_sym
->name
? next_sym
->name
: "<choice>");
1094 } else if (stack
->prop
) {
1095 fprintf(stderr
, "%s:%d:\tsymbol %s depends on %s\n",
1096 prop
->file
->name
, prop
->lineno
,
1097 sym
->name
? sym
->name
: "<choice>",
1098 next_sym
->name
? next_sym
->name
: "<choice>");
1099 } else if (sym_is_choice(sym
)) {
1100 fprintf(stderr
, "%s:%d:\tchoice %s contains symbol %s\n",
1101 menu
->file
->name
, menu
->lineno
,
1102 sym
->name
? sym
->name
: "<choice>",
1103 next_sym
->name
? next_sym
->name
: "<choice>");
1104 } else if (sym_is_choice_value(sym
)) {
1105 fprintf(stderr
, "%s:%d:\tsymbol %s is part of choice %s\n",
1106 menu
->file
->name
, menu
->lineno
,
1107 sym
->name
? sym
->name
: "<choice>",
1108 next_sym
->name
? next_sym
->name
: "<choice>");
1110 fprintf(stderr
, "%s:%d:\tsymbol %s is selected by %s\n",
1111 prop
->file
->name
, prop
->lineno
,
1112 sym
->name
? sym
->name
: "<choice>",
1113 next_sym
->name
? next_sym
->name
: "<choice>");
1118 "For a resolution refer to Documentation/kbuild/kconfig-language.txt\n"
1119 "subsection \"Kconfig recursive dependency limitations\"\n"
1122 if (check_top
== &cv_stack
)
1126 static struct symbol
*sym_check_expr_deps(struct expr
*e
)
1135 sym
= sym_check_expr_deps(e
->left
.expr
);
1138 return sym_check_expr_deps(e
->right
.expr
);
1140 return sym_check_expr_deps(e
->left
.expr
);
1147 sym
= sym_check_deps(e
->left
.sym
);
1150 return sym_check_deps(e
->right
.sym
);
1152 return sym_check_deps(e
->left
.sym
);
1156 fprintf(stderr
, "Oops! How to check %d?\n", e
->type
);
1160 /* return NULL when dependencies are OK */
1161 static struct symbol
*sym_check_sym_deps(struct symbol
*sym
)
1163 struct symbol
*sym2
;
1164 struct property
*prop
;
1165 struct dep_stack stack
;
1167 dep_stack_insert(&stack
, sym
);
1169 sym2
= sym_check_expr_deps(sym
->rev_dep
.expr
);
1173 for (prop
= sym
->prop
; prop
; prop
= prop
->next
) {
1174 if (prop
->type
== P_CHOICE
|| prop
->type
== P_SELECT
)
1177 sym2
= sym_check_expr_deps(prop
->visible
.expr
);
1180 if (prop
->type
!= P_DEFAULT
|| sym_is_choice(sym
))
1182 stack
.expr
= prop
->expr
;
1183 sym2
= sym_check_expr_deps(prop
->expr
);
1195 static struct symbol
*sym_check_choice_deps(struct symbol
*choice
)
1197 struct symbol
*sym
, *sym2
;
1198 struct property
*prop
;
1200 struct dep_stack stack
;
1202 dep_stack_insert(&stack
, choice
);
1204 prop
= sym_get_choice_prop(choice
);
1205 expr_list_for_each_sym(prop
->expr
, e
, sym
)
1206 sym
->flags
|= (SYMBOL_CHECK
| SYMBOL_CHECKED
);
1208 choice
->flags
|= (SYMBOL_CHECK
| SYMBOL_CHECKED
);
1209 sym2
= sym_check_sym_deps(choice
);
1210 choice
->flags
&= ~SYMBOL_CHECK
;
1214 expr_list_for_each_sym(prop
->expr
, e
, sym
) {
1215 sym2
= sym_check_sym_deps(sym
);
1220 expr_list_for_each_sym(prop
->expr
, e
, sym
)
1221 sym
->flags
&= ~SYMBOL_CHECK
;
1223 if (sym2
&& sym_is_choice_value(sym2
) &&
1224 prop_get_symbol(sym_get_choice_prop(sym2
)) == choice
)
1232 struct symbol
*sym_check_deps(struct symbol
*sym
)
1234 struct symbol
*sym2
;
1235 struct property
*prop
;
1237 if (sym
->flags
& SYMBOL_CHECK
) {
1238 sym_check_print_recursive(sym
);
1241 if (sym
->flags
& SYMBOL_CHECKED
)
1244 if (sym_is_choice_value(sym
)) {
1245 struct dep_stack stack
;
1247 /* for choice groups start the check with main choice symbol */
1248 dep_stack_insert(&stack
, sym
);
1249 prop
= sym_get_choice_prop(sym
);
1250 sym2
= sym_check_deps(prop_get_symbol(prop
));
1252 } else if (sym_is_choice(sym
)) {
1253 sym2
= sym_check_choice_deps(sym
);
1255 sym
->flags
|= (SYMBOL_CHECK
| SYMBOL_CHECKED
);
1256 sym2
= sym_check_sym_deps(sym
);
1257 sym
->flags
&= ~SYMBOL_CHECK
;
1260 if (sym2
&& sym2
== sym
)
1266 struct property
*prop_alloc(enum prop_type type
, struct symbol
*sym
)
1268 struct property
*prop
;
1269 struct property
**propp
;
1271 prop
= xmalloc(sizeof(*prop
));
1272 memset(prop
, 0, sizeof(*prop
));
1275 prop
->file
= current_file
;
1276 prop
->lineno
= zconf_lineno();
1278 /* append property to the prop list of symbol */
1280 for (propp
= &sym
->prop
; *propp
; propp
= &(*propp
)->next
)
1288 struct symbol
*prop_get_symbol(struct property
*prop
)
1290 if (prop
->expr
&& (prop
->expr
->type
== E_SYMBOL
||
1291 prop
->expr
->type
== E_LIST
))
1292 return prop
->expr
->left
.sym
;
1296 const char *prop_get_type_name(enum prop_type type
)