Subject: Re: ${ARCHSUBDIR}
To: None <tech-userlevel@netbsd.org>
From: None <itojun@iijlab.net>
List: tech-userlevel
Date: 01/05/2001 00:44:20
>>>	is it useful if we move them upwards, to bsd.own.mk?
>>>	(of course, we may be able to pick different variable name)
>	there are SO MANY of them.  the problem is that use of ARCHSUBDIR
>	is not very consistent...

	the following files use rules like ${MACHINE_ARCH:C:/mipse[lb]/mips/},
	or explicit .if clause based on ${MACHINE_ARCH}.

gnu/lib/libbfd/Makefile
gnu/lib/libg2c/Makefile
gnu/lib/libgcc/Makefile
gnu/lib/libobjc/Makefile
gnu/usr.bin/egcs/Makefile.inc
gnu/usr.bin/egcs/common/Makefile
gnu/usr.bin/gas.new/Makefile
gnu/usr.bin/gdb/Makefile
lib/csu/Makefile
lib/libc/Makefile
lib/libkvm/Makefile
lib/libposix/Makefile
share/mk/bsd.own.mk
sys/arch/Makefile
sys/lib/libkern/Makefile
usr.bin/crunch/crunchide/Makefile
usr.sbin/mdsetimage/Makefile

	patch at the end does two things for some of them:
	- define ${MACHINE_CPU} derived from ${MACHINE_ARCH} (which is,
	  i'm not sure if 100% correct.  also name is debetable)
	- look at arch/${MACHINE_ARCH}, then arch/${MACHINE_CPU}
	  (need better error trap - .INIT target seem to do nothing)

	does it sound useful, or harmful?

itojun



Index: gnu/lib/libg2c/Makefile
===================================================================
RCS file: /cvsroot/gnusrc/gnu/lib/libg2c/Makefile,v
retrieving revision 1.8
diff -u -r1.8 Makefile
--- gnu/lib/libg2c/Makefile	2001/01/04 09:22:06	1.8
+++ gnu/lib/libg2c/Makefile	2001/01/04 15:40:50
@@ -70,12 +70,14 @@
 
 MKLINT=		no
 
-.if (${MACHINE_ARCH} == "mipsel") || (${MACHINE_ARCH} == "mipseb")
-ARCHSUBDIR= mips
-.elif (${MACHINE_ARCH} == "sh3el") || (${MACHINE_ARCH} == "sh3eb")
-ARCHSUBDIR= sh3
-.else
+.if exists(${ARCH}/${MACHINE_ARCH})
 ARCHSUBDIR= ${MACHINE_ARCH}
+.elif exists(${ARCH}/${MACHINE_CPU})
+ARCHSUBDIR= ${MACHINE_CPU}
+.else
+.INIT:
+	@echo ${ARCH}/${MACHINE_ARCH} nor ${ARCH}/${MACHINE_CPU} exists
+	@false
 .endif
 
 CPPFLAGS+=	-I. -I${.CURDIR} -I${ARCH} -I${ARCH}/${ARCHSUBDIR} \
Index: gnu/lib/libgcc/Makefile
===================================================================
RCS file: /cvsroot/gnusrc/gnu/lib/libgcc/Makefile,v
retrieving revision 1.15
diff -u -r1.15 Makefile
--- gnu/lib/libgcc/Makefile	2001/01/04 09:17:42	1.15
+++ gnu/lib/libgcc/Makefile	2001/01/04 15:40:50
@@ -1,5 +1,7 @@
 #	$NetBSD: Makefile,v 1.15 2001/01/04 09:17:42 itojun Exp $
 
+.include <bsd.own.mk>
+
 HAVE_GCC28!=	${CXX} --version | egrep "^(2\.8|egcs)" ; echo
 
 LIB=		gcc
@@ -9,12 +11,14 @@
 DIST=		${.CURDIR}/../../dist/gcc
 ARCH=		${.CURDIR}/../../usr.bin/egcs/arch
 
-.if (${MACHINE_ARCH} == "mipsel") || (${MACHINE_ARCH} == "mipseb")
-ARCHSUBDIR= mips
-.elif (${MACHINE_ARCH} == "sh3el") || (${MACHINE_ARCH} == "sh3eb")
-ARCHSUBDIR= sh3
-.else
+.if exists(${ARCH}/${MACHINE_ARCH})
 ARCHSUBDIR= ${MACHINE_ARCH}
+.elif exists(${ARCH}/${MACHINE_CPU})
+ARCHSUBDIR= ${MACHINE_CPU}
+.else
+.INIT:
+	@echo ${ARCH}/${MACHINE_ARCH} nor ${ARCH}/${MACHINE_CPU} exists
+	@false
 .endif
 
 CPPFLAGS+=	-I${ARCH}/${ARCHSUBDIR} -I${ARCH} \
Index: gnu/lib/libobjc/Makefile
===================================================================
RCS file: /cvsroot/gnusrc/gnu/lib/libobjc/Makefile,v
retrieving revision 1.9
diff -u -r1.9 Makefile
--- gnu/lib/libobjc/Makefile	2001/01/04 09:22:06	1.9
+++ gnu/lib/libobjc/Makefile	2001/01/04 15:40:50
@@ -15,12 +15,14 @@
 		Object.h Protocol.h encoding.h typedstream.h thr.h
 INCSDIR=	/usr/include/objc
 
-.if (${MACHINE_ARCH} == "mipsel") || (${MACHINE_ARCH} == "mipseb")
-ARCHSUBDIR= mips
-.elif (${MACHINE_ARCH} == "sh3el") || (${MACHINE_ARCH} == "sh3eb")
-ARCHSUBDIR= sh3
-.else
+.if exists(${ARCH}/${MACHINE_ARCH})
 ARCHSUBDIR= ${MACHINE_ARCH}
+.elif exists(${ARCH}/${MACHINE_CPU})
+ARCHSUBDIR= ${MACHINE_CPU}
+.else
+.INIT:
+	@echo ${ARCH}/${MACHINE_ARCH} nor ${ARCH}/${MACHINE_CPU} exists
+	@false
 .endif
 
 CPPFLAGS+=	-I. -I${ARCH}/${ARCHSUBDIR} -I${ARCH} \
Index: gnu/usr.bin/egcs/Makefile.inc
===================================================================
RCS file: /cvsroot/gnusrc/gnu/usr.bin/egcs/Makefile.inc,v
retrieving revision 1.27
diff -u -r1.27 Makefile.inc
--- gnu/usr.bin/egcs/Makefile.inc	2001/01/04 10:43:24	1.27
+++ gnu/usr.bin/egcs/Makefile.inc	2001/01/04 15:40:50
@@ -21,12 +21,14 @@
 COMMONOBJ!=	cd ${.CURDIR}/../common; ${MAKE} print-objdir
 .endif
 
-.if (${MACHINE_ARCH} == "mipsel") || (${MACHINE_ARCH} == "mipseb")
-ARCHSUBDIR= mips
-.elif (${MACHINE_ARCH} == "sh3el") || (${MACHINE_ARCH} == "sh3eb")
-ARCHSUBDIR= sh3
-.else
+.if exists(${.CURDIR}/../arch/${MACHINE_ARCH})
 ARCHSUBDIR= ${MACHINE_ARCH}
+.elif exists(${.CURDIR}/../arch/${MACHINE_CPU})
+ARCHSUBDIR= ${MACHINE_CPU}
+.else
+.INIT:
+	@echo ${.CURDIR}/../arch/${MACHINE_ARCH} nor ${.CURDIR}/../arch/${MACHINE_CPU} exists
+	@false
 .endif
 
 CPPFLAGS+=	-I${.CURDIR}/../arch \
@@ -46,11 +48,11 @@
 CPPFLAGS+=-DDEFAULT_ELF
 .endif
 
-.if (${MACHINE_ARCH} == "mipseb")
+.if (${MACHINE_ARCH} == "mipseb") || (${MACHINE_ARCH} == "sh3eb")
 CPPFLAGS+=-DTARGET_BIG_ENDIAN_DEFAULT
 .endif
 
-.if (${MACHINE_ARCH} == "mipsel")
+.if (${MACHINE_ARCH} == "mipsel") || (${MACHINE_ARCH} == "sh3el")
 CPPFLAGS+=-DTARGET_LITTLE_ENDIAN_DEFAULT
 .endif
 
Index: gnu/usr.bin/gas.new/Makefile
===================================================================
RCS file: /cvsroot/gnusrc/gnu/usr.bin/gas.new/Makefile,v
retrieving revision 1.15
diff -u -r1.15 Makefile
--- gnu/usr.bin/gas.new/Makefile	2001/01/04 08:08:39	1.15
+++ gnu/usr.bin/gas.new/Makefile	2001/01/04 15:40:51
@@ -4,12 +4,14 @@
 .include <bsd.own.mk>
 
 # Override to make a cross assembler.
-.if ${MACHINE_ARCH} == "mipsel" || ${MACHINE_ARCH} == "mipseb"
-TARGET_ARCH ?=	mips
-.elif ${MACHINE_ARCH} == "sh3eb" || ${MACHINE_ARCH} == "sh3el"
-TARGET_ARCH ?=	sh3
+.if exists(${.CURDIR}/arch/${MACHINE_ARCH})
+TARGET_ARCH= ${MACHINE_ARCH}
+.elif exists(${.CURDIR}/arch/${MACHINE_CPU})
+TARGET_ARCH= ${MACHINE_CPU}
 .else
-TARGET_ARCH ?=	${MACHINE_ARCH}
+.INIT:
+	@echo ${.CURDIR}/arch/${MACHINE_ARCH} nor ${.CURDIR}/arch/${MACHINE_CPU} exists
+	@false
 .endif
 
 .if (${MACHINE_ARCH} != "m68k" && ${MACHINE_ARCH} != "ns32k") ||	\
Index: lib/csu/Makefile
===================================================================
RCS file: /cvsroot/basesrc/lib/csu/Makefile,v
retrieving revision 1.21
diff -u -r1.21 Makefile
--- lib/csu/Makefile	2001/01/04 08:01:49	1.21
+++ lib/csu/Makefile	2001/01/04 15:40:51
@@ -4,8 +4,14 @@
 
 .if ${OBJECT_FMT} == "ELF" && exists(${MACHINE_ARCH}_elf)
 SUBDIR=	${MACHINE_ARCH}_elf
+.elif exists(${MACHINE_ARCH})
+SUBDIR=	${MACHINE_ARCH}
+.elif exists(${MACHINE_CPU})
+SUBDIR=	${MACHINE_CPU}
 .else
-SUBDIR=	${MACHINE_ARCH:C/mipse[bl]/mips/:C/sh3e[bl]/sh3/}
+.INIT:
+	@echo no SUBDIR
+	@false
 .endif
 
 .if (${OBJECT_FMT} != "ELF" && ${MACHINE_ARCH} != "arm32")
Index: lib/libc/Makefile
===================================================================
RCS file: /cvsroot/basesrc/lib/libc/Makefile,v
retrieving revision 1.94
diff -u -r1.94 Makefile
--- lib/libc/Makefile	2001/01/04 06:53:45	1.94
+++ lib/libc/Makefile	2001/01/04 15:40:51
@@ -27,7 +27,16 @@
 #LINTFLAGS+=	-w
 LINTFLAGS+=-X 272
 
-ARCHSUBDIR=	${MACHINE_ARCH:C/mipse[bl]/mips/:S/arm26/arm/:C/sh3e[bl]/sh3/}
+.if exists(${.CURDIR}/arch/${MACHINE_ARCH})
+ARCHSUBDIR=	${MACHINE_ARCH}
+.elif exists(${.CURDIR}/arch/${MACHINE_CPU}) 
+ARCHSUBDIR=	${MACHINE_CPU}
+.else
+.INIT:
+	@echo no ARCHSUBDIR
+	@false
+.endif
+
 ARCHDIR=	${.CURDIR}/arch/${ARCHSUBDIR}
 AINC=		-I${ARCHDIR}
 .if defined(DESTDIR)
Index: lib/libkvm/Makefile
===================================================================
RCS file: /cvsroot/basesrc/lib/libkvm/Makefile,v
retrieving revision 1.33
diff -u -r1.33 Makefile
--- lib/libkvm/Makefile	2001/01/04 08:59:24	1.33
+++ lib/libkvm/Makefile	2001/01/04 15:40:51
@@ -11,14 +11,17 @@
 # If it is necessary to run different code based on ${MACHINE} then
 # the dispatch on ${MACHINE} should be done at run time (see m68k).
 
-.if ${MACHINE_ARCH} == "mipsel" || ${MACHINE_ARCH} == "mipseb"
-SRCS+=	kvm_mips.c
-.elif ${MACHINE_ARCH} == "arm26"
+.include <bsd.own.mk>
+.if ${MACHINE_ARCH} == "arm26"
 SRCS+=	kvm_arm32.c
-.elif ${MACHINE_ARCH} == "sh3eb" || ${MACHINE_ARCH} == "sh3el"
-SRCS+=	kvm_sh3.c
-.else
+.elif exists(kvm_${MACHINE_ARCH}.c)
 SRCS+=	kvm_${MACHINE_ARCH}.c
+.elif  exists(kvm_${MACHINE_CPU}.c)
+SRCS+=	kvm_${MACHINE_CPU}.c
+.else
+.INIT:
+	@echo no kvm_xx.c
+	@false
 .endif
 
 # Additional modules needed for m68k
Index: lib/libposix/Makefile
===================================================================
RCS file: /cvsroot/basesrc/lib/libposix/Makefile,v
retrieving revision 1.7
diff -u -r1.7 Makefile
--- lib/libposix/Makefile	2001/01/04 09:00:24	1.7
+++ lib/libposix/Makefile	2001/01/04 15:40:51
@@ -5,13 +5,16 @@
 .include <bsd.own.mk>
 
 CPPFLAGS+=-D_REENTRANT -I${.CURDIR}/../libc/include
-.if ${MACHINE_ARCH} == "mipsel" || ${MACHINE_ARCH} == "mipseb"
-ARCHDIR=	${.CURDIR}/../libc/arch/mips
-.elif ${MACHINE_ARCH} == "sh3el" || ${MACHINE_ARCH} == "sh3eb"
-ARCHDIR=	${.CURDIR}/../libc/arch/sh3
-.else
+.if exists(${.CURDIR}/../libc/arch/${MACHINE_ARCH})
 ARCHDIR=	${.CURDIR}/../libc/arch/${MACHINE_ARCH}
+.elif exists(${.CURDIR}/../libc/arch/${MACHINE_CPU})
+ARCHDIR=	${.CURDIR}/../libc/arch/${MACHINE_CPU}
+.else
+.INIT:
+	@echo no ARCHDIR
+	@false
 .endif
+
 AINC=	-I${ARCHDIR}
 .if defined(DESTDIR)
 AINC+=	-nostdinc -idirafter ${DESTDIR}/usr/include
Index: share/mk/bsd.own.mk
===================================================================
RCS file: /cvsroot/sharesrc/share/mk/bsd.own.mk,v
retrieving revision 1.151
diff -u -r1.151 bsd.own.mk
--- share/mk/bsd.own.mk	2001/01/04 15:17:41	1.151
+++ share/mk/bsd.own.mk	2001/01/04 15:40:52
@@ -132,6 +132,10 @@
 GNU_ARCH.sparc=sparc
 GNU_ARCH.sparc64=sparc
 GNU_ARCH.vax=vax
+
+# CPU model, derived from MACHINE_ARCH
+MACHINE_CPU=	${MACHINE_ARCH:C/mipse[bl]/mips/:S/arm26/arm/:C/sh3e[bl]/sh3/}
+
 .if ${MACHINE_ARCH} == "mips"
 .INIT:
 	@echo Must set MACHINE_ARCH to one of mipseb or mipsel