Skip to contentSkip to conversation

kconfig: store default ARCH in .config

PATCH In review Konstantin Khlebnikov 3 participants 11 messages Sep 1, 2014 – Dec 10, 2014

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover kconfig: store default ARCH in .config

This is second attempt of fixing target archecture amnesia. v1 patch: http://lkml.kernel.org/r/20140706080234.19520.96704.stgit@zurg

First version saved ARCH as CONFIG_DEFAULT_ARCH and used it as defult ARCH.

This version changes semantic of Kconfig option env="...", now it acts more like the user input, except that the value comes from the environment. Variable from environment overrides all defaults and value from config file. If environment variable is not defined this option has no effect.

So, now ARCH is saved as CONFIG_ARCH.

Also this patchset links CONFIG_CROSS_COMPILE and CROSS_COMPILE in the same way. Changing it in command line/environment also updates value in the config file.

---

Konstantin Khlebnikov (4):
kconfig: save values imported from environment into config file scripts/config: add option for changing output for undefined options
kconfig: get target architecture from config file
kconfig: link CONFIG_CROSS_COMPILE with environment variable

 Documentation/kbuild/kconfig-language.txt |   10 ++++------
 Documentation/kbuild/makefiles.txt        |    3 ++-
 Makefile                                  |   21 +++++++++++++++------
 init/Kconfig                              |    1 +
 scripts/config                            |   15 ++++++++++++---
 scripts/kconfig/confdata.c                |   26 ++++++++++++++++++++++++++
 scripts/kconfig/expr.h                    |    2 +-
 scripts/kconfig/symbol.c                  |    3 ---
 8 files changed, 61 insertions(+), 20 deletions(-)

--
Signature

#1 lore raw

PATCH v2 1/4 kconfig: save values imported from environment into config file

After this patch option env="..." behaves more like user input. Environment variable becomes optional, its last state is saved in config.

Impact of this change is minimal. This option is used only three times:
for ARCH, SRCARCH and KERNELVERSION. All of them are always defined by root Makefile.

---
 Documentation/kbuild/kconfig-language.txt |   10 ++++------
 scripts/kconfig/confdata.c                |   26 ++++++++++++++++++++++++++
 scripts/kconfig/expr.h                    |    2 +-
 scripts/kconfig/symbol.c                  |    3 ---
 4 files changed, 31 insertions(+), 10 deletions(-)
Documentation/kbuild/kconfig-language.txt +4 -6
index 350f733..0dad00a 100644
@@ -149,13 +149,11 @@ applicable everywhere (see syntax).
     enables the third modular state for all config symbols.
     At most one symbol may have the "modules" option set.
 
-  - "env"=<value>
+  - "env"=<varname>
     This imports the environment variable into Kconfig. It behaves like
-    a default, except that the value comes from the environment, this
-    also means that the behaviour when mixing it with normal defaults is
-    undefined at this point. The symbol is currently not exported back
-    to the build environment (if this is desired, it can be done via
-    another symbol).
+    the user input, except that the value comes from the environment.
+    Environment variable overrides all defaults and value from the file.
+    If environment variable is not defined this option has no effect.
 
   - "allnoconfig_y"
     This declares the symbol as one that should have the value y when
scripts/kconfig/confdata.c +26 -0
index f88d90f..5cb0034 100644
@@ -404,6 +404,30 @@ setsym:
 	return 0;
 }
 
