iPhone Toolchain on Linux

A Tutorial

Tagged: Linux OS X

I have an iPhone. I also use Google Mail as my web-based mail client. Unfortunately, there is really no good way to get push Gmail on an iPhone. Even now, post firmware 3.0, these are the best ways:
  1. Pay for a service like MobileMe.
    Problem: service fees seem like overkill, and the push E-mail would be the only benefit I’d get from it.
  2. Wrap Gmail’s IMAP service in an exchange server. There are some paid services that do this, however, Z-Push is free (if one can host it one’s self).
    Problem: the iPhone only supports a single Exchange server at a time. Therefore, I’d have to choose between getting push E-mail versus over-the-air calendar/contacts synchronization that is currently provided through Google’s own “Sync” Exchange wrapper.
  3. Write an app that uses the new Push Notification service in firmware 3.0 to remotely push mail to the phone.
    Problem: this would probably be a very lucrative solution (i.e., I’ll bet lots of people would pay a nominal one-time fee for this app), but it would almost definitely be rejected from the App Store. Furthermore, it would require me to set up a back-end server running 24/7 to push the updates.
  4. Jailbreak the phone and write a daemon that runs in the background, connects to Google’s IMAP service, and goes into IDLE mode.
    Problem: the only Apple device I own is my iPhone; how might I compile my own apps for it? (Sure, my wife does have a PowerBook, but that would be cheating, right? Right‽)
Therefore, I had to set up the iPhone development toolchain on Linux. It turns out that this path was paved a number of years ago (well before Apple even released their official SDK). It appears, however, that the primary audience for the open toolchain were Apple users that just wanted to code native apps for their phones. Therefore, it seems, much of the interest in the open toolchain waned after Apple made it possible to compile both legitimate apps (i.e., those destined for the App Store) and jailbreak apps using their XCode IDE. The problem, of course, is that XCode requires OSX. Since it appears that the open toolchain hasn’t been actively maintained for some time, it required a bit of hacking on my part to get it to work. I mentioned that I had gotten this working in Linux at a recent Philly CocoaHeads meeting and there was a surprising amount of interest. Therefore, the remainder of this article serves to explain (to the best of my memory) the steps required in the installation. Before I start, though, this is what the toolchain will let you do:
  • Compile native apps (both console and Cocoa/Springboard/GUI) for the Apple iPhone.
  • Utilize API features up to version 2.2.
  • Do both of the above on Linux/BSD (probably also including—but not personally tested—on OSX and from Cygwin).
This is what the toolchain will not let you do:
  • Use API 3.0 features (AFAIK), however, the binaries created by the toolchain can run on iPhones running firmware 3.0 just fine.
  • Submit apps to the App Store.
  • Simulate the iPhone on your desktop (like XCode’s simulator).
  • Install binaries to a non-jailbroken phone (AFAIK).
Prerequisites:
  • You must have a subversion client installed.
  • You must have a non-ancient version of Java installed.
  • You need the xar and cpio utilities.
  • You obviously need all of the dependencies required to compile the gcc cross-compiler (none of which I know offhand).
  • Command line skillz.
Now, the instructions. These instructions are a modification of those found here. You can refer to that page and utilize its comments section if you have any trouble. This following is the general sequence I used (although I may have forgotten something):
$ mkdir -p ~/projects/iphone/
$ cd ~/projects/iphone/toolchain
$ svn checkout http://iphonedevonlinux.googlecode.com/svn/trunk/ ./
Modify IPHONE_WIKI_KEY_URL in toolchain.sh (around line 96) to be the following:
http://www.theiphonewiki.com/wiki/index.php?title=VFDecrypt_Keys:_2.x
and then run
$ chmod u+x toolchain.sh
$ mkdir -p files/firmware
$ mkdir -p sdks
Download the latest iPhone SDK from here (you need to have an apple developer account, which is free). This should end up being a .dmg file. You need to get two .sdk files out of this .dmg. The toolchain.sh file has code to do this for you, but I couldn’t get it to work. Therefore, I used a free tool called hfsexplorer; download it here. It doesn’t claim to work in Linux, but it turns out that it was written in Java so in actuality it works fine. Just download the .zip version, go into the ./lib/ directory and run
$ java -jar hfsx.jar
A GUI will pop up. Open the iPhone SDK .dmg file and locate MacOSX10.5.pkg (or whatever is the latest version) in the Packages directory; extract it to the sdks subdirectory in your toolchain directory. Rename it to macosx.pkg. Also in the Packages directory, there should be a .pkg for the latest iPhone SDK. I forget what it was called, but it should be obvious (famous last words). Also extract that file to the sdks directory and rename it to iphone.pkg.
$ cd ~/projects/iphone/toolchain/sdks
$ xar -xf iphone.pkg Payload
$ cat Payload | zcat | cpio -id
$ mv -f mv -f Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS*.sdk .
$ xar -xf macosx.pkg Payload
$ cat Payload | zcat | cpio -id
$ mv -f SDKs/MacOSX10.*.sdk .
Now you should have two .sdk files in the sdks dir. You can delete all other files in that directory; you don’t need them anymore.
$ cd ~/projects/iphone/toolchain/files/firmware
Download the .ipsw file for the 2.2.1 firmware into this directory (I haven’t yet tried this with the 3.0 firmware). You can find the .ipsw file stored within the file structure of iTunes’ Application Support directory, if you’ve ever used that version of iTunes to upgrade your iPhone to that firmware. If you don’t have it, it’s widely available online (just make sure to check the hash after you download). Now we’re ready for the big step: compiling the toolchain!
$ cd ~/projects/iphone/toolchain/
$ ./toolchain.sh headers
$ ./toolchain.sh firmware
$ ./toolchain.sh darwin_sources
$ ./toolchain.sh build
Now you can optionally remove some temporary files:
$ ./toolchain.sh clean
You can test the toolchain by following the instructions here in the section of that same name, here. Good luck!
← Pli Aĝa Enskribigo Blog Archive Novega Enskribigo →