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 --- /home/jbeulich/tmp/linux-2.6.14/Makefile 2005-10-28 02:02:08.000000000 +0200 +++ 2.6.14/Makefile 2005-11-04 15:05:23.000000000 +0100 @@ -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 --- /home/jbeulich/tmp/linux-2.6.14/scripts/mkmakefile 2005-10-28 02:02:08.000000000 +0200 +++ 2.6.14/scripts/mkmakefile 2005-11-04 15:24:35.000000000 +0100 @@ -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