+static void conf_read_env(void)
+{
+	struct symbol *sym, *env_sym;
+	struct property *prop;
+	struct expr *expr;
+	char *value;
+
+	expr_list_for_each_sym(sym_env_list, expr, sym) {
+		prop = sym_get_env_prop(sym);
+		env_sym = prop_get_symbol(prop);
+		value = getenv(env_sym->name);
+		if (value) {
+			sym_calc_value(sym);
+			if (!sym_set_string_value(sym, value))
+				conf_warning("evironment variable %s value "
+					      "'%s' invalid for %s",
+					      env_sym->name, value, sym->name);
+		} else if (!(sym->flags & SYMBOL_DEF_USER))
+			conf_warning("neither symbol %s nor evironment "
+					"variable %s are defined",
+				       sym->name, env_sym->name);
+	}
+}
+
 int conf_read(const char *name)
 {
 	struct symbol *sym;
@@ -414,6 +438,8 @@ int conf_read(const char *name)
 	if (conf_read_simple(name, S_DEF_USER))
 		return 1;
 
+	conf_read_env();
+
 	for_all_symbols(i, sym) {
 		sym_calc_value(sym);
 		if (sym_is_choice(sym) || (sym->flags & SYMBOL_AUTO))
scripts/kconfig/expr.h +1 -1
index 412ea8a..8d9bbc9 100644
@@ -95,7 +95,7 @@ struct symbol {
 #define SYMBOL_OPTIONAL   0x0100  /* choice is optional - values can be 'n' */
 #define SYMBOL_WRITE      0x0200  /* write symbol to file (KCONFIG_CONFIG) */
 #define SYMBOL_CHANGED    0x0400  /* ? */
-#define SYMBOL_AUTO       0x1000  /* value from environment variable */
+#define SYMBOL_AUTO       0x1000  /* calculated value - not saved into file */
 #define SYMBOL_CHECKED    0x2000  /* used during dependency checking */
 #define SYMBOL_WARNED     0x8000  /* warning has been issued */
 
scripts/kconfig/symbol.c +0 -3
index 7caabdb..9dce811 100644
@@ -1350,7 +1350,6 @@ static void prop_add_env(const char *env)
 	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))
@@ -1368,6 +1367,4 @@ static void prop_add_env(const char *env)
 	p = getenv(env);
 	if (p)
 		sym_add_default(sym, p);
-	else
-		menu_warn(current_entry, "environment variable %s undefined", env);
 }
#2 lore raw

PATCH v2 2/4 scripts/config: add option for changing output for undefined options

In reply to Konstantin Khlebnikov

This patch adds command line option '--if-undef' which replaces string 'undef' in output of next command '--state' with whatever you want.

Also it adds grep key -s to suppress error messages about nonexistent file.

---
 scripts/config |   15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
scripts/config +12 -3
index 026aeb4..178652c 100755
@@ -6,6 +6,9 @@ myname=${0##*/}
 # If no prefix forced, use the default CONFIG_
 CONFIG_="${CONFIG_-CONFIG_}"
 
+# Output for undefined options
+UNDEF="undef"
+
 usage() {
 	cat >&2 <<EOL
 Manipulate options in a .config file from the command line.
@@ -34,6 +37,7 @@ commands:
 options:
 	--file config-file   .config file to change (default .config)
 	--keep-case|-k       Keep next symbols' case (dont' upper-case it)
+	--if-undef string    Print this string instead of state "undef"
 
 $myname doesn't check the validity of the .config file. This is done at next
 make time.
@@ -152,6 +156,11 @@ while [ "$1" != "" ] ; do
 		B=$ARG
 		shift 2
 		;;
+	--if-undef)
+		UNDEF=$1
+		shift
+		continue
+		;;
 	-*)
 		checkarg "$1"
 		shift
@@ -185,12 +194,12 @@ while [ "$1" != "" ] ; do
 		;;
 
 	--state|-s)
-		if grep -q "# ${CONFIG_}$ARG is not set" $FN ; then
+		if grep -sq "# ${CONFIG_}$ARG is not set" $FN ; then
 			echo n
 		else
-			V="$(grep "^${CONFIG_}$ARG=" $FN)"
+			V="$(grep -s "^${CONFIG_}$ARG=" $FN)"
 			if [ $? != 0 ] ; then
-				echo undef
+				echo "${UNDEF}"
 			else
 				V="${V/#${CONFIG_}$ARG=/}"
 				V="${V/#\"/}"
