Subject: cross-compiler-HOWTO
To: None <AllenBriggs@trier.fh-rpl.de>
From: Markus Hitter <M.Hitter@trier.fh-rpl.de>
List: port-mac68k
Date: 01/28/1996 16:50:50
I promised to tell you when my first cross-compiled kernel is accepted by the
booter. The first one is running now as good (or as bad) as one downloaded from
a NetBSD-site so here is a (slightly) corrected version of the
cross-compiler-HOWTO.

The problems I had were the following:

- gcc-2.7.2 could not compile some files. Exchanging 2.7.2's 'cc1' with the one
from 2.6.3 solved the problem.

- GNU's 'cpp' had trouble with the comments in the assembler sources. I had to
change all assembler comments to C comments ('|' -> '//'). Previously all the
objects made from a assembler source were empty.

- Following does not work with GNU's cpp:
     #define foo(x) _/**/x
     foo (bla)
  this results not in '_bla' as expected but in '_  bla' (Note the spaces).

- broken definition of MACHINE and MACHINS_ARCH forced a lot of undefined
symbols.

While the last mistake is silly, I don't know about the first three are handled
better by the cpp that comes with NetBSD. But I'll keep this for later.


so long, Markus

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

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 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 in this Makefile the variables MACHINE_ARCH to 'm68k' and
     MACHINE to 'mac68k'
   - Use '-DMAKE_BOOTSTRAP -I..' when compiling the files in 'lst.lib'.
   - Change the code in 'main.c' NOT to get value for the 'MACHINE'
     variable from the subroutine 'uname'. Use a simple
     'machine = "mac68k";' instead.
   - 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' with the normal name as well as
     with a prefixed name in '~/local/bin' (hard links). Feel free to change
     this name-prefix to one more easy to handle.

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 into your PATH.
   - Remove the PATH modifications from the script.
   - Change 'gcc' to the cross-gcc.

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 or adding the name-prefix isn'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 !
   - the 'mkdep' script
   - the files you copied from '/usr/share/mk/*', especially 'sys.mk'
   - 'Makefile.mac68k' and 'bsd.lib.mk' use a tool for optimizing
     libraries. Remove it, since you don't have this tool and it's
     safe to do so.
   - To be sure check all files you find with a "find . -name '*akefile*'
-print".

NOTES:
   - I had to change the comments in all the assembler sources (.s-, .S-files)
     to comments compatible with cpp.
   - The 'cc1' which came with 'gcc-2.7.2' worked not fine on some files
     (internal compiler error). I had to replace it with the one from
     'gcc-2.6.3'. Using 'gcc-2.6.3' at all whould be possible, but this
     handles the cross-environment not so elegant.
   - As a result of a broken definition of the variables 'MACHINE' and
     'MACHINE_ARCH' I had some hundered undefined symbols. Check the
     values with a 'bmake -n -dv|grep MACHINE'.



-- 

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