Subject: Crosscompiling
To: None <tech-toolchain@netbsd.org>
From: Frank van der Linden <frank@wins.uva.nl>
List: tech-toolchain
Date: 12/24/1999 14:51:03
I've been looking into getting cross-compiling between different NetBSD
platforms in the tree by default. The inspiration for this was a script
by Bill Sommerfeld, which showed that all the mechanisms are basically
already there; setting some make/environment variables is enough to
create the crosscompilers, and do a cross-build.

I took the following approach:

	* Call the cross-compile targets <machine>-<format>, e.g.
	  i386-elf, i386-aout, sparc-elf, alpha-elf. Just the machine
	  name (e.g. "alpha") will point to the currently used format
	  for that architecture.
	* For different ports that have the same CPU type (e.g.
	  the m68k ports), a different machine/ include dir will
	  be used.
	* in src/gnu/cross, create reachover trees for each of these
	  targets, and targets to install the different machine/
	  include dirs.
	* Supply script frontends called x<toolname> that accept
	  a "-target X" argment. I.e. there will be xcc, xas, xld
	  xstrip, xnm and possibly xmake. These frontends will invoke
	  the right crosstools, supplying the additional arguments
	  needed (like -B and -I for cc).

My current layout is:

	/usr/cross
		i386-elf
		i386-aout
		sparc-elf
		...
			libexec/
				cc
				as
				ld
				cc1
				cc1plus
				...
			lib/
		include/
			i386/
			alpha/
			...
				machine -> .
				param.h
				...
				m68k-> ../m68k (for m68k ports)

	/usr/bin
		xcc
		xld
		xas
		...

Note: cc, ld and as are in libexec because 1) they will never be executed
directly, only through a script, and 2) when invoked with -B, gcc expects
everything it invokes to be in the directory specified with -B.

Open issue: do we always want the full lib directory for the target archs
to be installed? It's not strictly necessary, you can do "make builds"
without them, but I'd like people to be able to do
"xcc -target m68k -o foo foo.c" and have it work.

- Frank