ONLamp.com
oreilly.comSafari Books Online.Conferences.

advertisement


The iPhone SDK: APIs Apple Didn't Want You to Know About
Pages: 1, 2, 3

Building the Open Source Tool Chain

Perhaps you're opposed to the idea of building applications linked in with embedded DRM (digital rights management), or perhaps you just like using open source software. The open source tool chain has been around since August 2007 and has matured considerably in its time. It also happens to run on Linux, Windows, and older versions of Mac OS X, making it a much cheaper alternative for developers who don't want to switch their entire department to Leopard-based Macs.



Many binary distributions of the open source tool chain are floating around. We'll walk you through a simple Leopard installation here that will work on the iPhone OS development platform.

What You'll Need

While there are some unofficial binary distributions of the tool chain floating around the Internet, you'll be building it from sources in this section. The following are requirements for building from source.

Supported Desktop Platform

The first thing you'll need is a desktop platform that is supported. Platforms currently supported by the tool chain are:

  • Mac OS X 10.4 Intel or PPC
  • Mac OS X 10.5 Intel
  • Ubuntu Feisty Fawn, Intel
  • Ubuntu Gusty Gibbon, Intel
  • Fedora Core, Intel
  • Gentoo Linux 2007.0, x86_64
  • Debian 2.6.18
  • CentOS 4
  • Windows / Cygwin

Nicholas Penree of Conceited Software took time to adapt the tool chain's installation to run on Leopard, which is what we'll use in our example, with my own notes for adding iPhone OS support. Other platforms follow the same basic steps as these. Official tool chain instructions can be found at http://code.google.com/p/iphone-dev/wiki/Building.

High Speed Internet Connection

The tool chain is several hundred megabytes in size-and that's just the sources. Unless you want to be sitting around for a few days, you'll likely want to download the sources over a high-speed connection. If you don't have one, it might be a good idea to perform the installation from a library or local coffee shop.

Open Source Tools

The next things you'll need are the necessary open source tools installed on your desktop:

  • bison (v1.28 or later)
  • flex (v2.5.4 or later)
  • gcc (the GNU compiler that handles C, C++, and Objective-C )
  • svn (the Subversion source control utity)

If you're missing any of these tools, download and install them before proceeding. On the Mac, these are included with Xcode tools, and you'll want to install or upgrade to the latest version of Xcode before proceeding. Most other operating systems provide them as optional components in their distribution.

Xcode tools can be downloaded from Apple's web site at http://developer.apple.com/tools/xcode/.

Apple SDK

Finally, the last thing you'll need is a copy of the Apple SDK, if you want to use the iPhone OS libraries and frameworks. Your applications will link to these when built.

If you've installed the Apple SDK, just symlink the framework libraries to a place the tool chain will see them:

sudo mkdir -p /usr/local/share

sudo ln -s/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.0.sdk \

/usr/local/share/iphone-filesystem

If you're unable to install these on your machine, you can download these directly from an iPhone running a jailbroken 1.2/2.0 file system; specifically, the libraries and frameworks.

Copying the libraries from your iPhone to your desktop is not condoned by Apple. Check with your local, state, and federal laws to ensure this is legal where you reside.

Presuming you have installed SSH onto the iPhone, use the following commands to download the files you need into a folder called /usr/local/share/iphone-filesystem.

# mkdir -p /usr/local/share/iphone-filesystem

# cd /usr/local/share/iphone-filesystem
 
# mkdir -p ./System/library ./usr

# scp -r root@[IPHONE IP ADDRESS]:/System/library/Frameworks/ .
 
# mv Frameworks ./System/library
 
# scp -r root@iphone:/usr/lib .
 
# mv lib ./usr

Compiling the Tool Chain

The source code for the tool chain is split into two repositories: one for the LLVM compiler framework and one for the rest of the tool chain. Create a build directory for yourself and cd into it. Now use Subversion to check both projects out from their repositories.

$ svn co http://llvm.org/svn/llvm-project/llvm/trunk  llvm-svn -r 42498
 
$ svn co http://iphone-dev.googlecode.com/svn/trunk/ iphone-dev

You'll also need to switch out a couple of SVN repositories to grab the new iPhone OS versions of various pieces. This will eventually be merged into the root of the source tree when iPhone OS is officially released.

$ pushd include
 
$ svn switch http://iphone-dev.googlecode.com/svn/branches/include-1.2-sdk
 
$ popd
 
$ pushd odcctools
 
$ svn switch http://iphone-dev.googlecode.com/svn/branches/odcctools-9.2-ld
 
$ popd

The download may take an hour or longer, depending on the speed of your connection. Once both repositories have been checked out, it's time to start building.

One convention that may be unfamiliar to you is the use of the built-in shell commands pushd and popd. These are similar to the cd command, but they push and pop directories on a stack. This makes it easy to do some work in a new directory and then return to a previous one without having to remember where you were.

You'll also see references to the sudo command. This is a Unix tool providing limited access to run privileged (root) commands. When you want to run a command that requires privileged access (because it accesses sensitive data on the operating system or could have dangerous effects hurting the operating system), type sudo on the command line followed by the command you wish to run. Mac OS X will then prompt you for the root password to your desktop before allowing the command to run. If you don't have sudo, you can safely leave it off of your commands, but will need to first invoke su to become root.

Step 1: Build and install the LLVM framework

The LLVM (Low Level Virtual Machine) framework provides a standard infrastructure for building compilers. It provides the necessary hooks and APIs to build a standardized compiler without having to rewrite all of the basic components of a compiler. Issue the following statements to compile and install a release build of the llvm compiler.

$ pushd llvm-svn
 
$ ./configure --enable-optimized
 
$ make ENABLE_OPTIMIZED=1
 
$ sudo make install
 
$ LLVMOBJDIR=`pwd`
 
$ popd

Pages: 1, 2, 3

Next Pagearrow





Sponsored by: