kconfig: fix MODULES-related bug in case of no .config
[sfrench/cifs-2.6.git] / scripts / kconfig / confdata.c
index b55e72ff2fc676d4ae36ebe9028c6dee5b44d715..8dce5862550db06e857170fab294621dc17ecbf9 100644 (file)
@@ -170,8 +170,11 @@ int conf_read_simple(const char *name, int def)
                if (in)
                        goto load;
                sym_add_change_count(1);
-               if (!sym_defconfig_list)
+               if (!sym_defconfig_list) {
+                       if (modules_sym)
+                               sym_calc_value(modules_sym);
                        return 1;
+               }
 
                for_all_defaults(sym_defconfig_list, prop) {
                        if (expr_calc_value(prop->visible.expr) == no ||
@@ -677,7 +680,7 @@ int conf_write_autoconf(void)
        struct symbol *sym;
        const char *str;
        const char *name;
-       FILE *out, *out_h;
+       FILE *out, *tristate, *out_h;
        time_t now;
        int i, l;
 
@@ -692,9 +695,16 @@ int conf_write_autoconf(void)
        if (!out)
                return 1;
 
+       tristate = fopen(".tmpconfig_tristate", "w");
+       if (!tristate) {
+               fclose(out);
+               return 1;
+       }
+
        out_h = fopen(".tmpconfig.h", "w");
        if (!out_h) {
                fclose(out);
+               fclose(tristate);
                return 1;
        }
 
@@ -707,6 +717,9 @@ int conf_write_autoconf(void)
                     "# %s"
                     "#\n",
                     sym_get_string_value(sym), ctime(&now));
+       fprintf(tristate, "#\n"
+                         "# Automatically generated - do not edit\n"
+                         "\n");
        fprintf(out_h, "/*\n"
                       " * Automatically generated C config: don't edit\n"
                       " * Linux kernel version: %s\n"
@@ -727,10 +740,14 @@ int conf_write_autoconf(void)
                                break;
                        case mod:
                                fprintf(out, "CONFIG_%s=m\n", sym->name);
+                               fprintf(tristate, "CONFIG_%s=M\n", sym->name);
                                fprintf(out_h, "#define CONFIG_%s_MODULE 1\n", sym->name);
                                break;
                        case yes:
                                fprintf(out, "CONFIG_%s=y\n", sym->name);
+                               if (sym->type == S_TRISTATE)
+                                       fprintf(tristate, "CONFIG_%s=Y\n",
+                                                       sym->name);
                                fprintf(out_h, "#define CONFIG_%s 1\n", sym->name);
                                break;
                        }
@@ -772,13 +789,19 @@ int conf_write_autoconf(void)
                }
        }
        fclose(out);
+       fclose(tristate);
        fclose(out_h);
 
        name = getenv("KCONFIG_AUTOHEADER");
        if (!name)
-               name = "include/linux/autoconf.h";
+               name = "include/generated/autoconf.h";
        if (rename(".tmpconfig.h", name))
                return 1;
+       name = getenv("KCONFIG_TRISTATE");
+       if (!name)
+               name = "include/config/tristate.conf";
+       if (rename(".tmpconfig_tristate", name))
+               return 1;
        name = conf_get_autoconfig_name();
        /*
         * This must be the last step, kbuild has a dependency on auto.conf
@@ -842,7 +865,8 @@ void conf_set_all_new_symbols(enum conf_def_mode mode)
                                sym->def[S_DEF_USER].tri = no;
                                break;
                        case def_random:
-                               sym->def[S_DEF_USER].tri = (tristate)(rand() % 3);
+                               cnt = sym_get_type(sym) == S_TRISTATE ? 3 : 2;
+                               sym->def[S_DEF_USER].tri = (tristate)(rand() % cnt);
                                break;
                        default:
                                continue;