UWA Logo Computer Science & Software Engineering
Compiling iPhone/iPod Touch applications
   Faculty Home  |  School Home  |  Chris McDonald  |  my applications

HOWTO compile iPhone applications using traditional development tools

I prefer to use quite traditional UNIX development tools for my application development - vi, make, and gcc (yes, you may prefer emacs). Of course each of these is readily provided under OS X but, when it comes to iPhone development, we're dissuaded from using these traditional tools in favour of the GUI-based XCode environment.

There is a wealth of information and noise on the web devoted to developing iPhone applications in a jailbroken world. The volumes of commentary on copying SDK headers, extracting the root-filesystem, bypassing code signatures, self-signed code, pseudo signing, disabling firmware checks, SpringBoard patching, and executable entitlements, is daunting. Moreover, one critical tool, ldid, remains poorly written and its only diagnostics are issued via its code's assert statements.

Unfortunately, much of this commentary is outdated, undated, confusing, and offers attractive red-herrings to those just starting out. Much of it was written prior to the lifting of the NDA, and describes long-past hacks for previous versions of the iPhone firmware and SDK.

This HOWTO outlines how to continue using traditional development tools.
It will have limited utility for most iPhone developers but, as it took me several frustrating hours to locate, distill, and test this information, I hope that I can save others some time.

Assumed environment

  • an Apple Macintosh computer, running OS X 10.5.5,
  • the XCode 3.1.1 Developer Tools,
  • the iPhone SDK for iPhone OS (2.1 or 2.2), and
  • a jailbroken iPhone (hereafter I will not explicitly mention iPod Touch) running firmware 2.1 or 2.2.

How you get your development environment to this level, legally or illegally, is up to you - but please don't ask how to do so illegally.

Preparing your iPhone

Firstly, on your jailbroken iPhone, add the new source www.iphone.org.hk/apt/ to Cydia:

     Cydia -> Manage -> Sources -> Edit -> Add

Then, when this source is entered and Cydia has been refreshed, install the two packages named:

  1. MobileInstallation Patch, and
  2. Link Identity Editor.

Configure your iPhone to trust your Macintosh

It is widely known that the root password on jailbroken iPhones is alpine, but it's inconvenient to have to type this many times during application development. Instead, we use the related commands ssh to issue commands on our iPhone, and scp to copy files to our iPhone.

The necessary steps to enable this are best described as steps (a)-(e) in the section commencing "In order to avoid typing the password using ssh...." from this blog.

Preparing your Macintosh

There's not much to do here. Most effort is usually devoted to locating all of the necessary files and directories amongst the /Developer directory, but the necessary information can best be provided through a generic Makefile (download here) :


# the IP address of your iPhone or iPod Touch
DEVICE	= 10.1.1.3

APPL	= MyApp

DOTH	= MyApp.h
OBJS	= main.o MyApp.o

TGZFILE	= $(HOME)/backup/MyApp.tgz

# ----------------------------------------------------------------------

SDK	= /Developer/Platforms/iPhoneOS.platform/Developer
ARCH	= armv6
#SYSROOT	= $(SDK)/SDKs/iPhoneOS2.1.sdk
SYSROOT	= $(SDK)/SDKs/iPhoneOS2.2.sdk

CC	= $(SDK)/usr/bin/arm-apple-darwin9-gcc-4.0.1 \
		-arch $(ARCH) -isysroot $(SYSROOT)
CFLAGS	= -std=c99 -Werror -I$(SDK)/usr/include/gcc/darwin/4.0

LD	= $(CC)
LDFLAGS	=\
	-framework UIKit\
	-framework CoreFoundation\
	-framework Foundation\
	-framework CoreGraphics\
	-lobjc\
	-bind_at_load

# ----------------------------------------------------------------------

$(APPL):	$(OBJS)
	$(LD) $(LDFLAGS) -o $@ $^
	cp $(APPL) $(APPL).app
	@chmod 755 $(APPL).app/$(APPL)
	@touch $(APPL).app

%.o:    %.m $(DOTH)
	$(CC) $(CFLAGS) -c $<


install: $(APPL)
	@ssh root@$(DEVICE) /bin/rm -f /Applications/$(APPL).app/$(APPL)
	scp -r $(APPL).app root@$(DEVICE):/Applications
	ssh root@$(DEVICE) /usr/bin/ldid -S /Applications/$(APPL).app/$(APPL)  

uninstall:
	ssh root@$(DEVICE) /bin/rm -rf /Applications/$(APPL).app

clean:
	rm -f $(APPL) $(APPL).app/$(APPL) *.o f?

backup:
	make clean
	tar zcvf $(TGZFILE) .
	@ls -l $(TGZFILE)

Compiling and installing your application

This HOWTO is not intended to be an introductory tutorial for iPhone and Objective-C development.
However, to test that your development platform is ready, an introductory application named MyApp may be downloaded from here.
  • Create a new directory and unzip MyApp.zip therein.
  • Type make - there should be no errors reported.
  • Ensure that your iPhone's WiFi (and possibly VPN) are turned on.
  • Type make install - there should be no errors reported.
  • The first time that you install MyApp its icon will not appear on the iPhone - you will need to restart (or respring) SpringBoard to display the icon.
    If you plan on a lot of future development, use Cydia to install the package named Respring. This provides a simple one-touch application to restart SpringBoard.
  • Run MyApp on your iPhone - it does nothing but count!
  • When you've had enough fun, type make uninstall.

That's it!

Suggestions on how to improve this document are welcome.
Good luck,


made with vi! CRICOS Provider Code: 00126G
Written by chris@csse.uwa.edu.au
last modified: 11th November 2008.
Valid HTML 4.01 Transitional