#3 lore raw

PATCH v2 3/4 kconfig: get target architecture from config file

In reply to Konstantin Khlebnikov

This patch makes kernel cross-compilation little bit easier. After initial configuration no special environment variables are required because default ARCH is saved in .config file:

# make ARCH=arm defconfig
# make menuconfig
# make

To solve chicken and egg problem ARCH is read directly from config file.

---
 Documentation/kbuild/makefiles.txt |    3 ++-
 Makefile                           |   15 ++++++++++-----
 2 files changed, 12 insertions(+), 6 deletions(-)
Documentation/kbuild/makefiles.txt +2 -1
index 764f599..92cf95b 100644
@@ -1365,7 +1365,8 @@ The top Makefile exports the following variables:
 	"arm", or "sparc". Some kbuild Makefiles test $(ARCH) to
 	determine which files to compile.
 
-	By default, the top Makefile sets $(ARCH) to be the same as the
+	By default $(ARCH) is set by option CONFIG_ARCH in .config,
+	default for it is set by top Makefile to be the same as the
 	host system architecture.  For a cross build, a user may
 	override the value of $(ARCH) on the command line:
 
Makefile +10 -5
index 2893d7f..f648405 100644
@@ -220,6 +220,8 @@ VPATH		:= $(srctree)$(if $(KBUILD_EXTMOD),:$(KBUILD_EXTMOD))
 
 export srctree objtree VPATH
 
+KCONFIG_CONFIG	?= .config
+export KCONFIG_CONFIG
 
 # SUBARCH tells the usermode build what the underlying arch is.  That is set
 # first, and if a usermode build is happening, the "ARCH=um" on the command
@@ -242,7 +244,14 @@ SUBARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \
 # ARCH can be set during invocation of make:
 # make ARCH=ia64
 # Another way is to have ARCH set in the environment.
-# The default ARCH is the host where make is executed.
+# Usually default value is saved in .config as CONFIG_ARCH.
+# If this option is undefined or config file does not exist
+# ARCH is set to the host where make is executed.
+ifndef ARCH
+	ARCH := $(shell $(srctree)/scripts/config \
+				--file $(KBUILD_OUTPUT)$(KCONFIG_CONFIG) \
+				--if-undef "$(SUBARCH)" --state "ARCH")
+endif
 
 # CROSS_COMPILE specify the prefix used for all executables used
 # during compilation. Only gcc and related bin-utils executables
@@ -254,7 +263,6 @@ SUBARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \
 # "make" in the configured kernel build directory always uses that.
 # Default value for CROSS_COMPILE is not to prefix executables
 # Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
-ARCH		?= $(SUBARCH)
 CROSS_COMPILE	?= $(CONFIG_CROSS_COMPILE:"%"=%)
 
 # Architecture as present in compile.h
@@ -293,9 +301,6 @@ endif
 # Where to locate arch specific headers
 hdr-arch  := $(SRCARCH)
 
-KCONFIG_CONFIG	?= .config
-export KCONFIG_CONFIG
-
 # SHELL used by kbuild
 CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
 	  else if [ -x /bin/bash ]; then echo /bin/bash; \
#4 lore raw

PATCH v2 4/4 kconfig: link CONFIG_CROSS_COMPILE with environment variable

In reply to Konstantin Khlebnikov

