slightly enhance cross builds
PATCH 1/1 slightly enhance cross builds
This adds functionality to default CROSS_COMPILE to a sensible value when cross-building (so one doesn't always have to specify this on the make command line), as well as storing ARCH and SUBARCH in the Makefile
generated when building outside of the source directory (so that subsequent make invocations don't have to always repeat these).
From: Jan Beulich <[email protected]>
(actual patch attached)
This adds functionality to default CROSS_COMPILE to a sensible value when cross-building (so one doesn't always have to specify this on the make command line), as well as storing ARCH and SUBARCH in the Makefile generated when building outside of the source directory (so that subsequent make invocations don't have to always repeat these).
From: Jan Beulich <[email protected]>
Makefile renamed from home/jbeulich/tmp/linux-2.6.14/Makefile +19 -12
@@ -160,15 +160,19 @@ LOCALVERSION = $(subst $(space),, \ KERNELRELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)$(LOCALVERSION) +HOSTARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \ + -e s/arm.*/arm/ -e s/sa110/arm/ \ + -e s/s390x/s390/ -e s/parisc64/parisc/ ) + # 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 # line overrides the setting of ARCH below. If a native build is happening, # then ARCH is assigned, getting whatever value it gets normally, and # SUBARCH is subsequently ignored. -SUBARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \ - -e s/arm.*/arm/ -e s/sa110/arm/ \ - -e s/s390x/s390/ -e s/parisc64/parisc/ ) +ifeq ($(SUBARCH),) +SUBARCH := $(if $(filter-out um xen,$(ARCH)),$(ARCH),$(HOSTARCH)) +endif # Cross compiling and selecting different set of gcc/bin-utils # ---------------------------------------------------------------------------
@@ -190,7 +198,7 @@ SUBARCH := $(shell uname -m | sed -e s/i # Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile ARCH ?= $(SUBARCH) -CROSS_COMPILE ?= +CROSS_COMPILE ?= $(if $(filter-out $(ARCH) $(SUBARCH),$(HOSTARCH)),$(SUBARCH)-linux-) # Architecture as present in compile.h UTS_MACHINE := $(ARCH)
@@ -386,16 +395,19 @@ scripts_basic: scripts/basic/%: scripts_basic ; .PHONY: outputmakefile -# outputmakefile generate a Makefile to be placed in output directory, if -# using a seperate output directory. This allows convinient use -# of make in output directory +# outputmakefile generates a Makefile in the output directory, if +# using a separate output directory. This allows convenient use +# of make in the output directory. outputmakefile: - $(Q)if test ! $(srctree) -ef $(objtree); then \ - $(CONFIG_SHELL) $(srctree)/scripts/mkmakefile \ - $(srctree) $(objtree) $(VERSION) $(PATCHLEVEL) \ - > $(objtree)/Makefile; \ - echo ' GEN $(objtree)/Makefile'; \ +ifneq ($(KBUILD_SRC),) + $(Q)if [ ! -r $(objtree)/Makefile -o -O $(objtree)/Makefile ]; then \ + echo ' GEN $(objtree)/Makefile'; \ + $(CONFIG_SHELL) $(srctree)/scripts/mkmakefile \ + $(srctree) $(objtree) $(VERSION) $(PATCHLEVEL) \ + $(ARCH) $(SUBARCH) $(HOSTARCH) \ + > $(objtree)/Makefile; \ fi +endif # To make sure we do not include .config for any of the *config targets # catch them early, and hand them over to scripts/kconfig/Makefile
scripts/mkmakefile renamed from home/jbeulich/tmp/linux-2.6.14/scripts/mkmakefile +8 -2
@@ -8,6 +8,9 @@ # $2 - Output directory # $3 - version # $4 - patchlevel +# $5 - architecture +# $6 - sub-architecture +# $7 - host architecture cat << EOF
@@ -20,12 +23,15 @@ KERNELSRC := $1 KERNELOUTPUT := $2 MAKEFLAGS += --no-print-directory +MAKEARGS := $(echo -n "-C \$(KERNELSRC) O=\$(KERNELOUTPUT)"; \ + test "$5" = "$7" || echo -n " ARCH=$5"; \ + test "$6" = "$5" -o "$6" = "$7" || echo -n " SUBARCH=$6") all: - \$(MAKE) -C \$(KERNELSRC) O=\$(KERNELOUTPUT) + \$(MAKE) \$(MAKEARGS) %:: - \$(MAKE) -C \$(KERNELSRC) O=\$(KERNELOUTPUT) \$@ + \$(MAKE) \$(MAKEARGS) \$@ EOF
Quoted 3 lines · Jan Beulich
This adds functionality to default
CROSS_COMPILEto a sensible value when cross-building (so one doesn't always have to specify this on the make command line)
Put something like this into your ~/bin and forget. Or use Al's kmk
script: ftp://ftp.linux.org.uk/pub/people/viro/
$ cat ~/bin/cross-compile #!/bin/sh
case "$#" in
0)
echo "usage: cross-compile ARCH ..." >&2 exit 1 ;;
esac
ARCH="$1"
shift
case $ARCH in
alpha|arm|m68k|s390|sh|sh64|sparc|sparc64|x86_64)
CROSS_COMPILE=$ARCH-unknown-linux-gnu- ;; parisc) CROSS_COMPILE=hppa-unknown-linux-gnu- ;; ppc) CROSS_COMPILE=powerpc-unknown-linux-gnu- ;; ppc64) CROSS_COMPILE=powerpc64-unknown-linux-gnu- ;; *) echo "cross-compile: -ENOCROSSCOMPILER for $ARCH" >&2 exit 1 ;;
esac
make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE "$@"
Quoted 6 lines · Jan Beulich
This adds functionality to default
CROSS_COMPILEto a sensible value when cross-building (so one doesn't always have to specify this on the make command line), as well as storing ARCH and SUBARCH in theMakefile
generated when building outside of the source directory (so that subsequent make invocations don't have to always repeat these).
This patch introduce different behaviour with and without make O= This will result on confusion and is bad.
The right approach is to come up with a patch that works in both cases.
Sam
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Sam Ravnborg <[email protected]> 08.11.05 00:04:26 >>>
Quoted 1 line · Jan Beulich
This adds functionality to default
CROSS_COMPILEto a sensible
value
Quoted 1 line
Quoted 1 line
when cross-building (so one doesn't always have to specify this on
the
Quoted 7 lines
Quoted 4 lines
make command line), as well as storing ARCH and SUBARCH in the
Makefile
generated when building outside of the source directory (so that subsequent make invocations don't have to always repeat these).This patch introduce different behaviour with and without make O= This will result on confusion and is bad.
Though I admit that I never build inside the source tree, I can't see what you apparently do. Where/how would the behavior differ? If you just mean the fact that in-source-tree builds will need to continue to specify ARCH/SUBARCH on the make command line, then of course yes, this is going to be different. But building in the source tree is a bad idea in general in my opinion, and hence I would view this as the price you pay. Of course this information could be stored in a hidden file in the output tree (rather than in mkmakefile itself) if that's more desirable...
Quoted 1 line
The right approach is to come up with a patch that works in both
cases.
Jan
Quoted 8 lines · Jan Beulich
Though I admit that I never build inside the source tree, I can't see what you apparently do. Where/how would the behavior differ? If you just mean the fact that in-source-tree builds will need to continue to specify ARCH/SUBARCH on the make command line, then of course yes, this is going to be different. But building in the source tree is a bad idea in general in my opinion, and hence I would view this as the price you pay.
That's anyway how most users builds kernel.
Quoted 3 lines
Of course this information could be stored in a hidden file in the output tree (rather than in mkmakefile itself) if that's more desirable...
Plan has been to add this during *config step to .config. But I have been sidetracked the few times I looked at it.
Having it as part of *config process is good because
- this is when you configure the kernel
- .config is a natural file to keep configuration within
- and then we have same functionality with and without O=...
Sam