Skip to contentSkip to conversation

kconfig CROSS_COMPILE option

PATCH In review [email protected] 1 participant 1 message Nov 4, 2009 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 4/4 kconfig CROSS_COMPILE option

From: Roland McGrath <[email protected]>

This adds CROSS_COMPILE as a kconfig string so you can store it in .config. Then you can use plain "make" in the configured kernel build directory to do the right cross compilation without setting the command-line or environment variable every time.

With this, you can set up different build directories for different kernel configurations, whether native or cross-builds, and then use the simple:

make -C /build/dir M=module-source-dir

idiom to build modules for any given target kernel, indicating which one by nothing but the build directory chosen.

I tried a version that defaults the string with env="CROSS_COMPILE" so that in a "make oldconfig" with CROSS_COMPILE in the environment you can just hit return to store the way you're building it. But the kconfig prompt for strings doesn't give you any way to say you want an empty string instead of the default, so I punted that.

---

 Makefile     |    3 +++
 init/Kconfig |    8 ++++++++
 2 files changed, 11 insertions(+)
Makefile renamed from Makefile~kconfig-cross_compile-option +3 -0
diff -puN Makefile~kconfig-cross_compile-option Makefile
@@ -177,11 +177,14 @@ SUBARCH := $(shell uname -m | sed -e s/i
 # CROSS_COMPILE can be set on the command line
 # make CROSS_COMPILE=ia64-linux-
 # Alternatively CROSS_COMPILE can be set in the environment.
+# A third alternative is to store a setting in .config so that plain
+# "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
 export KBUILD_BUILDHOST := $(SUBARCH)
 ARCH		?= $(SUBARCH)
 CROSS_COMPILE	?=
+CROSS_COMPILE	?= $(CONFIG_CROSS_COMPILE:"%"=%)
 
 # Architecture as present in compile.h
 UTS_MACHINE 	:= $(ARCH)
init/Kconfig renamed from init/Kconfig~kconfig-cross_compile-option +8 -0
diff -puN init/Kconfig~kconfig-cross_compile-option init/Kconfig
@@ -76,6 +76,14 @@ config INIT_ENV_ARG_LIMIT
 	  variables passed to init from the kernel command line.
 
 
+config CROSS_COMPILE
+	string "Cross-compiler tool prefix"
+	help
+	  Same as running 'make CROSS_COMPILE=prefix-' but stored for
+	  default make runs in this kernel build directory.  You don't
+	  need to set this unless you want the configured kernel build
+	  directory to select the cross-compiler automatically.
+
 config LOCALVERSION
 	string "Local version - append to kernel release"
 	help

_