[Gllug] cross compiling for Darwin

Nix nix at esperi.org.uk
Sun Jan 30 13:35:20 UTC 2005


On Sun, 30 Jan 2005, nelly boy uttered the following:
> Sunday morning and a Bloodshot (ala garlic and shots) fuelled  hangover
> has me wondering if I can use my Linux fuelled AMD64 workstation to
> compile for Darwin on PPC.

You can, although you'll need a copy, NFS mount or something of the
Darwin headers and libraries to even begin.

What you probably want to look at is Dan Kegel's `crosstool'. Alas,
this is for Linux/glibc crosses only, so you'll have to build a cross
yourself. Have a look at <http://www.kegel.com/crosstool/>.

Roughly, you want to:

- get the config triplets for the host and target. The host is
  probably i686-pc-linux-gnu or something, the target probably
  powerpc-apple-darwin10.3 or something like that. I'll call
  them $HOST and $TARGET from now on. I'm assuming you're building
  the compiler on the same machine you'll be running it on.

- build a cross binutils, --build=$HOST --host=$HOST --target=$TARGET.
  You probably want to install it in a different --prefix, or
  alternatively use the same trick I used for the
  sparc-linux -> sh-elf cross below, i.e., keep the cross-assembler's
  libraries off the beaten path:

LDFLAGS="-s -Wl,-rpath -Wl,/usr/sparc-unknown-linux-gnu/sh-unknown-elf/lib" /usr/packages/binutils/core/configure --prefix=/usr --enable-mmap --with-commonbfdlib --enable-shared --disable-static --with-gnu-ld --prefix=/usr --verbose --build=`config.guess` --target=sh-unknown-elf --program-prefix=sh-unknown-elf- --libdir='${prefix}/sparc-unknown-linux-gnu/sh-unknown-elf/lib' --includedir='${prefix}/sparc-unknown-linux-gnu/sh-unknown-elf/include'

- build a cross GCC. You'll want to specify --build, --host, --target,
  and --sysroot at least: --sysroot points at the directory below
  which are a lib/ and include/ directory containing the libraries
  from the Darwin box.

  Some caveats: You must make it with `make', *not* `make bootstrap';
  you must use a native GCC which is the same version as the
  cross-compiler you're trying to build: you must (as usual with
  GCC bootstraps) bootstrap from an objdir outside the GCC tree,
  so you end up typing ../gcc-3.4.3/configure [...] or something
  like that.


Also note that these are uncharted waters. Apple's GCC has numerous
bugfixes, some of which might be needed for compilation on Darwin to
work: I'm not certain. You might try checking out one of the apple-gcc-*
branches of GCC CVS, if a normal GCC doesn't work... I'm not sure if
that GCC will work as a native Linux GCC at all, in which case
you might have to build the Apple cross-GCC using a more ordinary
GCC, and it might work. :/

Don't expect precompiled headers to work on the resulting compiler
(which means that compiling anything with those massive headers will be
*slow*.)

I know some people have got successful Linux->Darwin crosses, but I
don't know anyone who's done it who doesn't work for Apple. :/

>                            Being a cross compiling beginner I wonder if
> anyone can point me in the right direction and/or tell me if this is
> complete folly: cross compiling, that is - obviously, mixing garlic,
> chillies and Vodka is highly questionable ;-)

It is difficult, but doable. GCC is good at cross-compiling, but getting
it set up to do that is a bit nasty.

-- 
`Blish is clearly in love with language. Unfortunately,
 language dislikes him intensely.' --- Russ Allbery
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list