CrossCompileLinuxOSX - hpgDesigns/hpgdesigns-dev.io GitHub Wiki

Introduction

Unlike Windows, OS-X has a very reasonable Unix layer that ENIGMA is known to work with. Despite this, there are several reasons you may wish to cross-compile from Linux to create an OS-X binary:

1. It's faster. 2. You may not own a Mac (although you'll need to secure one temporarily for the first steps). 3. You may want to deploy all 3 OSes from one host, rather than constantly switching files and rebooting.

This guide covers cross-compilation to OS-X using the osxcross tool chain. If you are ever in doubt, refer to their excellent install guide, here: https://github.com/tpoechtrager/osxcross.git

Step One: Retrieving the Mac SDK files

This is the only step that you absolutely need to have a Mac for. Perform the following:

1. Boot the Mac 2. Download and install Xcode from the App store (it's free). This guide was tested with version 5.1. 3. Open a terminal, and check out the OSX code repository, then run the extract script:

cd ~/Documents
git clone https://github.com/tpoechtrager/osxcross.git
cd osxcross
./tools/gen_sdk_package.sh

If the gen_sdk_package script complains, you may have to manually mount the Xcode.dmg image (with DiskImageMounter).

Now, you should see a file named MacOSX10.9.sdk.tar.xz or something similar. Copy this onto a USB stick; you will need it later on your Linux machine.

Congratulations, you don't need a Mac for the rest of this! (But you might want to keep one around for testing the compiled binary.)

Step Two: Build Tools and Environment setup

On an Ubuntu-based system, open a terminal and type the following:

sudo apt-get install clang llvm-dev automake autogen libtool patch libxml2-dev uuid-dev

Now, check out the osxcross repository (yes, again; this time you need it on Linux).

cd ~
git clone https://github.com/tpoechtrager/osxcross.git

Copy the MacOSX10.9.sdk.tar.xz file from earlier into the osxcross/tarball directory. Don't decompress it; just leave it there as-is. Now, we need to build clang:

cd ~/osxcross
./build.sh

If you get weird or confusing errors, make sure that only one version of clang is installed on your system.

One the system builds correctly, you'll see some path printed to the console (usually '/home/USER/osxcross/target/bin, but with your username). Add this to your .bashrc, like so:

gedit ~/.bashrc
export PATH=$PATH:/home/USER/osxcross/target/bin

Make sure that, for the remainder of this guide, if you see /home/USER/, you replace it with your home directory.

Test that it worked; you may have to restart your terminal, or source .bashrc:

source ~/.bashrc
x86_64-apple-darwin13-clang --version

Ubuntu clang version 3.4-1ubuntu3 (tags/RELEASE_34/final) (based on LLVM 3.4)
Target: x86_64-apple-darwin13
Thread model: posix

You might have a different darwin version. The 32-bit compiler (if you need it) is usually called i386-apple-darwin13-clang, or similar.

Step Three: Hackety hackety hackety

Open a terminal and type the following:

sudo apt-get install libX11-dev
cp -r /usr/include/X11 /home/USER/osxcross/target/SDK/MacOSX10.9.sdk/usr/include/c++/4.2.1/

You may have to replace the 4.2.1 with your actual version of clang, and MacOSX10.9.sdk with your version of the Mac OS-X SDK (from step 1).

OSX won't use X11, but it does check for the header files (somewhere in one of the Bridges). Until we fix this, it's easier (and harmless) to just make a copy of the X11 headers for your cross-compiler.

Step Four: Building a Game

...todo, need to get compiler.ey file approved.