linux-kbuild.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/4] kconfig: store default ARCH in .config
@ 2014-09-01  7:16 Konstantin Khlebnikov
  2014-09-01  7:16 ` [PATCH v2 1/4] kconfig: save values imported from environment into config file Konstantin Khlebnikov
                   ` (5 more replies)
  0 siblings, 6 replies; 11+ messages in thread
From: Konstantin Khlebnikov @ 2014-09-01  7:16 UTC (permalink / raw)
  To: Michal Marek, linux-kernel, linux-kbuild; +Cc: Paul Bolle, Geert Uytterhoeven

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v2 1/4] kconfig: save values imported from environment into config file
  2014-09-01  7:16 [PATCH v2 0/4] kconfig: store default ARCH in .config Konstantin Khlebnikov
@ 2014-09-01  7:16 ` Konstantin Khlebnikov
  2014-09-01  7:16 ` [PATCH v2 2/4] scripts/config: add option for changing output for undefined options Konstantin Khlebnikov
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 11+ messages in thread
From: Konstantin Khlebnikov @ 2014-09-01  7:16 UTC (permalink / raw)
  To: Michal Marek, linux-kernel, linux-kbuild; +Cc: Paul Bolle, Geert Uytterhoeven

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.

Signed-off-by: Konstantin Khlebnikov <koct9i@gmail.com>
---
 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(-)

diff --git a/Documentation/kbuild/kconfig-language.txt b/Documentation/kbuild/kconfig-language.txt
index 350f733..0dad00a 100644
--- a/Documentation/kbuild/kconfig-language.txt
+++ b/Documentation/kbuild/kconfig-language.txt
@@ -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
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index f88d90f..5cb0034 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -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))
diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h
index 412ea8a..8d9bbc9 100644
--- a/scripts/kconfig/expr.h
+++ b/scripts/kconfig/expr.h
@@ -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 */
 
diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
index 7caabdb..9dce811 100644
--- a/scripts/kconfig/symbol.c
+++ b/scripts/kconfig/symbol.c
@@ -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);
 }


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 2/4] scripts/config: add option for changing output for undefined options
  2014-09-01  7:16 [PATCH v2 0/4] kconfig: store default ARCH in .config Konstantin Khlebnikov
  2014-09-01  7:16 ` [PATCH v2 1/4] kconfig: save values imported from environment into config file Konstantin Khlebnikov
@ 2014-09-01  7:16 ` Konstantin Khlebnikov
  2014-09-01  7:16 ` [PATCH v2 3/4] kconfig: get target architecture from config file Konstantin Khlebnikov
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 11+ messages in thread
From: Konstantin Khlebnikov @ 2014-09-01  7:16 UTC (permalink / raw)
  To: Michal Marek, linux-kernel, linux-kbuild; +Cc: Paul Bolle, Geert Uytterhoeven

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.

Signed-off-by: Konstantin Khlebnikov <koct9i@gmail.com>
---
 scripts/config |   15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/scripts/config b/scripts/config
index 026aeb4..178652c 100755
--- a/scripts/config
+++ b/scripts/config
@@ -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/#\"/}"


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 3/4] kconfig: get target architecture from config file
  2014-09-01  7:16 [PATCH v2 0/4] kconfig: store default ARCH in .config Konstantin Khlebnikov
  2014-09-01  7:16 ` [PATCH v2 1/4] kconfig: save values imported from environment into config file Konstantin Khlebnikov
  2014-09-01  7:16 ` [PATCH v2 2/4] scripts/config: add option for changing output for undefined options Konstantin Khlebnikov
@ 2014-09-01  7:16 ` Konstantin Khlebnikov
  2014-09-01  7:16 ` [PATCH v2 4/4] kconfig: link CONFIG_CROSS_COMPILE with environment variable Konstantin Khlebnikov
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 11+ messages in thread
From: Konstantin Khlebnikov @ 2014-09-01  7:16 UTC (permalink / raw)
  To: Michal Marek, linux-kernel, linux-kbuild; +Cc: Paul Bolle, Geert Uytterhoeven

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.

Signed-off-by: Konstantin Khlebnikov <koct9i@gmail.com>
---
 Documentation/kbuild/makefiles.txt |    3 ++-
 Makefile                           |   15 ++++++++++-----
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/Documentation/kbuild/makefiles.txt b/Documentation/kbuild/makefiles.txt
index 764f599..92cf95b 100644
--- a/Documentation/kbuild/makefiles.txt
+++ b/Documentation/kbuild/makefiles.txt
@@ -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:
 
diff --git a/Makefile b/Makefile
index 2893d7f..f648405 100644
--- a/Makefile
+++ b/Makefile
@@ -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; \


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 4/4] kconfig: link CONFIG_CROSS_COMPILE with environment variable
  2014-09-01  7:16 [PATCH v2 0/4] kconfig: store default ARCH in .config Konstantin Khlebnikov
                   ` (2 preceding siblings ...)
  2014-09-01  7:16 ` [PATCH v2 3/4] kconfig: get target architecture from config file Konstantin Khlebnikov
@ 2014-09-01  7:16 ` Konstantin Khlebnikov
  2014-09-03 21:11   ` Paul Bolle
  2014-09-01  7:24 ` [PATCH v2 0/4] kconfig: store default ARCH in .config Geert Uytterhoeven
  2014-10-27 17:20 ` Konstantin Khlebnikov
  5 siblings, 1 reply; 11+ messages in thread
From: Konstantin Khlebnikov @ 2014-09-01  7:16 UTC (permalink / raw)
  To: Michal Marek, linux-kernel, linux-kbuild; +Cc: Paul Bolle, Geert Uytterhoeven

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

Signed-off-by: Konstantin Khlebnikov <koct9i@gmail.com>
---
 Makefile     |    6 +++++-
 init/Kconfig |    1 +
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index f648405..1044f40 100644
--- a/Makefile
+++ b/Makefile
@@ -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)
diff --git a/init/Kconfig b/init/Kconfig
index e84c642..1c2f621 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -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


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 0/4] kconfig: store default ARCH in .config
  2014-09-01  7:16 [PATCH v2 0/4] kconfig: store default ARCH in .config Konstantin Khlebnikov
                   ` (3 preceding siblings ...)
  2014-09-01  7:16 ` [PATCH v2 4/4] kconfig: link CONFIG_CROSS_COMPILE with environment variable Konstantin Khlebnikov
@ 2014-09-01  7:24 ` Geert Uytterhoeven
  2014-09-01  7:35   ` Konstantin Khlebnikov
  2014-10-27 17:20 ` Konstantin Khlebnikov
  5 siblings, 1 reply; 11+ messages in thread
