DoK – Where Dreams Come From

C’è chi vede il bicchiere mezzo pieno e chi lo vede mezzo vuoto… Per me, l’acqua che manca, è traboccata fuori ;)

ansani.it is finally iPhone ready :)

Hi guys,

thanks to WPTouch plugin my blog site is iPhone / iPod Touch ready icon wink ansani.it is finally iPhone ready :)

Look @ screenshot !!!

iphonescrsht ansani.it is finally iPhone ready :)

Build the toolchain for iPhone 2.0.x on MacOSX 10.5.x

Hi guys !!!
this is another (!?!?!?!) document on how to compile a toolchain for iPhone (with firmware 2.0.x) on MaxOSX 10.5.x. First of all, why a new document ?!?!?!? Simple question and simple response: “Because other documents I found on Internet don’t work for me, so I decided to mix infoz from the NET and try to make my toolchain… icon smile Build the toolchain for iPhone 2.0.x on MacOSX 10.5.x and… finally it works !!!!!”

Most info about toolchain compilation I get from this good article from Saurik, NerveGas and Drudge.

First of all, you need terminal access to your Mac. If you don’t known how made an ssh/shell access, well… go away icon wink Build the toolchain for iPhone 2.0.x on MacOSX 10.5.x
Now, I hope you have installed bison, flex and a svn client… It’s OK ?!?!? Do you have ?!?!? OK… let’s go !!

Create a new directory iPhoneDevel and go on with llvm.
Now, from shell:

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

If you want to known why you’re still relegate to release 42498 of llvm, you need to read these.

Now, it’s time to checkout some 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

I compile for arm-apple-darwin platform, you can safely change this target with whatever you want icon wink Build the toolchain for iPhone 2.0.x on MacOSX 10.5.x .
Now, check if you have MacOSX 10.4u SDK (if not, simply download iphone SDK from Apple Site and install everything). If so, simply write this on shell:

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

Now, compile party icon smile Build the toolchain for iPhone 2.0.x on MacOSX 10.5.x

make
sudo make install
popd

Ok, first BIG step is gone. Now it’s time to get iPhone FileSystem and mount to /usr/local/share/iphone-filesystem. If you don’t known how to obtain correct File System, simply read this document.
I assume you mounted correctly undecrypted dmg image so, go on mounting iPhone FS and compiling toolchain.

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

By now I tried successfully to compile gcc 4.0 with MacOSX 10.4u headers, so document I wrote assume you have downloaded and correctly installed these. I try to compile gcc 4.2 with 10.5.x headers and, if all was ok, I update this guide… stay tuneeeeeeeeeeeeeeed icon smile Build the toolchain for iPhone 2.0.x on MacOSX 10.5.x

Let’s go:

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

Now, it’s time to patch icon smile Build the toolchain for iPhone 2.0.x on MacOSX 10.5.x
If you don’t patch, you receive a lot of garbage errors like these:

../../../llvm-gcc-4.0-iphone/gcc/config/arm/lib1funcs.asm:670:garbage following instruction -- `bls 11f'
../../../llvm-gcc-4.0-iphone/gcc/config/arm/lib1funcs.asm:672:garbage following instruction -- `beq 12f'
make[2]: *** [libgcc/./_udivsi3_s.o] Error 1

Why you obtain these errors ?????? Read this page about issue #145.
How you can correct error ?!?!? Simply download this file and save it on iPhoneDevel directory and:

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

Now, final step icon smile Build the toolchain for iPhone 2.0.x on MacOSX 10.5.x

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

OKOKOKOKOKOKOKKOKOK icon smile Build the toolchain for iPhone 2.0.x on MacOSX 10.5.x

Now all it’s OK with toolchain. All files are installed on /usr/local/arm-apple-darwin/ and you can safely compile all sources you want.

Before you go out, some little tips icon smile Build the toolchain for iPhone 2.0.x on MacOSX 10.5.x

If you want to run your app on iPhone, you need to run “ldid -S YourApp” on your iPhone, otherwise you obtain “Killed” because your app need to be signed.

If you obtain a “Segmentation fault” error, a “Bus error” or a trap error on your iPhone when you try to launch your app, something went wrong with your main method. Remember, you need to use something like thah when you create your app:

int main(int argc, char *argv[])
{
NSAutoreleasePool* pool = [ [ NSAutoreleasePool alloc ] init ];
int AppReturn;
AppReturn = UIApplicationMain( argc, argv, [YourAppLicationName class] );
return AppReturn;
[ pool release ];
}

Finally, I suggest a Makefile like that when you try to compile icon smile Build the toolchain for iPhone 2.0.x on MacOSX 10.5.x

CC = /usr/local/bin/arm-apple-darwin-gcc-4.0.1
CFLAGS =  \
-I"/usr/local/arm-apple-darwin/include/"  \
-I"/usr/local/lib/gcc/arm-apple-darwin/4.0.1/include/" \
-fobjc-abi-version=2 \
 
LD=$(CC)
LDFLAGS = \
-fobjc-abi-version=2 \
-lobjc  -lstdc++.6 -licucore -llockdown -lz.1 -lxml2.2 \
-framework CoreFoundation       \
-framework Foundation   \
-framework UIKit        \
-L"/usr/local/share/iphone-filesystem/usr/lib/" \
-F"/usr/local/share/iphone-filesystem/System/Library/Frameworks/"       \
-bind_at_load
 
App=YourAppName
 
all:    $(App)
 
$(App): main.o YourAppName.o
$(LD) $(LDFLAGS) -o $@ $^
 
%.o:    %.m
$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
 
clean:
rm -f *.o $(App)

Now, it’s all icon smile Build the toolchain for iPhone 2.0.x on MacOSX 10.5.x

Good compiling icon smile Build the toolchain for iPhone 2.0.x on MacOSX 10.5.x

Salvatore vs. iPhone 1 – 0 :)

Ebbene si, sono emozionatissimo !!!!

Dopo mille mila ore dedite al coding matto e disperato, sono riuscito finalmente a compilare correttamente la toolchain nativa per iPhone su MacOSX 10.5.x  e, cosa ancora più incommensurabilmente incommensurabile, a compilare, a linkare ed a far girare (GULP!!!!!) il primo programma su quel coso fetuso di iPhone 2.0.1 icon smile Salvatore vs. iPhone 1   0 :)

Ovviamente, fra qualche ora aggiornerò il post con i comandi utilizzati per il toolchain ed i tips (una marea…) per “correggere” le applicazioni in modo che non diano mille mila trap error sul “melacosino”… icon smile Salvatore vs. iPhone 1   0 :)

Stay TUNED !!!!!

iPhone 2.0 and Killed message… A solution :)

So, you wrote your first application on iPhone, you compiled without any error, you downloaded on PDA and… a strange Killed message appear… GRRRRRRRR “/(&(/”$!)”$!)”$()!”)$”.

I tried lot of ancestrals rites before solution icon smile iPhone 2.0 and Killed message... A solution :)

[Tech Mode On] You need to sign your app before iPhone can run it icon sad iPhone 2.0 and Killed message... A solution :) If you, like me, are still waiting damn Apple certs, you can use ldid (install it with apt-get install ldid directly on your iPhone). Syntax is very very very simple: ldid -S YourUnsignedAppt.

Enjoy iPhone icon smile iPhone 2.0 and Killed message... A solution :)