ONLamp.com
oreilly.comSafari Books Online.Conferences.

advertisement


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

Step 2: Build and install cross-compiler tools



The following commands build and install the cross-compiler components of the tool chain. These are specific to Mac OS X, so be sure to read the official documentation if you're using a different platform.

$ pushd iphone-dev
 
$ sudo mkdir /usr/local/arm-apple-darwin
 
$ mkdir -p build/odcctools
 
$ pushd build/odcctools
 
$ ../../odcctools/configure --target=arm-apple-darwin --disable-ld64
 
$ export INCPRIVEXT="-isysroot /Developer/SDKs/MacOSX10.4u.sdk"
 
$ make
 
$ sudo make install
 
$ popd
 
$ HEAVENLY=/usr/local/share/iphone-filesystem

Step 3: Install the low-level API headers

Because the iPhone's architecture is different from the desktop's, special headers need to be installed to access the low-level APIs of the iPhone. Issue the following commands to install them:

$ pushd include
 
$ ./configure
--with-macosx-sdk=/Developer/SDKs/MacOSX10.4u.sdk
 
$ sudo bash install-headers.sh
 
$ popd

Step 4: Install the Csu

The Csu provides C hooks into assembly's "start" entry point, and sets up the stack so that your program's main() function can be called. It's essentially glue code.

$ mkdir -p build/csu
 
$ pushd build/csu
 
$ ../../csu/configure --host=arm-apple-darwin
 
$ sudo make install
 
$ popd

Step 5: Build and install llvm-gcc

Now that the LLVM framework, cross-compiler tools, and Csu have been built, the compiler itself can now be built and installed. If you're doing this in stages or have since closed your Terminal window, make sure that you've still got the environment variables $LLVMOBJDIR and $HEAVENLY set to the proper directories. The LLVMOBJDIR variable points to the location of LLVM object files, which were compiled when you built LLVM. These are used to build llvm-gcc. The HEAVENLY variable points to the location where you copied the iPhone's libraries onto your desktop. This directory is used by llvm-gcc to nk to the iPhone's framework and library files when you compile applications. The name "Heavenly" was the code name given by Apple to the 1.0 code base of the iPhone software. The latest version (1.2) is named "Aspen," but the original name is still used in the tool chain. Both are named for ski slopes.

$ set
| grep -e LLVMOBJDIR -e HEAVENLY

If you don't see output from the previous command, you need to set the environment variables again. Get back into your build directory and run:

$ pushd
llvm-svn && LLVMOBJDIR=`pwd` && popd
 
$ HEAVENLY=/usr/local/share/iphone-filesystem

Once you've ensured that these are set, issue the following commands to build and install the compiler.

$ mv llvm-gcc-4.0-iphone/configure llvm-gcc-4.0-iphone/configure.old
 
$ sed \
 
's/^FLAGS_FOR_TARGET=$/FLAGS_FOR_TARGET=${FLAGS_FOR_TARGET-}/g' \
 
 
llvm-gcc-4.0-iphone/configure.old > llvm-gcc-4.0-iphone/configure
 
$ sudo ln -s /usr/local/arm-apple-darwin/lib/crt1.o \
 
 
/usr/local/arm-apple-darwin/lib/crt1.10.5.o
 
$ mkdir -p build/llvm-gcc-4.0-iphone
 
$ pushd build/llvm-gcc-4.0-iphone
 
$ export FLAGS_FOR_TARGET="-mmacosx-version-min=10.1"
 
$ sh ../../llvm-gcc-4.0-iphone/configure \
 
--enable-llvm=`llvm-config --obj-root` \
 
--enable-languages=c,c++,objc,obj-c++ \
 
--target=arm-apple-darwin --enable-sjlj-exceptions \
 
--with-heavenly=$HEAVENLY \
 
--with-as=/usr/local/bin/arm-apple-darwin-as \
 
--with-ld=/usr/local/bin/arm-apple-darwin-ld
 
$ make LLVM_VERSION_INFO=2.0-svn-iphone-dev-0.3-svn
 
$ sudo make install
 
$ popd
 
$ popd

Congratulations! You've built the free tool chain for iPhone. You're now ready to start compiling iPhone applications. The compiler itself can be invoked directly by calling /usr/local/bin/arm-apple-darwin-gcc.

When you build your applications for iPhone OS, you'll need to be sure to use the following additional CFLAGS:

CFLAGS = -fobjc-abi-version=2 \
 
-F/usr/local/share/iphone-filesystem/System/library/PrivateFrameworks

And LDFLAGS:

-lobjc

Resources

Jonathan Zdziarski is better known as the hacker "NerveGas" in the iPhone development community. His work in cracking the iPhone helped lead the effort to port the first open source applications, and his book, iPhone Open Application Development, taught developers how to write applications for the popular device long before Apple introduced its own SDK. Jonathan's website is zdziarski.com.


Return to ONLamp.



Sponsored by: