Subject: Re: Cross-compiler-HOWTO
To: netbsd-ports@NetBSD.ORG, Markus Hitter <M.Hitter@trier.fh-rpl.de>
From: Andrew Cagney <cagney@highland.com.au>
List: netbsd-ports
Date: 01/21/1996 17:06:16
Excerpts from mail: 20-Jan-96 Cross-compiler-HOWTO Markus
Hitter@trier.fh-r (4584*)

Here's a description how to build a cross-compiling environment for NetBSD.

Thanks!  I've been doing this but never attempt to write it up.  Add
Solaris-2.5/x86 and Solarsi-1.0/SPARC and NetBSD-1.0 to the list of
hosts that NetBSD can be cross compiled from.

> 1) bmake (= NetBSD's 'make'):
>    - Get this tool first, it's needed to build the others.
>    - The included 'Makefile.boot' will be understood by a generic 'make'.
>    - Change the variables MACHINE_ARCH to 'm68k' and MACHINE to 'mac68k'
>    - Use '-DMAKE_BOOTSTRAP -I..' when compiling the files in 'lst.lib'.
>    - Get /usr/share/mk/* from the NetBSD distribution and install
>      them somewhere on your host machine.
>    - Change the paths in 'pathnames.h' to the locations on your
>      host machine. You may have to create the locations.

Yes, very important to get bmake running (and as you suggest it isn't
hard).  BTW, there is no need to modify the source code - the `-r' `-f'
and `-I' options in combination do the trick vis:

	exec make -r -f $HOME/bin/hacks/sys.mk -f Makefile -I $HOME/bin/hacks -e "$@"

The `-e' is there so that the CC etc options can be overwridden vis:

	target=...
	SOURCE=$HOME/build/nbsd
	...
	DESTDIR=/applications/clayton/root ;                    export DESTDIR
	CC="${target}-gcc -g" ;					export CC
	LD=${target}-ld ;					export LD
	PATH= .... ; export PATH
	....
	exec make .... -e ...

I've put all this into a shell script called emake.
	
> 4) gcc-2.7.2:
>    - Get here the standard GNU distribution as well.
>    - Before compilation, install all the NetBSD include files to
>      '~/local/m68k-apple-netbsd1.1/include/'. Don't forget the
>      machine dependant files from the kernel sources:
>       .../sys/arch/m68k/include/* to .../include/m68k/
>       .../sys/arch/mac68k/include/* to .../include/machine/
>       .../sys/sys/* to .../include/sys/
>    - Configure with:
>      'configure --target=m68k-apple-netbsd1.1 --prefix=~/local
>      --with-gnu-as --with-gnu-ld'.
>    - Build with 'gmake LANGUAGES=c' or
>      'gmake LANGUAGES=c CC=gcc CFLAGS='-s -O2' LDFLAGS=-s'.
>    - Install with 'gmake LANGUAGES=c install'.

The way I do this is to install the include files:

	cd ..../src/include
	emake install

into /applications/clayton/root (say) and then point the GNU include
directory at the BSD one:

	ls -l /applications/clayton/targ-unknown-eabisim/include 
	lrwxrwxrwx  1 cagney         19 Jan  8 15:21
	/applications/clayton/powerpcle-unknown-eabisim/include
		-> ../root/usr/include

Same diff :-)

> 7) Well now you're nearly finished. The last step is to change the
>    various Makefiles etc. to use the cross compiling tools instead
>    of the host tools where needed. Adding a appropriate path to the
   PATH environment variable solves MOST, but not ALL problems. 

See above for alternative way to do this.

Thanks for getting some notes up,

		Andrew