# HOWTO: Use Gentoo Distcc Host to cross-compile for OSX

## xadium

HOWTO: Use Gentoo Distcc Host to cross-compile for OSX

Pre-amble

Having recently discovered the wonders of distcc and seeing the recently announced release of OpenOffice.org for OSX I decided I'd look into using my Gentoo box to compile for my slightly underpowered G3 700Mhz iBook running OSX 10.3 Panther.  Looking around the forums there were a number of posts for compiling for Linux on PPC and using distcc in that way but I couldn't find anything specifically to compile Mach-o Darwin binaries under Gentoo.  Before I go any further I should say a huge thank you to Dara Hazeghi whose homepage can be found here - I emailed him regarding the instructions on his website which were instrumental in working out which tools I needed and the script that was used to create the toolchain.  The credit is primarily his and any mistakes are more than likely mine!  He kindly gave me permission to reproduce the steps I followed to build the cross compiler.

1.  Creating the toolchain

There is an ebuild (crossdev) for creating toolchains for other architectures running Linux, as we're using a different architecture and a different OS this can't be used.  Instead you'll need to equip yourself with some Darwin-specific stuff.  You will need:

cctools - Apple's sourcecode for the assembler used in Darwin.  The latest version of cctools at the time of writing is cctools-495 which can be downloaded from http://distfiles-msn.opendarwin.org/cctools-495.tar.bz2

Patches for cctools - developed by xwt.org and Dara which can be downloaded from http://i-x.ath.cx/gentoo/cctools.patch.bz2

macosx-include files - stripped down collection of header files to build cctools from http://i-x.ath.cx/gentoo/macosx-include.tar.bz2

gcc - the gnu c compiler!  Download from http://www.opensource.apple.com/darwinsource/tarballs/other/gcc-1495.tar.gz

gcc patches - patches to ensure gcc builds courtesy of Dara - http://i-x.ath.cx/gentoo/gcc.patch.bz2

bison-1.2.8 it seems that it is necessary to use the same version of Bison that Apple do otherwise errors occur - ftp://ftp.gnu.org/gnu/bison/bison-1.28.tar.gz

shortbuild.sh - Dara's script to automate the build process - http://i-x.ath.cx/gentoo/shortbuild.sh

Once you have everything downloaded into a directory you'll need to edit the top section of shortbuild.sh to suit you: SRCDIR is where you've placed the downloaded files, PREFIX is where we want the toolchain to end up and TARGET needs to reflect the system type of the target system.

```
SRCDIR=/home/ali/crossdev

PREFIX=/home/crossdev/darwin

CCTOOLSVERSION=495

CCTOOLS=cctools-$CCTOOLSVERSION.tar.gz

BISON=bison-1.28.tar.gz

GCCVERSION=1495

GCC=gcc-$GCCVERSION.tar.gz

TARGET=powerpc-apple-darwin7.3.0

```

Execute shortbuild.sh and cross your fingers - at the end you should have a toolchain in PREFIX containing an assembler and the gcc tools!

2. Using distcc

I personally already have distcc running on my Gentoo box to compile x86 software for my brother's laptop and my server.  I've set my machine up to run a parallel version of distcc for building the Darwin binaries.  I:

Copied the existing /etc/conf.d/distccd to /etc/conf.d/distccd-ppc and /etc/init.d/distccd to /etc/init.d/distccd-ppc

Edited /etc/conf.d/distccd-ppc so that distccd would run on a different port, use an alternative pid file and contained the PATH to PREFIX/bin and PREFIX/TARGET/bin

```
/etc/conf.d/distccd-ppc

# Copyright 2003 Gentoo Technologies, Inc

# $Header: /home/cvsroot/gentoo-x86/sys-devel/distcc/files/2.11.1p/conf,v 1.2 2004/03/02 17:23:01 lisa Exp $

# distccd configuration file

# this is the distccd executable

DISTCCD_EXEC=/usr/bin/distccd

# this is where distccd will store its pid file

DISTCCD_PIDFILE=/var/run/distccd/distccd-ppc.pid

# set this option to run distccd with extra parameters

# Default port is 3632.  For most people the default is okay.

DISTCCD_OPTS="--port 3633"

# set this for niceness

# Default is 15

DISTCCD_NICE="15"

DISTCCD_PATH="/home/crossdev/darwin/bin:/home/crossdev/darwin/powerpc-apple-darwin7.3.0/bin:${PATH}"

DISTCCD_LOG="/var/log/distccd.log"

```

Unfortunately the init script for distccd doesn't pay any attention to the DISTCCD_PATH variable, instead using gcc to establish its own path.  I edited my /etc/init.d/distccd-ppc so that it would use the path specified above.  Find the line in start() that begins PATH and change it as below:

