Subject: Re: endianness of *.db on cross builds
To: None <tech-userlevel@netbsd.org>
From: Jun-ichiro itojun Hagino <itojun@iijlab.net>
List: tech-userlevel
Date: 05/31/2002 01:30:23
>I think the correct byte order should be used for the target.
>
>Can I suggest putting the Makefile fragment into a bsd.endian.mk, or
>something like that, so that the code doesn't have to be duplicated
>all over the place (at least the code that extracts the "1234" or "4321")?

	something like this?  it still looks ugly, i need help from Makefile
	expert.

itojun


Index: etc/Makefile
===================================================================
RCS file: /cvsroot/basesrc/etc/Makefile,v
retrieving revision 1.220
diff -u -r1.220 Makefile
--- etc/Makefile	2002/05/30 09:49:22	1.220
+++ etc/Makefile	2002/05/30 16:28:51
@@ -107,15 +107,7 @@
 NAMEDB=	127 root.cache named.conf localhost loopback.v6
 
 .if make(install-etc-files)						# {
-# find out endianness of target and set proper flag for pwd_mkdb so that
-# it creates database in same endianness
-.if exists(${DESTDIR}/usr/include/sys/endian.h)
-TARGET_ENDIANNESS!= \
-	printf '\#include <sys/endian.h>\n_BYTE_ORDER\n' | \
-	${CC} -I${DESTDIR}/usr/include -E - | tail -1 | awk '{print $$1}'
-.else
-TARGET_ENDIANNESS=
-.endif
+.include <bsd.endian.mk>
 
 .if ${TARGET_ENDIANNESS} == "1234"
 TARGET_ENDIANNESS= -L
Index: share/termcap/Makefile
===================================================================
RCS file: /cvsroot/sharesrc/share/termcap/Makefile,v
retrieving revision 1.24
diff -u -r1.24 Makefile
--- share/termcap/Makefile	2002/05/30 10:45:03	1.24
+++ share/termcap/Makefile	2002/05/30 16:28:53
@@ -9,8 +9,17 @@
 FILESNAME_termcap.src=termcap
 FILESDIR=${BINDIR}/misc
 
+.include <bsd.endian.mk>
+.if ${TARGET_ENDIANNESS} == "1234"
+TARGET_ENDIANNESS=	-l
+.elif ${TARGET_ENDIANNESS} == "4321"
+TARGET_ENDIANNESS=	-b
+.else
+TARGET_ENDIANNESS=
+.endif
+
 # there's no issue in endianness as DB keys are ascii strings.
 termcap.db: termcap.src
-	${CAP_MKDB} -f termcap ${.ALLSRC}
+	${CAP_MKDB} ${TARGET_ENDIANNESS} -f termcap ${.ALLSRC}
 
 .include <bsd.prog.mk>
Index: usr.bin/vgrind/Makefile
===================================================================
RCS file: /cvsroot/basesrc/usr.bin/vgrind/Makefile,v
retrieving revision 1.13
diff -u -r1.13 Makefile
--- usr.bin/vgrind/Makefile	2002/05/30 10:45:04	1.13
+++ usr.bin/vgrind/Makefile	2002/05/30 16:28:53
@@ -24,10 +24,20 @@
 
 realall: vfontedpr vgrindefs.src.db
 
+.include <bsd.endian.mk>
+.if ${TARGET_ENDIANNESS} == "1234"
+TARGET_ENDIANNESS=	-l
+.elif ${TARGET_ENDIANNESS} == "4321"
+TARGET_ENDIANNESS=	-b
+.else
+TARGET_ENDIANNESS=
+.endif
+
 # there's no issue of endianness as DB keys are ascii strings.
 .if ${MKSHARE} != "no"
 vgrindefs.src.db: vgrindefs.src
-	${CAP_MKDB} -f vgrindefs.src ${.CURDIR}/vgrindefs.src
+	${CAP_MKDB} ${TARGET_ENDIANNESS} -f vgrindefs.src \
+	    ${.CURDIR}/vgrindefs.src
 .else
 vgrindefs.src.db:
 .endif
Index: distrib/sets/lists/comp/mi
===================================================================
RCS file: /cvsroot/basesrc/distrib/sets/lists/comp/mi,v
retrieving revision 1.443
diff -u -r1.443 mi
--- distrib/sets/lists/comp/mi	2002/05/28 11:35:40	1.443
+++ distrib/sets/lists/comp/mi	2002/05/30 16:29:16
@@ -6060,6 +6060,7 @@
 ./usr/share/mk/bsd.README		comp-util-share
 ./usr/share/mk/bsd.dep.mk		comp-util-share
 ./usr/share/mk/bsd.doc.mk		comp-util-share
+./usr/share/mk/bsd.endian.mk		comp-util-share
 ./usr/share/mk/bsd.files.mk		comp-util-share
 ./usr/share/mk/bsd.hostlib.mk		comp-util-share
 ./usr/share/mk/bsd.hostprog.mk		comp-util-share
Index: share/mk/Makefile
===================================================================
RCS file: /cvsroot/sharesrc/share/mk/Makefile,v
retrieving revision 1.33
diff -u -r1.33 Makefile
--- share/mk/Makefile	2001/12/14 05:46:47	1.33
+++ share/mk/Makefile	2002/05/30 16:29:17
@@ -6,7 +6,7 @@
 .include <bsd.own.mk>
 
 .if ${MKSHARE} != "no"
-FILES=	bsd.README bsd.doc.mk bsd.dep.mk bsd.files.mk bsd.hostlib.mk \
+FILES=	bsd.README bsd.doc.mk bsd.dep.mk bsd.endian.mk bsd.files.mk bsd.hostlib.mk \
 	bsd.hostprog.mk bsd.inc.mk bsd.info.mk bsd.init.mk bsd.kernobj.mk \
 	bsd.kinc.mk bsd.kmod.mk bsd.lib.mk bsd.links.mk bsd.man.mk \
 	bsd.nls.mk bsd.obj.mk bsd.own.mk bsd.prog.mk bsd.subdir.mk \
Index: share/mk/bsd.endian.mk
===================================================================
RCS file: bsd.endian.mk
diff -N bsd.endian.mk
--- /dev/null	Thu May 30 19:28:47 2002
+++ bsd.endian.mk	Thu May 30 19:29:17 2002
@@ -0,0 +1,21 @@
+#	$NetBSD$
+
+.include <bsd.init.mk>
+
+# find out endianness of target and set proper flag for pwd_mkdb so that
+# it creates database in same endianness.
+.if exists(${DESTDIR}/usr/include/sys/endian.h)
+TARGET_ENDIANNESS!= \
+	printf '\#include <sys/endian.h>\n_BYTE_ORDER\n' | \
+	${CC} -I${DESTDIR}/usr/include -E - | tail -1 | awk '{print $$1}'
+.else
+TARGET_ENDIANNESS=
+.endif
+
+#.if ${TARGET_ENDIANNESS} == "1234"
+#TARGET_ENDIANNESS=	little
+#.elif ${TARGET_ENDIANNESS} == "4321"
+#TARGET_ENDIANNESS=	big
+#.else
+#TARGET_ENDIANNESS=	unknown
+#.endif