From: Geert Uytterhoeven @ 2014-09-01  7:24 UTC (permalink / raw)
  To: Konstantin Khlebnikov
  Cc: Michal Marek, linux-kernel, linux-kbuild, Paul Bolle

Hi Konstantin,

On Mon, Sep 1, 2014 at 9:16 AM, Konstantin Khlebnikov <koct9i@gmail.com> wrote:
> 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.

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 -- geert@linux-m68k.org

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 0/4] kconfig: store default ARCH in .config
  2014-09-01  7:24 ` [PATCH v2 0/4] kconfig: store default ARCH in .config Geert Uytterhoeven
@ 2014-09-01  7:35   ` Konstantin Khlebnikov
  0 siblings, 0 replies; 11+ messages in thread
From: Konstantin Khlebnikov @ 2014-09-01  7:35 UTC (permalink / raw)
  To: Geert Uytterhoeven; +Cc: Michal Marek, linux-kernel, linux-kbuild, Paul Bolle

On Mon, Sep 1, 2014 at 11:24 AM, Geert Uytterhoeven
<geert@linux-m68k.org> wrote:
> Hi Konstantin,
>
> On Mon, Sep 1, 2014 at 9:16 AM, Konstantin Khlebnikov <koct9i@gmail.com> wrote:
>> 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.
>
> 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.

>
> 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 -- geert@linux-m68k.org
>
> 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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 4/4] kconfig: link CONFIG_CROSS_COMPILE with environment variable
  2014-09-01  7:16 ` [PATCH v2 4/4] kconfig: link CONFIG_CROSS_COMPILE with environment variable Konstantin Khlebnikov
@ 2014-09-03 21:11   ` Paul Bolle
  2014-09-04  5:23     ` Konstantin Khlebnikov
  0 siblings, 1 reply; 11+ messages in thread
From: Paul Bolle @ 2014-09-03 21:11 UTC (permalink / raw)
  To: Konstantin Khlebnikov
  Cc: Michal Marek, linux-kernel, linux-kbuild, Geert Uytterhoeven

Hi Konstantin,

On Mon, 2014-09-01 at 11:16 +0400, Konstantin Khlebnikov wrote:
> 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
> 
> Signed-off-by: Konstantin Khlebnikov <koct9i@gmail.com>

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.

> ---
>  Makefile     |    6 +++++-
>  init/Kconfig |    1 +
>  2 files changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/Makefile b/Makefile
> index f648405..1044f40 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -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)
> diff --git a/init/Kconfig b/init/Kconfig
> index e84c642..1c2f621 100644
> --- a/init/Kconfig
> +++ b/init/Kconfig
> @@ -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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 4/4] kconfig: link CONFIG_CROSS_COMPILE with environment variable
  2014-09-03 21:11   ` Paul Bolle
