Skip to contentSkip to conversation

kbuild feature/question: default ARCH

PATCH Randy Dunlap 3 participants 4 messages Feb 14, 2007 Kbuild

lore
Share & tools
lore
#0 lore raw

Hi,

I'd like for kbuild to default ARCH to the already-symlinked arch in include/asm-$(ARCH) if ARCH is not specified on the command line or in the environment. I have a non-working patch, complete with a circular dependency which is dropped:

make: Circular ' <- ' dependency dropped.

Any suggestions for how to complete this?

Thanks.
---

From: Randy Dunlap <[email protected]>

If ARCH is unspecified (command line or environment) and if include/asm is already a symlink to include/asm-$ARCH,
use that ARCH as the default instead of the host ARCH.
Undo the effect of this by using 'make mrproper' or just 'rm include/asm'.

This allows us to drop 'ARCH=fobr' for subsequent builds of the same ARCH, after using it in a build one time (not counting make *config).

---
 Makefile |   18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
Makefile +18 -0
@@ -172,6 +172,10 @@ SUBARCH := $(shell uname -m | sed -e s/i
 # make ARCH=ia64
 # Another way is to have ARCH set in the environment.
 # The default ARCH is the host where make is executed.
+#
+# However, if include/asm is already a symlink to include/asm-$ARCH,
+# use that ARCH as the default instead of the host ARCH.
+# Undo the effect of this by using 'make mrproper' or just 'rm include/asm'.
 
 # CROSS_COMPILE specify the prefix used for all executables used
 # during compilation. Only gcc and related bin-utils executables
@@ -182,6 +186,20 @@ SUBARCH := $(shell uname -m | sed -e s/i
 # Default value for CROSS_COMPILE is not to prefix executables
 # Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
 
+# if ARCH is unspecified & symlink include/asm exists, set ARCH to
+# its symlink arch
+@echo '  CHK DEF ARCH -> include/asm:'
+$(Q)if [ "$(ARCH)" == "" -a -h $(srctree)/include/asm ]; then \
+	symlink=`readlink include/asm` \
+	len=`expr length $symlink` \
+	if [ len -le 4 ]; then \
+		@echo '    no symlink for include/asm' \
+	else \
+		ARCH=${symlink:4} \
+		@echo '    ARCH symlink to ${ARCH}' \
+	fi \
+fi
+
 ARCH		?= $(SUBARCH)
 CROSS_COMPILE	?=
 
#1 lore raw
Quoted 6 lines · On Tue, 13 Feb 2007 22:06:19 -0800 Randy Dunlap wrote:

---

If ARCH is unspecified (command line or environment) and if include/asm is already a symlink to include/asm-$ARCH,
use that ARCH as the default instead of the host ARCH.
Undo the effect of this by using 'make mrproper' or just 'rm include/asm'.

Probably simpler just to do

$ export ARCH=i386
$ make ...

and skip this patch. g/nite.

---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***

#2 lore raw
In reply to Randy Dunlap
Quoted 5 lines · Randy Dunlap

Hi,

I'd like for kbuild to default ARCH to the already-symlinked arch in include/asm-$(ARCH) if ARCH is not specified on the command line or in the environment.

Another approach I have been toying with previously was to include ARCH in .config. But I somehow failed
to get it working and it went on my TODO list.

If kconfig get extended to so it can include Kconfig files for all archs then it could be a Kconfig option like anything else to select architecture and this would also solve your issue.

As for the "export ARCH=i386" proposal this is of no use for people crosscompiling a lot.
Think of the 'Al Viro' setup with crosscompile for 5+ different architectures.

But as I have no patches this is just cheap talk for now.

Sam

#3 lore raw

[pp] kbuild: ARCH-setup (Re: kbuild feature/question: default ARCH)

Hallo.

Quoted 9 lines · Sam Ravnborg
Quoted 5 lines · Randy Dunlap

Hi,

I'd like for kbuild to default ARCH to the already-symlinked arch in include/asm-$(ARCH) if ARCH is not specified on the command line or in the environment.

Another approach I have been toying with previously was to include ARCH in .config. But I somehow failed
to get it working and it went on my TODO list.

Sam, IMHO this is one inconvenience of the many, due to absence of conf-build, build mechanism (you have my message about just for fun thoughts ;).

Quoted 9 lines

If kconfig get extended to so it can include Kconfig files for all archs then it could be a Kconfig option like anything else to select architecture and this would also solve your issue.

As for the "export ARCH=i386" proposal this is of no use for people crosscompiling a lot.
Think of the 'Al Viro' setup with crosscompile for 5+ different architectures.

While trying to do something with lguest and "private" asm-offsets on AMD64, i must use ARCH=i386 for testing stuff. Thus, i give you my patch proposition (proposed patch, whatever) that remembers ARCH in Makefile in $(objtree). Once you have setup, you may use just
`make target' there.

Randy, maybe this is *something* to have, than nothing. Testing is appreciated.

,-*- shell -*-

|olecom@flower:/mnt/work/app-src-build/kernel.org/linux-2.6.20$
|olecom@flower:/mnt/work/app-src-build/kernel.org/linux-2.6.20$ rm -rf /tmp/linuz
|olecom@flower:/mnt/work/app-src-build/kernel.org/linux-2.6.20$ mkdir /tmp/linuz
|olecom@flower:/mnt/work/app-src-build/kernel.org/linux-2.6.20$ make ARCH=i386 O=/tmp/linu
|linux-2.6.20/ linuz/
|olecom@flower:/mnt/work/app-src-build/kernel.org/linux-2.6.20$ make ARCH=i386 O=/tmp/linuz/ defconfig > /dev/null
|/mnt/work/app-src-build/kernel.org/linux-2.6.20/arch/i386/defconfig:1122:warning:
|trying to assign nonexistent symbol USB_MULTITHREAD_PROBE
|olecom@flower:/mnt/work/app-src-build/kernel.org/linux-2.6.20$ cd /tmp/linuz
|olecom@flower:/tmp/linuz$ make prepare
|make -C /mnt/work/app-src-build/kernel.org/linux-2.6.20 O=/dev/shm/linuz prepare
|scripts/kconfig/conf -s arch/i386/Kconfig
|  Using /mnt/work/app-src-build/kernel.org/linux-2.6.20 as source for kernel
|  CHK     include/linux/version.h
|  UPD     include/linux/version.h
|  CHK     include/linux/utsrelease.h
|  UPD     include/linux/utsrelease.h
|  SYMLINK include/asm -> include/asm-i386
|  CC      arch/i386/kernel/asm-offsets.s
|  GEN     include/asm-i386/asm-offsets.h
|olecom@flower:/tmp/linuz$ arch
|x86_64
|olecom@flower:/tmp/linuz$

`-*-

Thanks.

---
Changes for mkmakefile:
* bugfix: _really_ generate Makefile once '!'
* use shell paramenter expansion only where needed, thus Makefile's body is a little bit easy to read and write.

 Makefile           |    2 +-
 scripts/mkmakefile |   26 ++++++++++++++++----------
 2 files changed, 17 insertions(+), 11 deletions(-)
scripts/mkmakefile +16 -10
Index: linux-2.6.20/scripts/mkmakefile
===================================================================
@@ -9,12 +9,13 @@
 # $3 - version
 # $4 - patchlevel
+# $5 - ARCH
 
-
-test ! -r $2/Makefile -o -O $2/Makefile || exit 0
+test ! -r $2/Makefile -o ! -O $2/Makefile || exit 0
 echo "  GEN     $2/Makefile"
 
-cat << EOF > $2/Makefile
-# Automatically generated by $0: don't edit
-
+echo "#
+# Automatically generated by
+# $0
+#
 VERSION = $3
 PATCHLEVEL = $4
@@ -22,15 +23,20 @@ PATCHLEVEL = $4
 KERNELSRC    := $1
 KERNELOUTPUT := $2
+ARCH         := $5
+" > $2/Makefile
+
+cat << "EOF" >> $2/Makefile
+MAKEFLAGS    += -rR --no-print-directory
 
-MAKEFLAGS += --no-print-directory
+export ARCH
 
-.PHONY: all \$(MAKECMDGOALS)
+.PHONY: all $(MAKECMDGOALS)
 
 all:
-	\$(MAKE) -C \$(KERNELSRC) O=\$(KERNELOUTPUT)
+	$(MAKE) -C $(KERNELSRC) O=$(KERNELOUTPUT)
 
 Makefile:;
 
-\$(filter-out all Makefile,\$(MAKECMDGOALS)) %/:
-	\$(MAKE) -C \$(KERNELSRC) O=\$(KERNELOUTPUT) \$@
+$(filter-out all Makefile,$(MAKECMDGOALS)) %/:
+	$(MAKE) -C $(KERNELSRC) O=$(KERNELOUTPUT) $@
 EOF
Makefile +1 -1
Index: linux-2.6.20/Makefile
===================================================================
@@ -358,5 +358,5 @@ outputmakefile:
 ifneq ($(KBUILD_SRC),)
 	$(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile \
-	    $(srctree) $(objtree) $(VERSION) $(PATCHLEVEL)
+	    $(srctree) $(objtree) $(VERSION) $(PATCHLEVEL) $(ARCH)
 endif