Subject: Re: Cross compiling NetBSD/i386 -> NetBSD/mac68k
To: port-mac68k@NetBSD.ORG, Dave Huang <khym@bga.com>
From: Andrew Cagney <cagney@highland.com.au>
List: tech-ports
Date: 09/14/1995 13:10:02
Hello,

Some general comments on cross compiling may be helpful (I'm doing this
but not for the 68k).


Cross compiling NetBSD is non trivial.


Compilation tools:

This is where you may come to grief...

Firstly I suggest that you check that you've got sufficient disk space
to keep online fully built copies of the compiler, assembler, linker and
possibly debugger.  I suggest this as it is esentially guarenteed that
you'll find bugs in your compiler tools (if you don't you're very very
lucky :-).

Also needed is a decision on which compiler tools to use.  I can think
of several choices 1) GNU's current tools. 2) NetBSD's tools or 3) some
hybrid (eg current gcc but NetBSD's as/ld).  I'm using a variation on #1
- the bleading edge of the GNU tools - because NetBSD's bundled compiler
et.al. don't suport my target (yes that is my blood on the floor). Any
advice?  Mainly shop around. I believe that someone in the Amega group
has recently being doing work on getting better NetBSD/68k suport into
GCC.


Build process:

I've successfuly (for my target) built lib and built/run a few select
user programs.  I've also (before beeing distracted by yet another
compler bug) linked a kernel.  Over all, this side of the problem (once
the compler tools works) is fairly straight forward.

In my case, I've got a script called emake that contains something like:

	#!/bin/sh
	PATH=$HOME/bin/hacks:$PATH ; export PATH
	# sets up environment variables for parts of make that need to be
overwritten eg:
	CC="target-unknown-netbsd-gcc -g" ; export CC
	DESTDIR=/path/to/root ; export DESTDIR
	# it sets all of CC, LD, CXX, AS, CPP, RANLIB, AR, NM, SIZE, TARGET,
MACHINE, MACHINE_ARCH, NOPIC, NOTAGS, NOPROFILE, NOMAN, DESTDIR
	# run make -e to so that these variables override the defaults
	make -e -I $HOME/bin/hacks "$@"

Where the directory $HOME/bin/hacks contains several useful things. 
Other people probably handle this differently.  Firstly it contains two
shell scripts:

	a wrapper for `install' that strips off -[mog] options
	a wrapper for chown that ignores its arguments

this is so I can do installs as a normal user (emake install) with out
running the risk of me trashing say /usr/include.  Secondly (the make -I
...), if I find a problem with one of the bsd.*.mk make files, I can put
them in there so that they override the default bsd.*.mk files (in
/usr/share/....).


With this set up, I can (the kernel may require some minor fiddling that
I've forgoten) do the following:

	# unpack
	gunzip < include.tar.gz | tar xf -
	gunzip < lib.tar.gz | tar xf -
	gunzip < sys.tar.gz | tar xf -
	gunzip < something in gnu (flex?) so you've got a file that lib needs | ....
	...
	( cd src/include && emake install )
	( cd src/lib/libcurses && emake && emake install ) # bug
	( cd src/lib && emake && emake install )
	( cd src/usr.bin/printenv && emake )
	( cd src/sys/arch/<arch>/conf && config{.new} GENERIC && cd
../compile/GENERIC && emake depend && emake )

BTW: You don't need to build/install lib to build the kernel.  You may
also be able to get away with not installing the include files - I've
not tried it though.

Other people probably have different notes.

		Andrew