Cross-compiler tool prefix can be set in command line, in the environment variable CROSS_COMPILE or in config file, in option CONFIG_COROSS_COMPILE. Also some arch/*/Makefile provides default value.

This patch links config option CONFIG_CROSS_COMPILE and variable CROSS_COMPILE in both directions: environment/command line has higher priority and updates value saved in the config file, config option acts as default value for it.

This is especially useful together with option O=dir which allows to create separate directory for each target architecture and kernel flavor:

# make O=build/arm ARCH=arm CROSS_COMPILE=arm-none-eabi- defconfig
# make -C build/arm
---
 Makefile     |    6 +++++-
 init/Kconfig |    1 +
 2 files changed, 6 insertions(+), 1 deletion(-)
Makefile +5 -1
index f648405..1044f40 100644
@@ -263,7 +263,11 @@ endif
 # "make" in the configured kernel build directory always uses that.
 # Default value for CROSS_COMPILE is not to prefix executables
 # Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
-CROSS_COMPILE	?= $(CONFIG_CROSS_COMPILE:"%"=%)
+ifndef CROSS_COMPILE
+	CROSS_COMPILE := $(shell $(srctree)/scripts/config \
+				--file $(KBUILD_OUTPUT)$(KCONFIG_CONFIG) \
+				--if-undef "" --state "CROSS_COMPILE")
+endif
 
 # Architecture as present in compile.h
 UTS_MACHINE 	:= $(ARCH)
init/Kconfig +1 -0
index e84c642..1c2f621 100644
@@ -47,6 +47,7 @@ config INIT_ENV_ARG_LIMIT
 
 config CROSS_COMPILE
 	string "Cross-compiler tool prefix"
+	option env="CROSS_COMPILE"
 	help
 	  Same as running 'make CROSS_COMPILE=prefix-' but stored for
 	  default make runs in this kernel build directory.  You don't
#5 lore raw

Re: [PATCH v2 4/4] kconfig: link CONFIG_CROSS_COMPILE with environment variable

Hi Konstantin,

Quoted 8 lines · Konstantin Khlebnikov

Cross-compiler tool prefix can be set in command line, in the environment variable CROSS_COMPILE or in config file, in option CONFIG_COROSS_COMPILE. Also some arch/*/Makefile provides default value.

This patch links config option CONFIG_CROSS_COMPILE and variable CROSS_COMPILE in both directions: environment/command line has higher priority and updates value saved in the config file, config option acts as default value for it.

Quoted 7 lines

This is especially useful together with option O=dir which allows to create separate directory for each target architecture and kernel flavor:

# make O=build/arm ARCH=arm CROSS_COMPILE=arm-none-eabi- defconfig
# make -C build/arm

I have only had a quick glance at this series. Just a quick question to help me understand where it is going.

Would this patch mean that, if a (def)config file has both ARCH and CROSS_COMPILE set, one could use that (def)config file and invoke "make $whatever_target" and expect it to do the right thing (provided a suitable cross compiler is installed)?

This implies cross compiler prefixes are standardized across distributions, I guess. Maybe they're not.

Quoted 28 lines
---
 Makefile     |    6 +++++-
 init/Kconfig |    1 +
 2 files changed, 6 insertions(+), 1 deletion(-)
Makefile +5 -1
index f648405..1044f40 100644
@@ -263,7 +263,11 @@ endif
 # "make" in the configured kernel build directory always uses that.
 # Default value for CROSS_COMPILE is not to prefix executables
 # Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
-CROSS_COMPILE	?= $(CONFIG_CROSS_COMPILE:"%"=%)
+ifndef CROSS_COMPILE
+	CROSS_COMPILE := $(shell $(srctree)/scripts/config \
+				--file $(KBUILD_OUTPUT)$(KCONFIG_CONFIG) \
+				--if-undef "" --state "CROSS_COMPILE")
+endif
 
 # Architecture as present in compile.h
 UTS_MACHINE 	:= $(ARCH)
init/Kconfig +0 -0
index e84c642..1c2f621 100644

init/Kconfig config INIT_ENV_ARG_LIMIT · line 53

Quoted 7 lines
init/Kconfig +1 -0
@@ -47,6 +47,7 @@ config INIT_ENV_ARG_LIMIT
 
 config CROSS_COMPILE
 	string "Cross-compiler tool prefix"
+	option env="CROSS_COMPILE"
 	help
 	  Same as running 'make CROSS_COMPILE=prefix-' but stored for
 	  default make runs in this kernel build directory.  You don't

Paul Bolle

#6 lore raw

