CrossCompileLinuxOSX

From ENIGMA
Jump to navigation Jump to search

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 libssl-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/

You may have to replace the 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

You are now ready to build a game! First, make sure the following files are present in the enigma-dev directory:

MacOS/build/Release/EnigmaXcode.app/Contents/Info.plist
MacOS/build/Release/EnigmaXcode.app/Contents/Resources/EnigmaGame.icns
MacOS/build/Release/EnigmaXcode.app/Contents/Resources/English.lproj/MainMenu.nib

If they are not there, perform the following, from the enigma-dev directory:

#This should work:
python install.py

#If that doesn't work, try:
python install.py mac

Now, fire up the ENIGMA engine, and open your game. Open the "Enigma Settings" tab in your project, and change to the tab labeled "Api". In there, change the "Compiler" to "Apple64". This will change the platform to "Cocoa", which is what you want.

Now, click the "Run" button and wait for the game to compile. It will definitely not launch, but you will see that the compilation process succeeds, producing a game labeled ./MacOS/build/Release/EnigmaXcode.app/Contents/MacOS/EnigmaXcode. Now, make sure you don't close ENIGMA, and do the following:

  • Open the enigma-dev folder in your file manager.
  • Go into the folder MacOS/build/Release.
  • Copy the entire EnigmaXcode.app folder to a USB drive.
  • Now you can close ENIGMA if you want to.

On a Mac, copy the EnigmaXcode.app folder to your desktop, right-click on it, and choose "open". Congratulations, your game is working on OS-X!


Step Five: Tidying up

You might want to do a few things before releasing your app into the wild:

  • Rename EnigmaXcode.app to whatever your game is called (keep the .app extension). Make sure you only do this to the folder once it's been copied; the folder in enigma-dev shouldn't be changed.
  • Replace EnigmaGame.icns with your game's icon. You can use [png2icns http://icns.sourceforge.net/] to easily create an icon in the icns format.
  • Edit the Info.plist file, replacing various aspects such as the game's author, version, and copyright tag.

In the future, we may automate this (by pulling it from your game's settings panel).