Subject: Cross compile on FreeBSD. Help needed.
To: None <port-hpcmips@netbsd.org>
From: None <yasu@mrit.mei.co.jp>
List: port-hpcmips
Date: 08/27/2000 15:33:06
As I sent this message yesterday, but it seems the message lost somewhere.
I send it again.

As I do not have running NetBSD machines and use FreeBSD, I hope hpcmips binaries
can be cross-compiled on a FreeBSD machine.

At first, I tried to compile the hpcmips build on FreeBSD directly
but it faied because the build architectures between FreeBSD and NetBSD are
different so much, so I decided to use NetBSD runtime binaries in a chrooted
enviroment on FreeBSD(4.1).

Though I have not succeed in building hpcmips `make build' yet, a step toward
hpcmips-cross-compiling on FreeBSD is found. Any help is appreciated.

here is a simple procedual description which I succeed so far.
(1) Get NetBSD binaries. I used 1.5_ALPHA2 snapshot on ftp://ftp.netbsd.org/
    I downloaded with this script. And unpack the binaries to some directory.
    Suppose you put the binaries in /NetBSD. (The directory resides in
    a FreeBSD machine.)
--- begin script
#!/bin/sh
# runs on FreeBSD
MACHINE=i386
BINARY_URL="ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-1.5_ALPHA2/$MACHINE/binary/sets"

b="base.tgz comp.tgz etc.tgz misc.tgz text.tgz"
for a in $b; do
        fetch $BINARY_URL/$a
done
--- end script
(2) Emulate Netbsd's system calls which are not present in FreeBSD(4.1).
    As I do not know much about kernel emulation in FreeBSD, I changed
    kern/init_sysent.c directly. I used FreeBSD 4.1 compiled on our site.
    Make kernel, make kernel-install and then reboot.
    CAUTION: This change may damege your system, use it with your own risk.
    Here is the diff.
--- begin patch
Index: init_sysent.c
===================================================================
RCS file: /mount/FreeBSD/cvs/src/sys/kern/init_sysent.c,v
retrieving revision 1.79.2.5
diff -u -b -r1.79.2.5 init_sysent.c
--- init_sysent.c	2000/07/18 21:49:12	1.79.2.5
+++ init_sysent.c	2000/08/25 05:37:51
@@ -302,7 +302,7 @@
 	{ 2, (sy_call_t *)nfstat },			/* 279 = nfstat */
 	{ 2, (sy_call_t *)nlstat },			/* 280 = nlstat */
 	{ 0, (sy_call_t *)nosys },			/* 281 = nosys */
-	{ 0, (sy_call_t *)nosys },			/* 282 = nosys */
+	{ 0, (sy_call_t *)vfork },			/* 282 = nosys */
 	{ 0, (sy_call_t *)nosys },			/* 283 = nosys */
 	{ 0, (sy_call_t *)nosys },			/* 284 = nosys */
 	{ 0, (sy_call_t *)nosys },			/* 285 = nosys */
@@ -311,12 +311,12 @@
 	{ 0, (sy_call_t *)nosys },			/* 288 = nosys */
 	{ 0, (sy_call_t *)nosys },			/* 289 = nosys */
 	{ 0, (sy_call_t *)nosys },			/* 290 = nosys */
-	{ 0, (sy_call_t *)nosys },			/* 291 = nosys */
-	{ 0, (sy_call_t *)nosys },			/* 292 = nosys */
-	{ 0, (sy_call_t *)nosys },			/* 293 = nosys */
-	{ 0, (sy_call_t *)nosys },			/* 294 = nosys */
-	{ 0, (sy_call_t *)nosys },			/* 295 = nosys */
-	{ 0, (sy_call_t *)nosys },			/* 296 = nosys */
+	{ 3, (sy_call_t *)sigaction },			/* 291 = netbsd */
+	{ 1, (sy_call_t *)sigpending },			/* 292 = netbsd */
+	{ 3, (sy_call_t *)sigprocmask },			/* 293 = netbsd */
+	{ 1, (sy_call_t *)sigsuspend },			/* 294 = netbsd */
+	{ 1, (sy_call_t *)sigreturn },			/* 295 = netbsd */
+	{ 2, (sy_call_t *)__getcwd},			/* 296 = netbsd */
 	{ 2, (sy_call_t *)fhstatfs },			/* 297 = fhstatfs */
 	{ 2, (sy_call_t *)fhopen },			/* 298 = fhopen */
 	{ 2, (sy_call_t *)fhstat },			/* 299 = fhstat */
--- end patch
(3) Chroot to /NetBSD. We are in the (pseudo) NetBSD enviroment on FreeBSD.
    It seems most programs work, as far as I know.

(4) Install ftp://ftp.netbsd.org/pub/NetBSD/arch/hpcmips/cross/i386-hpcmips/
    files and slitly changed the hpcmips-make and did `hpcmips-make build'.
    It failed with the following error message. The point is _ns`something'
    symbols can not be resolved during making csh below.
--- begin error message1
/usr/pkg/mipsel-netbsd/bin/mipsel-netbsd-gcc  -static -o csh -nostdlib -Wl,-rpath-link,/cross/usr/lib /cross/usr/lib/crt0.o /cross/usr/lib/crtbegin.o alloc.o char.o const.o csh.o dir.o dol.o err.o exec.o exp.o file.o func.o glob.o hist.o init.o lex.o misc.o parse.o printf.o proc.o sem.o set.o str.o strpct.o time.o  -L/cross/usr/lib -lgcc -lc -lgcc /cross/usr/lib/crtend.o
/cross/usr/lib/libc.a(nsdispatch.o): In function `_nsdbtget':
/usr/src/lib/libc/net/nsdispatch.c(.text+0x610): undefined reference to `_nsyyin'
/usr/src/lib/libc/net/nsdispatch.c(.text+0x640): undefined reference to `_nsyyin'
/cross/usr/lib/libc.a(nsparser.o): In function `_nsaddsrctomap':
/usr/src/lib/libc/net/nsparser.y(.text+0x14): undefined reference to `_nsyytext'
/cross/usr/lib/libc.a(nsparser.o): In function `_nsyyparse':
nsparser.c(.text+0x498): undefined reference to `_nsyylex'
nsparser.c(.text+0x6c0): undefined reference to `_nsyyerror'
nsparser.c(.text+0x984): undefined reference to `_nsyytext'
nsparser.c(.text+0xc20): undefined reference to `_nsyylex'
nsparser.c(.text+0xda4): undefined reference to `_nsyyerror'
collect2: ld returned 1 exit status
--- end error message1

Tried i386 self `make build'.
(4') Chroot to /NetBSD.  Making (self) build in the enviroment failed in the
     following error:
--- begin error message2
install -r  -c  -o root  -g wheel -m 444 libc.so.12.62.1 /usr/lib/libc.so.12.62.1
rm -f /usr/lib/libc.so.12
ln -s libc.so.12.62.1  /usr/lib/libc.so.12
rm -f /usr/lib/libc.so
ln -s libc.so.12.62.1  /usr/lib/libc.so
install -r  -c  -o root  -g wheel -m 444 llib-lc.ln /usr/libdata/lint
*** Error code 1

Stop.
*** Error code 1

Stop.
*** Error code 1

Stop.
--- end error message2

Any infomatiom is appreciated.
----------
WATANABE, Yasuhiko
Matsushita Research Institute Tokyo, Inc.
Mobile Communication Research Laboratory.