2008年10月22日星期三

iPhone non official SDK aka ToolChain finally setup

[Original: http://aakash-bapna.blogspot.com/2007/10/iphone-non-official-sdk-aka-toolchain.html]

Woo.. after doing the process almost ten times, downloading the full xodetools.dmg(~924mb) i finally have the iPhone toolchain working.. i have setup the non official iPhone SDK ,, untill the official by Apple comes out in Feb'08 .
Start developing native iPhone apps today, no more web 2.0...
There are many guides out there, i am just telling my expierience, hope it works for you..
It uses the GC++, GCC compiler in linux..
I used Fedore 7 on VMware(virtual machine, you can grab both of them for free) to build the toolchain. I recomd. linux for good performance..
Content from -http://code.google.com/p/iphone-dev/wiki/Building ,with my tips in BOLD.

HOWTO build the toolchain
Run terminal...

  • Ensure that you have a copy of bison and flex installed on your system. All major systems should have these tools installed or available in package management systems. Most linux flavours have the packages, you can skip this..
  • $ bison --version
    GNU
    Bison version 1.28
    $ flex
    --version
    flex version
    2.5.4
  • Check out a copy of LLVM SVN, and build a release build (as opposed to a debug one). Currently, due to Issue 70, we are limited to revision 42498. it will take some time while files are being downloaded to your PC from internet, probably no errors here
  • $ 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
  • Check out a copy of the iphone-dev SVN repository.( it will take large amount of time, the longest step of all)
  • $ svn checkout http://iphone-dev.googlecode.com/svn/trunk/ iphone-dev
    $ pushd iphone
    -dev
  • Make a directory to hold the toolchain.
  • $ sudo mkdir /usr/local/arm-apple-darwin
  • Build odcctools. ( you will get some error if you are using CYGWIN on windows here, refer to there site for details )
  • $ mkdir -p build/odcctools
    $ pushd build
    /odcctools
    $
    ../../odcctools/configure --target=arm-apple-darwin --disable-ld64
    $ make
    $ sudo make install
    $ popd
  • Get a copy of the iPhone root filesystem. This is usually obtained by decrypting and extracting the iPhone restore software using these tools, but there are many other methods to obtain this, including simply using scp to download all the files from the iPhone over Wi-Fi. (Scroll below for a download link of ready to use iPhone 1.0.2 image) Unpack the root filesystem somewhere, and set the environment variable $HEAVENLY to its path. (set this again if you restart system or terminal)
  • $ HEAVENLY=/usr/local/share/iphone-filesystem
  • Install the iPhone headers to the appropriate place. If you aren't on Mac OS X, replace the /Developer/SDKs/MacOSX10.4u.sdk path with the full path to the unpacked Mac OS X 10.4 Universal SDK(ie. MacOSX10.4u.sdk). If you don't have a copy of this, scroll below..
  • $ pushd include
    $
    ./configure --with-macosx-sdk=/Developer/SDKs/MacOSX10.4u.sdk
    $ sudo bash install
    -headers.sh
    $ popd
  • Install csu, which includes crt1.o, dylib1.o, and bundle1.o. Don't rebuild them from source, as this requires a working cross-GCC, which you don't have yet (and the build-from-source process for csu is broken right now anyway). Binaries are provided for this reason.
  • $ mkdir -p build/csu
    $ pushd build
    /csu
    $
    ../../csu/configure --host=arm-apple-darwin
    $ sudo make install
    $ popd
  • Only if you are compiling on leopard 10.5. This is an ugly workaround and compiling with the resulting toolchain will give you a warning.
  • $ 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
    $
    export FLAGS_FOR_TARGET="-mmacosx-version-min=10.1"
    $ sudo ln
    -s /usr/local/arm-apple-darwin/lib/crt1.o \
    /usr/local/arm-apple-darwin/lib/crt1.10.5.o
  • Configure and make LLVM-GCC. Make sure that $LLVMOBJDIR and $HEAVENLY are set per the instructions above.(i got the errors like error 1, error 2 more than 5 times, i solved this problem by changing lots of files,symlinks in /usr/lib folder of iphone image hence i have uploaded my modified working iphone image. see below for errors).
  • $ mkdir -p build/llvm-gcc-4.0-iphone
    $ pushd build
    /llvm-gcc-4.0-iphone
    $
    ../../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
You're done. Have fun!

Gotchas

  • Make sure that there are no spaces in any of the directory names that you use. GCC does not build if there are spaces in the directory names, and the shell scripts will not work. This is most often a problem on Windows.
  • Make sure that /usr/local/bin is in your PATH. This is not the case out of the box on Mac OS X, although chances are if you've installed things from source before you've added it already.
  • If LLVM failed to compile because of missing bison and/or flex (evidence that this was the case is a failed compile on utils/TableGen/FileLexer.l), you must make clean and delete utils/TableGen/FileParser.h before trying again with bison and flex installed. LLVM's make clean script does not always properly clean up after a failed build.
  • Make sure that $HEAVENLY points to a copy of the full iPhone root filesystem, not just the unpacked update DMG. If you get errors about being unable to find -lc, then your $HEAVENLY is set incorrectly, you mistyped the --with-heavenly option to configure, or your copy of the root partition is incomplete. Your copy of the iPhone root filesystem must include a usr/lib/libc.dylib file.

HOWTO obtain the Mac OS X headers on Linux or Windows

=Install the cpio utility using your distribution's standard package management system. All the major Linux distributions, as well as Cygwin, should have this utility.
=No need to download the whole xcode tools dmg (~924mb). I extracted the package,uploaded it for you :), download the needed file from here- http://rapidshare.com/files/66764258/MacOSX10.4u.sdk.rar
=Extract RAR, then the pax archive by creating a new dir and using the following command in terminal
gunzip -c MacOSX10.4u.sdk.pax.gz | cpio -i

