# Architecture as present in compile.h
 UTS_MACHINE := $(ARCH)
 
+KCONFIG_CONFIG ?= .config
+
 # SHELL used by kbuild
 CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
          else if [ -x /bin/bash ]; then echo /bin/bash; \
 -include include/config/auto.conf
 
 # To avoid any implicit rule to kick in, define an empty command
-.config include/config/auto.conf.cmd: ;
+$(KCONFIG_CONFIG) include/config/auto.conf.cmd: ;
 
 # If .config is newer than include/config/auto.conf, someone tinkered
 # with it and forgot to run make oldconfig.
 # if auto.conf.cmd is missing then we are probarly in a cleaned tree so
 # we execute the config step to be sure to catch updated Kconfig files
-include/config/auto.conf: .config include/config/auto.conf.cmd
+include/config/auto.conf: $(KCONFIG_CONFIG) include/config/auto.conf.cmd
        $(Q)$(MAKE) -f $(srctree)/Makefile silentoldconfig
 
 else
 
 static const char *conf_filename;
 static int conf_lineno, conf_warnings, conf_unsaved;
 
-const char conf_def_filename[] = ".config";
-
 const char conf_defname[] = "arch/$ARCH/defconfig";
 
 static void conf_warning(const char *fmt, ...)
        conf_warnings++;
 }
 
+const char *conf_get_configname(void)
+{
+       char *name = getenv("KCONFIG_CONFIG");
+
+       return name ? name : ".config";
+}
+
 static char *conf_expand_value(const char *in)
 {
        struct symbol *sym;
        } else {
                struct property *prop;
 
-               name = conf_def_filename;
+               name = conf_get_configname();
                in = zconf_fopen(name);
                if (in)
                        goto load;
                if (!stat(name, &st) && S_ISDIR(st.st_mode)) {
                        strcpy(dirname, name);
                        strcat(dirname, "/");
-                       basename = conf_def_filename;
+                       basename = conf_get_configname();
                } else if ((slash = strrchr(name, '/'))) {
                        int size = slash - name + 1;
                        memcpy(dirname, name, size);
                        if (slash[1])
                                basename = slash + 1;
                        else
-                               basename = conf_def_filename;
+                               basename = conf_get_configname();
                } else
                        basename = name;
        } else
-               basename = conf_def_filename;
+               basename = conf_get_configname();
 
-       sprintf(newname, "%s.tmpconfig.%d", dirname, (int)getpid());
-       out = fopen(newname, "w");
+       sprintf(newname, "%s%s", dirname, basename);
+       env = getenv("KCONFIG_OVERWRITECONFIG");
+       if (!env || !*env) {
+               sprintf(tmpname, "%s.tmpconfig.%d", dirname, (int)getpid());
+               out = fopen(tmpname, "w");
+       } else {
+               *tmpname = 0;
+               out = fopen(newname, "w");
+       }
        if (!out)
                return 1;
+
        sym = sym_lookup("KERNELVERSION", 0);
        sym_calc_value(sym);
        time(&now);
                }
        }
        fclose(out);
-       if (!name || basename != conf_def_filename) {
-               if (!name)
-                       name = conf_def_filename;
-               sprintf(tmpname, "%s.old", name);
-               rename(name, tmpname);
+
+       if (*tmpname) {
+               strcat(dirname, name ? name : conf_get_configname());
+               strcat(dirname, ".old");
+               rename(newname, dirname);
+               if (rename(tmpname, newname))
+                       return 1;
        }
-       sprintf(tmpname, "%s%s", dirname, basename);
-       if (rename(newname, tmpname))
-               return 1;
 
        printf(_("#\n"
                 "# configuration written to %s\n"
-                "#\n"), tmpname);
+                "#\n"), newname);
 
        sym_change_count = 0;