Subject: 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/30/2002 17:51:27
	do people think it necessary?  or should we modify lib/libc/db
	to be bi-endian? (or is it bi-endian already?)

	the problem was originally noted by From: HAMAJIMA Katsuomi
	<hamajima@nagoya.ydc.co.jp>.

itojun


Index: share/termcap/Makefile
===================================================================
RCS file: /cvsroot/sharesrc/share/termcap/Makefile,v
retrieving revision 1.23
diff -u -r1.23 Makefile
--- share/termcap/Makefile	2002/03/30 19:09:52	1.23
+++ share/termcap/Makefile	2002/05/30 08:50:44
@@ -9,7 +9,24 @@
 FILESNAME_termcap.src=termcap
 FILESDIR=${BINDIR}/misc
 
+# find out endianness of target and set proper flag for cap_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= -l
+.elif ${TARGET_ENDIANNESS} == "4321"
+TARGET_ENDIANNESS= -b
+.else
+TARGET_ENDIANNESS=
+.endif
+
 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.12
diff -u -r1.12 Makefile
--- usr.bin/vgrind/Makefile	2002/01/31 19:32:11	1.12
+++ usr.bin/vgrind/Makefile	2002/05/30 08:50:45
@@ -24,9 +24,27 @@
 
 realall: vfontedpr vgrindefs.src.db
 
+# find out endianness of target and set proper flag for cap_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= -l
+.elif ${TARGET_ENDIANNESS} == "4321"
+TARGET_ENDIANNESS= -b
+.else
+TARGET_ENDIANNESS=
+.endif
+
 .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