2009-09-05 00:30:32

by Roland McGrath

[permalink] [raw]
Subject: [PATCH] kconfig CROSS_COMPILE option

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.

Signed-off-by: Roland McGrath <[email protected]>
CC: Sam Ravnborg <[email protected]>
---
Makefile | 4 +++-
init/Kconfig | 8 ++++++++
2 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/Makefile b/Makefile
index 25c615e..8f02b6e 100644
--- a/Makefile
+++ b/Makefile
@@ -177,11 +177,13 @@ SUBARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
# 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)
diff --git a/init/Kconfig b/init/Kconfig
index 3f7e609..452080d 100644
--- a/init/Kconfig
+++ b/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


2009-09-07 13:09:14

by Pavel Machek

[permalink] [raw]
Subject: Re: [PATCH] kconfig CROSS_COMPILE option

Hi!

> 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.

Yes that would be very nice. Editing Makefile every time I
crosscomppile for arm sucks.

But... do we need an option for subarch, too? And will Kconfig system
handle that?
Pavel

> # 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)
> diff --git a/init/Kconfig b/init/Kconfig
> index 3f7e609..452080d 100644

--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

2009-09-07 18:38:22

by Roland McGrath

[permalink] [raw]
Subject: Re: [PATCH] kconfig CROSS_COMPILE option

> Yes that would be very nice. Editing Makefile every time I
> crosscomppile for arm sucks.

The other trick I can recommend is to write a GNUmakefile containing:

ARCH=foo
CROSS_COMPILE=foo-linux-
include Makefile

(GNU make reads GNUmakefile in preference to Makefile.)
But this manual hackery is still not nearly as nice as the automagic way.

> But... do we need an option for subarch, too? And will Kconfig system
> handle that?

I'm not sure I follow exactly what your concern is. I am mostly familiar
with doing x86 and powerpc builds. For both of those, the kernel config
sets whether it's the 32-bit or 64-bit world.


Thanks,
Roland

2009-09-09 08:08:39

by Pavel Machek

[permalink] [raw]
Subject: Re: [PATCH] kconfig CROSS_COMPILE option

On Mon 2009-09-07 11:38:01, Roland McGrath wrote:
> > Yes that would be very nice. Editing Makefile every time I
> > crosscomppile for arm sucks.
>
> The other trick I can recommend is to write a GNUmakefile containing:
>
> ARCH=foo
> CROSS_COMPILE=foo-linux-
> include Makefile

Hehe, thanks.

> (GNU make reads GNUmakefile in preference to Makefile.)
> But this manual hackery is still not nearly as nice as the automagic way.
>
> > But... do we need an option for subarch, too? And will Kconfig system
> > handle that?
>
> I'm not sure I follow exactly what your concern is. I am mostly familiar
> with doing x86 and powerpc builds. For both of those, the kernel config
> sets whether it's the 32-bit or 64-bit world.

Well, my concern is that your patch allows me to set $CROSS_COMPILE,
but I need to set $ARCH too, to get useful result. So I can't actually
see how to use your patch.
Pavel

--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

2009-09-09 13:19:58

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH] kconfig CROSS_COMPILE option

On Mon, 7 Sep 2009, Roland McGrath wrote:
> > Yes that would be very nice. Editing Makefile every time I
> > crosscomppile for arm sucks.
>
> The other trick I can recommend is to write a GNUmakefile containing:
>
> ARCH=foo
> CROSS_COMPILE=foo-linux-
> include Makefile

Woow, that's shorter than mine :-)

--------------------------------------------------------------------------------

MAKEARGS = ARCH=powerpc CROSS_COMPILE=ppu- CC="ppu-gcc43 -m32 -mcpu=440"

MAKEFLAGS += --no-print-directory

.PHONY: all $(MAKECMDGOALS)

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

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

Makefile:;

$(all) %/: all
@:

--------------------------------------------------------------------------------

Note that in this example I also have to override CC, as (1) ppu-gcc is gcc
version 4.1.1, i.e. too old and (2) ppu-gcc43 defaults to -m64 and -mcpu=cell.

> (GNU make reads GNUmakefile in preference to Makefile.)
> But this manual hackery is still not nearly as nice as the automagic way.

Indeed, putting everything in .config would be more convenient.

With kind regards,

Geert Uytterhoeven
Software Architect
Techsoft Centre

Technology and Software Centre Europe
The Corporate Village ? Da Vincilaan 7-D1 ? B-1935 Zaventem ? Belgium

Phone: +32 (0)2 700 8453
Fax: +32 (0)2 700 8622
E-mail: [email protected]
Internet: http://www.sony-europe.com/

A division of Sony Europe (Belgium) N.V.
VAT BE 0413.825.160 ? RPR Brussels
Fortis ? BIC GEBABEBB ? IBAN BE41293037680010