=Find MacOSX10.4u.sdk folder in extracted contents and link it toolchain install procedure.

--LOGIN as root to avoid weird errors, password prompts again and again..

--The envirnoment variables should be set properly to check there use this command in terminal- echo $VARIABLENAME, eg. - echo $HEAVENLY if it returns blank line set it again. the envirno. variable has a liftime till the terminal runs, if you close it, you have to set it again


-- errors i got ,
when i do "make LLVM_VERSION_INFO=2.0-svn-iphone-dev-0.3-svn " its runs for a long time and then results in this error * /usr/local/bin/arm-apple-darwin-ld: /home/Aakash/iphone/iphone-image/usr/lib/libc.dylib truncated or malformed object (mach header extends past the end of the file) collect2: ld returned 1 exit status make2 [libgcc_s.dylib] Error 1 make2 Leaving directory `/root/iphone-dev/build/llvm-gcc-4.0-iphone/gcc' make1 [stmp-multilib] Error 2 make1: Leaving directory `/root/iphone-dev/build/llvm-gcc-4.0-iphone/gcc' make: [all-gcc] Error 2*
i did this to get off the error "open all .dylib files (<=1 k) one by one in folder /iphone-image/usr/lib/, rename it - and for example libc.dylib shows path to libSystem and libSystem - path to libSystem.B.dylib. Just copy libSystem.B.dylib twice and rename 2 new files to libc.dylib and libSystem.dylib. do this for all <=1kb .dylib files".
The iPhone image i uploaded here contains these changes, no need to do again.


Password for all my rapidshare uploads if needed in this post is aksblog.co.nr

Usefull links-
Post toolchain install--
  • sample test app that worked for me http://absolutech.org/files/testApp.rar , extract, goto directory in terminal type make
  • http://www.cocoadev.com/index.pl?UIKit
  • http://phonedev.tumblr.com/
  • http://www.lucasnewman.com/iphone/

Need any help, post as comment...

没有评论: