kconfig: fix broken target update-po-config
[safe/jmp/linux-2.6] / scripts / kconfig / symbol.c
index a7dfc82..4a03191 100644 (file)
@@ -34,6 +34,8 @@ struct symbol *sym_defconfig_list;
 struct symbol *modules_sym;
 tristate modules_val;
 
+struct expr *sym_env_list;
+
 void sym_add_default(struct symbol *sym, const char *def)
 {
        struct property *prop = prop_alloc(P_DEFAULT, sym);
@@ -45,7 +47,6 @@ void sym_init(void)
 {
        struct symbol *sym;
        struct utsname uts;
-       char *p;
        static bool inited = false;
 
        if (inited)
@@ -54,20 +55,6 @@ void sym_init(void)
 
        uname(&uts);
 
-       sym = sym_lookup("ARCH", 0);
-       sym->type = S_STRING;
-       sym->flags |= SYMBOL_AUTO;
-       p = getenv("ARCH");
-       if (p)
-               sym_add_default(sym, p);
-
-       sym = sym_lookup("KERNELVERSION", 0);
-       sym->type = S_STRING;
-       sym->flags |= SYMBOL_AUTO;
-       p = getenv("KERNELVERSION");
-       if (p)
-               sym_add_default(sym, p);
-
        sym = sym_lookup("UNAME_RELEASE", 0);
        sym->type = S_STRING;
        sym->flags |= SYMBOL_AUTO;
@@ -117,6 +104,15 @@ struct property *sym_get_choice_prop(struct symbol *sym)
        return NULL;
 }
 
+struct property *sym_get_env_prop(struct symbol *sym)
+{
+       struct property *prop;
+
+       for_all_properties(sym, prop, P_ENV)
+               return prop;
+       return NULL;
+}
+
 struct property *sym_get_default_prop(struct symbol *sym)
 {
        struct property *prop;
@@ -302,22 +298,30 @@ void sym_calc_value(struct symbol *sym)
                if (sym_is_choice_value(sym) && sym->visible == yes) {
                        prop = sym_get_choice_prop(sym);
                        newval.tri = (prop_get_symbol(prop)->curr.val == sym) ? yes : no;
-               } else if (EXPR_OR(sym->visible, sym->rev_dep.tri) != no) {
-                       sym->flags |= SYMBOL_WRITE;
-                       if (sym_has_value(sym))
-                               newval.tri = sym->def[S_DEF_USER].tri;
-                       else if (!sym_is_choice(sym)) {
-                               prop = sym_get_default_prop(sym);
-                               if (prop)
-                                       newval.tri = expr_calc_value(prop->expr);
+               } else {
+                       if (sym->visible != no) {
+                               /* if the symbol is visible use the user value
+                                * if available, otherwise try the default value
+                                */
+                               sym->flags |= SYMBOL_WRITE;
+                               if (sym_has_value(sym)) {
+                                       newval.tri = EXPR_AND(sym->def[S_DEF_USER].tri,
+                                                             sym->visible);
+                                       goto calc_newval;
+                               }
                        }
-                       newval.tri = EXPR_OR(EXPR_AND(newval.tri, sym->visible), sym->rev_dep.tri);
-               } else if (!sym_is_choice(sym)) {
-                       prop = sym_get_default_prop(sym);
-                       if (prop) {
+                       if (sym->rev_dep.tri != no)
                                sym->flags |= SYMBOL_WRITE;
-                               newval.tri = expr_calc_value(prop->expr);
+                       if (!sym_is_choice(sym)) {
+                               prop = sym_get_default_prop(sym);
+                               if (prop) {
+                                       sym->flags |= SYMBOL_WRITE;
+                                       newval.tri = EXPR_AND(expr_calc_value(prop->expr),
+                                                             prop->visible.tri);
+                               }
                        }
+               calc_newval:
+                       newval.tri = EXPR_OR(newval.tri, sym->rev_dep.tri);
                }
                if (newval.tri == mod && sym_get_type(sym) == S_BOOLEAN)
                        newval.tri = yes;
@@ -346,6 +350,9 @@ void sym_calc_value(struct symbol *sym)
                ;
        }
 
+       if (sym->flags & SYMBOL_AUTO)
+               sym->flags &= ~SYMBOL_WRITE;
+
        sym->curr = newval;
        if (sym_is_choice(sym) && newval.tri == yes)
                sym->curr.val = sym_calc_choice(sym);
@@ -860,6 +867,8 @@ const char *prop_get_type_name(enum prop_type type)
        switch (type) {
        case P_PROMPT:
                return "prompt";
+       case P_ENV:
+               return "env";
        case P_COMMENT:
                return "comment";
        case P_MENU:
@@ -877,3 +886,32 @@ const char *prop_get_type_name(enum prop_type type)
        }
        return "unknown";
 }
+
+void prop_add_env(const char *env)
+{
+       struct symbol *sym, *sym2;
+       struct property *prop;
+       char *p;
+
+       sym = current_entry->sym;
+       sym->flags |= SYMBOL_AUTO;
+       for_all_properties(sym, prop, P_ENV) {
+               sym2 = prop_get_symbol(prop);
+               if (strcmp(sym2->name, env))
+                       menu_warn(current_entry, "redefining environment symbol from %s",
+                                 sym2->name);
+               return;
+       }
+
+       prop = prop_alloc(P_ENV, sym);
+       prop->expr = expr_alloc_symbol(sym_lookup(env, 1));
+
+       sym_env_list = expr_alloc_one(E_LIST, sym_env_list);
+       sym_env_list->right.sym = sym;
+
+       p = getenv(env);
+       if (p)
+               sym_add_default(sym, p);
+       else
+               menu_warn(current_entry, "environment variable %s undefined", env);
+}