```
#!/sbin/runscript

# $Header: /home/cvsroot/gentoo-x86/sys-devel/distcc/files/2.11.1p/init,v 1.2 2004/03/02 17:23:01 lisa Exp $

depend() {

        need net

}

start() {

        rm -f ${DISTCCD_PIDFILE}

        ebegin "Starting distccd"

        PATH="${DISTCCD_PATH}" \

        /sbin/start-stop-daemon --start --quiet --startas ${DISTCCD_EXEC} \

        --pidfile ${DISTCCD_PIDFILE} -- \

        --pid-file ${DISTCCD_PIDFILE} -N ${DISTCCD_NICE} --user distcc \

        ${DISTCCD_OPTS}

        eend $?

}

stop() {

        ebegin "Stopping distccd"

        start-stop-daemon --stop --quiet --pidfile "${DISTCCD_PIDFILE}"

        rm -f "${DISTCCD_PIDFILE}"

        eend $?

}
```

That's it!  Add distccd-ppc to your default runlevel if you so wish and/or issue a

```
/etc/init.d/distccd-ppc start
```

 and you should be away!

3. Setting up the Mac

I won't go into the details of setting up Fink on your Mac as this is a Gentoo forum, for more information head over to the Fink homepage.  Do the following:

Install Fink

Set Fink up to use unstable sources

Run:

```
fink selfupdate; fink index

fink install distcc-default
```

Link /sw/bin/gcc, /sw/bin/c++ and /sw/bin/g++ to /sw/bin/distcc and delete /sw/bin/cc.

Edit /sw/etc/distcc.conf to include your Gentoo box running distcc

Try and compile something and see what happens!

This is my first attempt at attempting to document something on here so if anything is incorrect with the layout or something then I apologise.  If there's anything that doesn't make sense or could be made clearer then feel free to let me know.  I'd like to say thanks again to Dara, he's the genius behind the process and it's down to him that I managed to get it working!  If you want anymore help with the Fink aspect I intend to put the guide up on my website with that section expanded but am more than happy to respond to a PM or IM.

Ali

----------

## NewBlackDak

Kewl.  I've been trying to setup my sun boxes to compile OS X code for awhile.  They already compile x86 Linux, and PPC Linux code.  I wasn't even thinking about Apple's cctools.  I'll see if I can install it on sparc, and if it needs a patch or not.

----------

## Hes Nikke

if you can get this working with XCode and cocoa, i will personally kiss you!  :Laughing: 

(i hope apple make an announcement about cross platform build farms at WWDC!)

----------

## kare

Can you please tell me which version of gcc you used creating the toolchain.

I've tried to build it with no success on a gentoo box version 1.4.16.

----------

## servobf

I've got my 800MHz iBook running Gentoo, and my wife has a 1.25GHz iMac running OS 10.3.

I'd like to be able to also compile things for my gentoo box with the help of the iMac.

Is this possible? Dificult? 

Thanks, 

Michael

----------

## stonent

What is $TOOLDIR supposed to be? It doesn't apear to be set in your script.

Edit: oops found it.

----------

## stonent

```
make[2]: Entering directory `/mnt/sda6/darwin/objdir/libiberty/testsuite'

make[2]: Nothing to be done for `install'.

make[2]: Leaving directory `/mnt/sda6/darwin/objdir/libiberty/testsuite'

make[1]: Leaving directory `/mnt/sda6/darwin/objdir/libiberty'

make: Target `install' not remade because of errors.

```

The only thing in the bin directory is "as" the others are dead links to non existant files.

----------

## pvdabeel

The 2004.3 ppc universal livecd (not the mini) has a powerpc-apple-darwin cross compiler on board. The livecd is also distcc enabled.

The cross compiler can compile C, C++, objC and objC++ applications for the Mac OS X / Darwin platform. 

Best regards,

Pieter Van den Abeele

----------

## assembler

I get the following error as well, after trying to build on both Debian Woody (with GCC 2.95.4) and on Debian Sid (gcc (GCC) 3.3.5 (Debian 1:3.3.5-5)).

```
make[2]: Entering directory `/home/build/crossdev/objdir/libiberty/testsuite'

make[2]: Nothing to be done for `install'.

make[2]: Leaving directory `/home/build/crossdev/objdir/libiberty/testsuite'

make[1]: Leaving directory `/home/build/crossdev/objdir/libiberty'

make: Target `install' not remade because of errors.
```

Any ideas?  I'd love to get this to work..  (and yes, I know this is a Gentoo linux forum, but I thought I might as well try).

Asm

----------

## uncleben

i get the same error when building. But this error is due to an error long before, there goes something wrong when doing gcc make all.

Can i use this toolchain to develop graphical OSX software.. for example with wxWidgets?

Cocoa is not possible?

----------

## line72

I'm getting this same error.  I also tried every different version of gcc on apple's site, and they all fail to build (with different errors).  Has anyone been successful?

----------

## Immortal Q

I'd like to get this going with the current version of the toolchain (Tiger/Darwin  :Cool:  but I can't figure out where those include files came from in these instructions.  I'll sniff around and see what I can find, in any case.  Maybe the folks who put together the cross-compiler for the LiveCD can provide their methods, if they aren't too catalyst-specific?  (I know nothing of catalyst, so forgive my ignorance)

----------

## Oxidative

Same problem here. Any news on this? I'd really prefere to build my code on my linux box instead of a slow pearpc emulation.  :Razz: 

----------

## syamajala

anyone get this to work with the new stuff from tiger? i haven't tried with gcc4 and the new cctools yet, but i would love to use this on my amd64 systems.

----------

