Difference between revisions of "Cross compiling OSX on Linux"
m (→Copy SDK) |
m (OSX -> Mac OS X, XCode -> Xcode) |
||
Line 1: | Line 1: | ||
− | == Cross compiling for | + | == Cross compiling for Mac OS X on Linux == |
=== Requirements === | === Requirements === | ||
Line 6: | Line 6: | ||
[1] an Intel Mac running Leopard, Snow Leopard, or Lion | [1] an Intel Mac running Leopard, Snow Leopard, or Lion | ||
− | [2] | + | [2] Xcode installed on your Mac or the original or retail Mac OS X DVD (for the SDK) |
[3] a working linux setup (Debian Squeeze in my case) | [3] a working linux setup (Debian Squeeze in my case) | ||
Line 18: | Line 18: | ||
=== Copy SDK === | === Copy SDK === | ||
STEP 1: copy the SDK from your Mac. | STEP 1: copy the SDK from your Mac. | ||
− | You need to install | + | You need to install Xcode from your Mac OS X DVD if you've not already done so and copy the SDK to an appropriate location on your Linux box. I'd |
− | recommend | + | recommend MacMac OS X10.5.sdk (compatible with Leopard) but it depends on how far back you want to be compatible. MacMac OS X10.5.sdk is located in /Developer/SDKs on the Mac. |
− | I put mine at /opt/ | + | I put mine at /opt/MacMac OS X10.5.sdk on my Debian box. Example using ssh from your Linux box to copy over the files: |
su - #become root | su - #become root | ||
cd /opt | cd /opt | ||
# all users should have read access to /Developer/SDKs... | # all users should have read access to /Developer/SDKs... | ||
− | ssh appleuser@applehostname "cd /Developer/SDKs && tar cz | + | ssh appleuser@applehostname "cd /Developer/SDKs && tar cz MacMac OS X10.5.sdk" | tar xz |
=== Get odcctools === | === Get odcctools === | ||
Line 38: | Line 38: | ||
cd ~/hg/odcctools && ./extract.sh && cd odcctools | cd ~/hg/odcctools && ./extract.sh && cd odcctools | ||
CC=gcc-4.4 ./configure --target=i386-darwin \ | CC=gcc-4.4 ./configure --target=i386-darwin \ | ||
− | --prefix=/opt/odcctools --with-sysroot=/opt/ | + | --prefix=/opt/odcctools --with-sysroot=/opt/MacMac OS X10.5.sdk |
make && make install | make && make install | ||
Line 53: | Line 53: | ||
CROSSBINDIR=/opt/odcctools/bin BINUTILSPREFIX=i386-darwin- \ | CROSSBINDIR=/opt/odcctools/bin BINUTILSPREFIX=i386-darwin- \ | ||
INSTALL_PREFIX=/opt/cross \ | INSTALL_PREFIX=/opt/cross \ | ||
− | OPT="-gl -gw -godwarfsets -XX -CX -Xd -Fl/opt/ | + | OPT="-gl -gw -godwarfsets -XX -CX -Xd -Fl/opt/MacMac OS X10.5.sdk/usr/lib" |
Note that the options (OPT) as shown are vital, especially -gw. | Note that the options (OPT) as shown are vital, especially -gw. | ||
Line 73: | Line 73: | ||
the Package Registration. | the Package Registration. | ||
− | You should now be able to use Lazarus in Linux to build for Mac | + | You should now be able to use Lazarus in Linux to build for Mac Mac OS X. |
=== Gotcha's === | === Gotcha's === | ||
Line 82: | Line 82: | ||
Second, be sure to specify the -XR option pointing to your SDK root, in | Second, be sure to specify the -XR option pointing to your SDK root, in | ||
− | my case -XR/opt/ | + | my case -XR/opt/MacMac OS X10.5.sdk, or the Darwin linker will try to link to |
the wrong startup object (/usr/lib/crt1.o). | the wrong startup object (/usr/lib/crt1.o). | ||
Line 89: | Line 89: | ||
Adapted by BigChimp | Adapted by BigChimp | ||
− | [[Category: | + | [[Category:Mac OS X]] |
Revision as of 16:30, 8 August 2011
Cross compiling for Mac OS X on Linux
Requirements
What you'll need:
[1] an Intel Mac running Leopard, Snow Leopard, or Lion
[2] Xcode installed on your Mac or the original or retail Mac OS X DVD (for the SDK)
[3] a working linux setup (Debian Squeeze in my case)
[4] up to date source for FPC (2.4.x) and Lazarus (0.9.30)
[5] the Open Darwin cctools (odcctools)
Once set up, you won't need the Mac to compile your code.
Copy SDK
STEP 1: copy the SDK from your Mac. You need to install Xcode from your Mac OS X DVD if you've not already done so and copy the SDK to an appropriate location on your Linux box. I'd recommend MacMac OS X10.5.sdk (compatible with Leopard) but it depends on how far back you want to be compatible. MacMac OS X10.5.sdk is located in /Developer/SDKs on the Mac. I put mine at /opt/MacMac OS X10.5.sdk on my Debian box. Example using ssh from your Linux box to copy over the files:
su - #become root cd /opt # all users should have read access to /Developer/SDKs... ssh appleuser@applehostname "cd /Developer/SDKs && tar cz MacMac OS X10.5.sdk" | tar xz
Get odcctools
STEP 2: grab odcctools from SVN (I use mercurial, hence the "hg" stuff) Install Mercurial if you haven't already:
aptitude install mercurial mkdir ~/hg #store our hg repositories here, change according to taste cd ~/hg hg clone http://svn.macosforge.org/repository/odcctools/trunk/ odcctools
and build it as
cd ~/hg/odcctools && ./extract.sh && cd odcctools CC=gcc-4.4 ./configure --target=i386-darwin \ --prefix=/opt/odcctools --with-sysroot=/opt/MacMac OS X10.5.sdk make && make install
I've specified gcc 4.4 but it should be okay with other versions.
Rebuild FPC
STEP 3: rebuild FPC (my sources are in ~/hg/pascal)
cd ~/hg/pascal && hg id -bint 730fd5ffbeb1 16666 fixes_2_4 release_2_4_2 make distclean && FPC=ppc386 make crossall crossinstall \ CPU_TARGET=i386 OS_TARGET=darwin \ CROSSBINDIR=/opt/odcctools/bin BINUTILSPREFIX=i386-darwin- \ INSTALL_PREFIX=/opt/cross \ OPT="-gl -gw -godwarfsets -XX -CX -Xd -Fl/opt/MacMac OS X10.5.sdk/usr/lib"
Note that the options (OPT) as shown are vital, especially -gw.
STEP 4: add a darwin (cross-compile) clause to /etc/fpc.cfg
#IFDEF darwin -Fu/opt/cross/lib/fpc/$fpcversion/units/i386-darwin/ -Fu/opt/cross/lib/fpc/$fpcversion/units/i386-darwin/* -Fu/opt/cross/lib/fpc/$fpcversion/units/i386-darwin/rtl -FD/opt/odcctools/bin #ENDIF
Build Carbon LCL
STEP 5: build the Carbon LCL (in Lazarus)
Be sure to specify the Darwin OS target, i386 CPU target and, most importantly, add the -gw option. Perform a Clean+Build of the LCL and the Package Registration.
You should now be able to use Lazarus in Linux to build for Mac Mac OS X.
Gotcha's
There are two more gotcha's when cross-compiling to OS X:
First, be sure to specify the -gw in your projects to avoid problems reported in (the unfixable) FPC bug #12001.
Second, be sure to specify the -XR option pointing to your SDK root, in my case -XR/opt/MacMac OS X10.5.sdk, or the Darwin linker will try to link to the wrong startup object (/usr/lib/crt1.o).
Source
Fpc Mailing list 6 August 2011 post by Bruce titled "Re: Cross Compiling from Linux to a Mac OS X 10.5 or 10.6 target. How? [SOLVED]" Adapted by BigChimp