28 Aug 2009 (updated 29 Aug 2009 at 16:37 UTC)
»
iPhone Development on Linux
I recently bought an iPod
Touch (which is basically an iPhone without the phone),
specifically to develop games for it. Now, the
official way to develop for the device is with Apple's SDK,
which only runs on Macs. I don't own a Mac, but I knew
there's an unofficial toolchain that runs on Linux (in fact,
it appeared before the official SDK - there's even an O'Reilly
book about it, written by one of the main developers).
Unlike the homebrew toolkits for the Sony PSP or
Nintendo DS, the unofficial iPhone toolchain actually uses
Apple's SDK, so it's easy to go mainstream afterwards if you
feel like it.
Here's how I set it up.
Jailbreak
the device
It's easy. If you're lazy and impatient,
there
are GUI
applications (for Windows) that do everything without too
much hassle. I used QuickFreedom.
These jailbreak applications will
usually
install Cydia,
a graphical front-end to apt (the package system we all
know and love). The first package you'll probably want
to install is OpenSSH. After you installed it, log in to the
device and look around - it's a BSD:
$ ssh root@192.168.0.174
iPod-touch:~ root# uname -a
Darwin iPod-touch 9.4.1 Darwin Kernel Version 9.4.1: Mon Dec
8 21:02:57 PST 2008;
root:xnu-1228.7.37~4/RELEASE_ARM_S5L8720X iPod2,1 arm N72AP
Darwin
Build the Linux toolchain
The iphonedevonlinux
project is a nifty shell script that builds everything.
The only catch is that it builds the toolchain for firmware
2.* (the current one is 3.*). But don't worry, it's still
compatible with the newer firmwares.
Before you start, you need to
download the
iPhone
SDK from
Apple's site. There's no link at the site to the 2.* SDK,
only for the 3.0 SDK, so here's a direct
link to the one I downloaded, for 2.2. You'll need to
register at Apple's site, but it's free.
The file is 1.7 GB. I left Firefox
downloading it
before I
left for work in the morning a couple of times, only to find
out in the evening that Firefox
crashed during the download. If, like me, you don't have an
ultra-fast internet connection, you might want to install
this
Firefox add-on; then log-in to Apple's site, use the add-on
to export cookies.txt, and download the file with
wget --load-cookies cookies.txt ....
After you're done, follow the installation
instructions (if you
downloaded the .dmg file I mentioned above, use the 2.1
branch). After you check out the project from SVN,
toolchain.sh needs a couple of fixes before you can
run it. Apply
this
patch - it fixes a broken URL and makes the script copy
the OpenGL ES headers. Run the script and be patient - it
will take a while.
While the script builds everything, you
might
want to
read up on Objective C (in case you don't know it
already) and the documentation on iPhone development at
Apple's site (use Google). Have fun!
I ported my little game SIGBUS to
the iPod -
you can
use the
accelerometer to control the ship. Here's
an early picture, and here's
the application binary, which you can try if you have a
jailbroken device. It's a work-in-progress - source code
coming soon.
Assorted observations
- Home wi-fi is an absolute must if you're
developing under Linux. You'll need SSH to upload your
applications to the device. Sorry.
- iphonedevonlinux includes a couple of nice little
"Hello, world"-type applications to get you started. If you
look at the Makefiles, you'll notice that the deploy target
does a killall SpringBoard - this is used to make
the new application icon appear on the main menu.
Unfortunately, this no longer works with newer firmwares (at
least, it doesn't work with mine - I have 2.2.1). Instead,
install BossPrefs from Cydia, and do
/Applications/BossPrefs.app/Respring.
- OpenGL
ES is OpenGL minus a lot of cruft. Among other
things, there's no immediate mode
(glBegin/glEnd) or display lists. That's
actually a good thing. Here's
a quick hack to get you started - it sets up an OpenGL
context and draws a triangle.
I'll update this "article" when I
have some
time.