Skip to main content
Nowa Zhu

搭建toolchain For iPhone 2.x

··1 min

这几天正在申请iDP,等待的同时也顺便在Leopard下搭建个非官方的开发环境。如何申请iDP我就不说了,Robin有描述他的成功经历。这是搭建iPhone 2.x的toolchain环境的中文资料还是比较少的,我在此把我的步骤贡献出来,备忘且供参考。

首先建立一个目录,我们的操作将在这个目录里进行。你可以命名为iphone_devel或其它你喜欢的名字:

 mkdir iphone_devel
 cd iphone_devel 

我们从llvm开始

 svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm-svn -r 42498
 pushd llvm-svn
 ./configure --enable-optimized
 make ENABLE_OPTIMIZED=1
 sudo make install
 LLVMOBJDIR=`pwd`
 popd

为什么一定要是42498这个版本呢,看这里

接下来安装iPhone devel tools:

 svn checkout http://iphone-dev.googlecode.com/svn/trunk/ iphone-dev
 pushd iphone-dev
 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
 sudo mkdir -p /usr/local/arm-apple-darwin
 mkdir -p build/odcctools
 pushd build/odcctools
 ../../odcctools/configure --target=arm-apple-darwin --disable-ld64

接下来检查你是否有/Developer/SDKs/MacOSX10.4u.sdk这样一个文件,如果没有下载iPhone SDK并安装之,如果有:

 export INCPRIVEXT="-isysroot /Developer/SDKs/MacOSX10.4u.sdk"

然后编译

 make
 sudo make install
 popd

第一个大步骤到此完成,接下来我们要将iPhone FileSystem复制或者链接到/usr/local/share/iphone-filesystem。如果你不会提取iPhone FileSystem,看这里

当iPhone FileSystem已经mount到了正确的位置后,我们继续:

 sudo ln -s /Volumes/BigBear5A347.M68OS /usr/local/share/iphone-filesystem
 export HEAVENLY=/usr/local/share/iphone-filesystem
 pushd include
 ./configure --with-macosx-sdk=/Developer/SDKs/MacOSX10.4u.sdk
 sudo bash install-headers.sh
 popd
 mkdir -p build/csu
 pushd build/csu
 ../../csu/configure --host=arm-apple-darwin
 sudo make install
 popd

接下来我们开始编译gcc:

 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

在真正开始编译gcc之前,我们要从这里下载一个文件,保存到iphone_devel目录,然后给gcc打个patch:

 patch ../../llvm-gcc-4.0-iphone/gcc/config/arm/lib1funcs.asm ../../../lib1funcs.asm.diff

现在开始编译:

 make LLVM_VERSION_INFO=2.0-svn-iphone-dev-0.3-svn
 sudo make install

支持toolchain搭建完成,所有的文件都安装在/usr/local/arm-apple-darwin/

参考资料:

  1. http://ansani.it/2008/08/12/build-the-toolchain-for-iphone-20x-on-macosx-105x/
  2. http://code.google.com/p/iphone-dev/wiki/Building