@ 2014-09-04  5:23     ` Konstantin Khlebnikov
  0 siblings, 0 replies; 11+ messages in thread
From: Konstantin Khlebnikov @ 2014-09-04  5:23 UTC (permalink / raw)
  To: Paul Bolle
  Cc: Michal Marek, Linux Kernel Mailing List, linux-kbuild,
	Geert Uytterhoeven

On Thu, Sep 4, 2014 at 1:11 AM, Paul Bolle <pebolle@tiscali.nl> wrote:
> Hi Konstantin,
>
> On Mon, 2014-09-01 at 11:16 +0400, Konstantin Khlebnikov wrote:
>> 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
>>
>> Signed-off-by: Konstantin Khlebnikov <koct9i@gmail.com>
>
> 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.

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

>
>> ---
>>  Makefile     |    6 +++++-
>>  init/Kconfig |    1 +
>>  2 files changed, 6 insertions(+), 1 deletion(-)
>>
>> diff --git a/Makefile b/Makefile
>> index f648405..1044f40 100644
>> --- a/Makefile
>> +++ b/Makefile
>> @@ -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)
>> diff --git a/init/Kconfig b/init/Kconfig
>> index e84c642..1c2f621 100644
>> --- a/init/Kconfig
>> +++ b/init/Kconfig
>> @@ -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
>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 0/4] kconfig: store default ARCH in .config
  2014-09-01  7:16 [PATCH v2 0/4] kconfig: store default ARCH in .config Konstantin Khlebnikov
                   ` (4 preceding siblings ...)
  2014-09-01  7:24 ` [PATCH v2 0/4] kconfig: store default ARCH in .config Geert Uytterhoeven
@ 2014-10-27 17:20 ` Konstantin Khlebnikov
  2014-12-10 20:24   ` Paul Bolle
  5 siblings, 1 reply; 11+ messages in thread
From: Konstantin Khlebnikov @ 2014-10-27 17:20 UTC (permalink / raw)
  To: Michal Marek, Linux Kernel Mailing List, linux-kbuild
  Cc: Paul Bolle, Geert Uytterhoeven

Bump.

On Mon, Sep 1, 2014 at 11:16 AM, Konstantin Khlebnikov <koct9i@gmail.com> wrote:
> 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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 0/4] kconfig: store default ARCH in .config
  2014-10-27 17:20 ` Konstantin Khlebnikov
@ 2014-12-10 20:24   ` Paul Bolle
  0 siblings, 0 replies; 11+ messages in thread
From: Paul Bolle @ 2014-12-10 20:24 UTC (permalink / raw)
  To: Konstantin Khlebnikov
  Cc: Michal Marek, Linux Kernel Mailing List, linux-kbuild,
	Geert Uytterhoeven

Hi Konstantin,

On Mon, 2014-10-27 at 21:20 +0400, Konstantin Khlebnikov wrote:
> Bump.
> 
> On Mon, Sep 1, 2014 at 11:16 AM, Konstantin Khlebnikov <koct9i@gmail.com> wrote:
> > 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
---
diff --git a/Makefile b/Makefile
index ec2f22615d3d..a8bc3290f2e9 100644
--- a/Makefile
+++ b/Makefile
@@ -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; \
diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
index 7d09e029a779..77c8341af494 100644
--- a/scripts/kconfig/symbol.c
+++ b/scripts/kconfig/symbol.c
@@ -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);
+	}
 }


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2014-12-10 20:24 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-01  7:16 [PATCH v2 0/4] kconfig: store default ARCH in .config Konstantin Khlebnikov
2014-09-01  7:16 ` [PATCH v2 1/4] kconfig: save values imported from environment into config file Konstantin Khlebnikov
2014-09-01  7:16 ` [PATCH v2 2/4] scripts/config: add option for changing output for undefined options Konstantin Khlebnikov
2014-09-01  7:16 ` [PATCH v2 3/4] kconfig: get target architecture from config file Konstantin Khlebnikov
2014-09-01  7:16 ` [PATCH v2 4/4] kconfig: link CONFIG_CROSS_COMPILE with environment variable Konstantin Khlebnikov
2014-09-03 21:11   ` Paul Bolle
2014-09-04  5:23     ` Konstantin Khlebnikov
2014-09-01  7:24 ` [PATCH v2 0/4] kconfig: store default ARCH in .config Geert Uytterhoeven
2014-09-01  7:35   ` Konstantin Khlebnikov
2014-10-27 17:20 ` Konstantin Khlebnikov
2014-12-10 20:24   ` Paul Bolle

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).