Subject: Cross-compiler-HOWTO
To: None <netbsd-ports@NetBSD.ORG>
From: Markus Hitter <M.Hitter@trier.fh-rpl.de>
List: netbsd-ports
Date: 01/20/1996 19:17:00
Hm.

I just finished building a cross compiling environment for Mac - NetBSD on a
RS6000. The work should be similar for the other ports so I use this list for
posting.

I want to encourage the Maintainer(s) to add this document to some public
places so everybody interested can find it. (Allen Briggs, perhaps you could
complete your description of the kernel compilation options now, too...)

If someone is interested in binaries for RS6000, or someone found a mistake,
drop me a line.

----------------------------------------------------------------------------

Here's a description how to build a cross-compiling environment for
NetBSD. The needed effort may vary from host machine to host machine,
but 10 to 20 hours of work should be enough to finish.

I tested it on a Apollo DN3000 and on a IBM RS6000. On both machine the work
were similar and had the same success. If you feel able to hack the kernel,
the upcoming problems shouldn't be to hard for you. Where I use path
examples I canged my home directory with '~/'. I installed the compiling
tools in '~/local/' and the needed parts of the NetBSD in '~/netbsd/'.
For building the GNU stuff I used GNU 'make', for the NetBSD stuff I used
Berkley 'make' (the one which comes with NetBSD).

You have to compile and install a set of tools, get the corresponding sources
from NetBSD-current or the 1.1-release, except where noted other. Most
problems can be solved by finding the proper #include files and adding
some #defines copied from the NetBSD headers. If you install a NetBSD
distribution anywhere you have access to headers and man-pages which
is sometimes a great help.

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.

2) config:
   - Be careful, some missing symbols may have the reason in a
     missing #define.

3) binutils-2.6:
   - Get a standard GNU distribution instead of the NetBSD sources,
     this will be much easier to configure and compile.
   - Configure with:
     'configure --target=m68k-apple-netbsd1.1 --prefix=~/local'
   - build and install it normal, it will be installed in
     '~/local/m68k-apple-netbsd1.1/bin'.

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'.

5) mkdep:
   - 'mkdep' is a script, so just copy the gcc version your PATH.
   - Remove the PATH modifications from the script.

6) mkdir:
   - Check that your 'mkdir' supports the -p option, otherwise
     compile the one from NetBSD.

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. Adding
   absolute paths is't as hard as you might think. Check at least the
   following files:
   - ~/netbsd/usr/src/sys/arch/mac68k/conf/Makefile.mac68k
     'LOCAL_CC' should go to your host compiler !
     change 'CPP' to '.../gcc -E'
   - the 'mkdep' script
   - the files you copied from '/usr/share/mk/*', especally 'sys.mk'
   - 'Makefile.mac68k' and 'bsd.lib.mk' use a tool for optimizing
     libraries. Remove it, since you don't have this tool on the host
     machine and it's safe to do so.


   Good Luck !


-- 

------------------------------------------------------------------------------
 Markus Hitter			email:	hitterm@trier.fh-rpl.de
				WWW:	http://www.trier.fh-rpl.de/~hitterm
				Voice:	++49/0651/828172
------------------------------------------------------------------------------