Re: [PATCH v2 4/4] kconfig: link CONFIG_CROSS_COMPILE with environment variable

Quoted 22 lines · Paul Bolle

Hi Konstantin,

Quoted 8 lines · Konstantin Khlebnikov

Cross-compiler tool prefix can be set in command line, in the environment variable CROSS_COMPILE or in config file, in option CONFIG_COROSS_COMPILE. Also some arch/*/Makefile provides default value.

This patch links config option CONFIG_CROSS_COMPILE and variable CROSS_COMPILE in both directions: environment/command line has higher priority and updates value saved in the config file, config option acts as default value for it.

Quoted 7 lines

This is especially useful together with option O=dir which allows to create separate directory for each target architecture and kernel flavor:

# make O=build/arm ARCH=arm CROSS_COMPILE=arm-none-eabi- defconfig
# make -C build/arm

I have only had a quick glance at this series. Just a quick question to help me understand where it is going.

Quoted 7 lines

Would this patch mean that, if a (def)config file has both ARCH and CROSS_COMPILE set, one could use that (def)config file and invoke "make $whatever_target" and expect it to do the right thing (provided a suitable cross compiler is installed)?

This implies cross compiler prefixes are standardized across distributions, I guess. Maybe they're not.

As I know they are not strictly standardized.
Naming convention is arch[-vendor][-os]-abi, but there is a lot of possible combinations.

Quoted 40 lines
Quoted 29 lines
---
 Makefile     |    6 +++++-
 init/Kconfig |    1 +
 2 files changed, 6 insertions(+), 1 deletion(-)
Makefile +5 -1
index f648405..1044f40 100644
@@ -263,7 +263,11 @@ endif
 # "make" in the configured kernel build directory always uses that.
 # Default value for CROSS_COMPILE is not to prefix executables
 # Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
-CROSS_COMPILE        ?= $(CONFIG_CROSS_COMPILE:"%"=%)
+ifndef CROSS_COMPILE
+     CROSS_COMPILE := $(shell $(srctree)/scripts/config \
+                             --file $(KBUILD_OUTPUT)$(KCONFIG_CONFIG) \
+                             --if-undef "" --state "CROSS_COMPILE")
+endif
 
 # Architecture as present in compile.h
 UTS_MACHINE  := $(ARCH)
init/Kconfig +0 -0
index e84c642..1c2f621 100644

init/Kconfig config INIT_ENV_ARG_LIMIT · line 53

Quoted 7 lines
init/Kconfig +1 -0
@@ -47,6 +47,7 @@ config INIT_ENV_ARG_LIMIT
 
 config CROSS_COMPILE
      string "Cross-compiler tool prefix"
+     option env="CROSS_COMPILE"
      help
        Same as running 'make CROSS_COMPILE=prefix-' but stored for
        default make runs in this kernel build directory.  You don't

Paul Bolle

#7 lore raw
In reply to Konstantin Khlebnikov

Hi Konstantin,

Quoted 10 lines · Konstantin Khlebnikov

This is second attempt of fixing target archecture amnesia. v1 patch: http://lkml.kernel.org/r/20140706080234.19520.96704.stgit@zurg

First version saved ARCH as CONFIG_DEFAULT_ARCH and used it as defult ARCH.

This version changes semantic of Kconfig option env="...", now it acts more like the user input, except that the value comes from the environment. Variable from environment overrides all defaults and value from config file. If environment variable is not defined this option has no effect.

Quoted 4 lines

So, now ARCH is saved as CONFIG_ARCH.

Also this patchset links CONFIG_CROSS_COMPILE and CROSS_COMPILE in the same way. Changing it in command line/environment also updates value in the config file.

Thanks, I haven't tried this yet, but it looks promising!

For the record, right now I use a GNUmakefile (which takes precedence over the Makefile) in the build directory containing e.g.

MAKEARGS = ARCH=arm CROSS_COMPILE=arm-unknown-linux-gnueabi-

MAKEFLAGS += --no-print-directory

.PHONY: all $(MAKECMDGOALS)

all := $(filter-out all Makefile,$(MAKECMDGOALS))

all:

        $(MAKE) $(MAKEARGS) $(all) -f Makefile

Makefile:;

$(all) %/: all

        @:

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#8 lore raw
Quoted 15 lines · Geert Uytterhoeven

Hi Konstantin,

Quoted 12 lines · Konstantin Khlebnikov

This is second attempt of fixing target archecture amnesia. v1 patch: http://lkml.kernel.org/r/20140706080234.19520.96704.stgit@zurg

First version saved ARCH as CONFIG_DEFAULT_ARCH and used it as defult ARCH.

This version changes semantic of Kconfig option env="...", now it acts more like the user input, except that the value comes from the environment. Variable from environment overrides all defaults and value from config file. If environment variable is not defined this option has no effect.

So, now ARCH is saved as CONFIG_ARCH.

Quoted 7 lines
Quoted 2 lines

Also this patchset links CONFIG_CROSS_COMPILE and CROSS_COMPILE in the same way. Changing it in command line/environment also updates value in the config file.

Thanks, I haven't tried this yet, but it looks promising!

For the record, right now I use a GNUmakefile (which takes precedence over the Makefile) in the build directory containing e.g.

Heh, I've used and seen a lot of such hacks.
GNUmakefile also might include Makefile after defining environment.

Quoted 27 lines

MAKEARGS = ARCH=arm CROSS_COMPILE=arm-unknown-linux-gnueabi-

MAKEFLAGS += --no-print-directory

.PHONY: all $(MAKECMDGOALS)

all := $(filter-out all Makefile,$(MAKECMDGOALS))

all:

        $(MAKE) $(MAKEARGS) $(all) -f Makefile

Makefile:;

$(all) %/: all

        @:

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#9 lore raw
In reply to Konstantin Khlebnikov

Bump.

Quoted 36 lines · Konstantin Khlebnikov

This is second attempt of fixing target archecture amnesia. v1 patch: http://lkml.kernel.org/r/20140706080234.19520.96704.stgit@zurg

First version saved ARCH as CONFIG_DEFAULT_ARCH and used it as defult ARCH.

This version changes semantic of Kconfig option env="...", now it acts more like the user input, except that the value comes from the environment. Variable from environment overrides all defaults and value from config file. If environment variable is not defined this option has no effect.

So, now ARCH is saved as CONFIG_ARCH.

Also this patchset links CONFIG_CROSS_COMPILE and CROSS_COMPILE in the same way. Changing it in command line/environment also updates value in the config file.

---

Konstantin Khlebnikov (4):
kconfig: save values imported from environment into config file scripts/config: add option for changing output for undefined options
kconfig: get target architecture from config file
kconfig: link CONFIG_CROSS_COMPILE with environment variable

 Documentation/kbuild/kconfig-language.txt |   10 ++++------
 Documentation/kbuild/makefiles.txt        |    3 ++-
 Makefile                                  |   21 +++++++++++++++------
 init/Kconfig                              |    1 +
 scripts/config                            |   15 ++++++++++++---
 scripts/kconfig/confdata.c                |   26 ++++++++++++++++++++++++++
 scripts/kconfig/expr.h                    |    2 +-
 scripts/kconfig/symbol.c                  |    3 ---
 8 files changed, 61 insertions(+), 20 deletions(-)

--
Signature

#10 lore raw

Hi Konstantin,

Quoted 36 lines · Konstantin Khlebnikov

Bump.

Quoted 33 lines · Konstantin Khlebnikov

This is second attempt of fixing target archecture amnesia. v1 patch: http://lkml.kernel.org/r/20140706080234.19520.96704.stgit@zurg

First version saved ARCH as CONFIG_DEFAULT_ARCH and used it as defult ARCH.

This version changes semantic of Kconfig option env="...", now it acts more like the user input, except that the value comes from the environment. Variable from environment overrides all defaults and value from config file. If environment variable is not defined this option has no effect.

So, now ARCH is saved as CONFIG_ARCH.

Also this patchset links CONFIG_CROSS_COMPILE and CROSS_COMPILE in the same way. Changing it in command line/environment also updates value in the config file.

---

Konstantin Khlebnikov (4):
kconfig: save values imported from environment into config file scripts/config: add option for changing output for undefined options
kconfig: get target architecture from config file
kconfig: link CONFIG_CROSS_COMPILE with environment variable

 Documentation/kbuild/kconfig-language.txt |   10 ++++------
 Documentation/kbuild/makefiles.txt        |    3 ++-
 Makefile                                  |   21 +++++++++++++++------
 init/Kconfig                              |    1 +
 scripts/config                            |   15 ++++++++++++---
 scripts/kconfig/confdata.c                |   26 ++++++++++++++++++++++++++
 scripts/kconfig/expr.h                    |    2 +-
 scripts/kconfig/symbol.c                  |    3 ---
 8 files changed, 61 insertions(+), 20 deletions(-)

It's been a few months since you submitted this series and you've received little feedback. So I tried to review this series. That didn't go too well. Mainly because the kconfig code makes answering questions like "What does sym_calc_value() actually do?" harder than it should be. (And because make and the kernel Makefiles scare me, but I don't like to admit that.)

Anyhow, I think what you want to accomplish, is basically to save make's ARCH as CONFIG_ARCH and, likewise, save make's CROSS_COMPILE as CONFIG_CROSS_COMPILE. You jump through quite a few hoops to do that in this series.

Now I'm not clear whether saving those variables should actually be done. But I did cobble together a much smaller _hack_ that seems to achieve what you want. I've pasted it at the end of this message. It's lightly tested on top of today's linux-next. (Does it break building UML?) But does it do what you basically care about?

Paul Bolle
---

Makefile +7 -3
index ec2f22615d3d..a8bc3290f2e9 100644
@@ -228,6 +228,9 @@ SUBARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \
 				  -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
 				  -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ )
 
+KCONFIG_CONFIG	?= .config
+export KCONFIG_CONFIG
+
 # Cross compiling and selecting different set of gcc/bin-utils
 # ---------------------------------------------------------------------------
 #
@@ -248,6 +251,10 @@ SUBARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \
 # "make" in the configured kernel build directory always uses that.
 # Default value for CROSS_COMPILE is not to prefix executables
 # Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
+ARCH		?= $(shell grep -s ^CONFIG_ARCH= $(KCONFIG_CONFIG) | sed -e s/^CONFIG_ARCH=// -e s/\"//g)
+ifeq ($(ARCH),)
+        undefine ARCH
+endif
 ARCH		?= $(SUBARCH)
 CROSS_COMPILE	?= $(CONFIG_CROSS_COMPILE:"%"=%)
 
@@ -287,9 +294,6 @@ endif
 # Where to locate arch specific headers
 hdr-arch  := $(SRCARCH)
 
-KCONFIG_CONFIG	?= .config
-export KCONFIG_CONFIG
-
 # SHELL used by kbuild
 CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
 	  else if [ -x /bin/bash ]; then echo /bin/bash; \
scripts/kconfig/symbol.c +6 -2
index 7d09e029a779..77c8341af494 100644
@@ -1364,8 +1364,12 @@ static void prop_add_env(const char *env)
 	sym_env_list->right.sym = sym;
 
 	p = getenv(env);
-	if (p)
+	if (p) {
 		sym_add_default(sym, p);
-	else
+		if ((strcmp(sym->name, "ARCH") == 0) ||
+		    (strcmp(sym->name, "CROSS_COMPILE") == 0))
+			sym->flags &= ~SYMBOL_AUTO;
+	} else {
 		menu_warn(current_entry, "environment variable %s undefined", env);
+	}
 }