Saturday, October 18, 2008

[How-To] Install llvm-gcc for iPhone SDK 2.0 in Linux

The building of iPhone gcc in Linux is described in
http://www.saurik.com/id/4

But this guide involved a lot of downloading and patching, so I put all the downloading in one zipped tar file. All you have to do is download it and run the build script in your Linux

I used the Asus eeepc Linux as an example, but others Linux variant / cygwin should be very similar.

Asus eeepc comes with xandros Debian Linux but does not have development tools. This part(A) shows you how to setup the development tools first. Other Linux variant does have development tools and you might want to skip this part and continue on Part B

(A) Install the development tools in eeepc

(1) Launch Terminal (Ctrl-Alt-T) in eeepc

(2) edit the file/etc/apt/sources.list
sudo vi /etc/apt/sources.list

and add this line to the end of the file "sources.list"
deb http://http.us.debian.org/debian/ stable main

(3) Run these commands in Terminal to install building tools

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential bison flex


(B) Download the file to your Linux
UpgradeToolChain2.tgz

The package is very large (about 200M)
You should first goto this websever
http://www.iphonefix.de/

and click the DOWNLOADS menu
and username password is generated for every visitor on the fly when you click on the ftp sever link

Inside the ftp server goto the folder
iPhoneToolchain VMWare Image / V3
and download the file UpgradeToolChain2.tgz

MD5 (UpgradeToolChain2.tgz) = b373c0e600d45b1019e2894614b5979b
Size (UpgradeToolChain2.tgz) = 202278454




and extract to /usr

cd /usr
sudo tar -xzvf ~/UpgradeToolChain2.tgz


(C) login in as superuser and build the Darwin CC tools and llvm-gcc in Linux

su
cd /usr/toolchain2
./build_20.sh

wait for 10+ minutes to complete the building of tools and gcc

If you extract the tgz to different folder and want to build it in some other folder, please modify the environment variable toolchain in build_20.sh

(D) Test build your project in Linux
The include files have the iPhone SDK headers so you can test it using some available open source project (without Interface Builder) that using SDK 2.0 headers

If you want ti upgrade to SDK 2.1/2.2 headers just copy and replace the 2.0 headers.

For example, download this WinterBoard App Source code from the developer and compile it in Linux

wget http://svn.saurik.com/repos/menes/trunk/winterboard/Application.mm

/usr/toolchain2/pre/bin/arm-apple-darwin9-g++ -g0 -O2 -Wall -Werror -o WinterBoard Application.mm \
-framework UIKit -framework Foundation -framework CoreFoundation -lobjc -framework CoreGraphics


If you want to deploy the app to iPhone, you have to codesign it (using ldid in iPhone) and provide the additional required project file in the .app folder e.g. (Info.plist, Icon.png etc)

Enjoy compiling and building iPhone App

Moreover, I have modified a previous VMWare image based on Debian Linux and build the llvm-gcc for iPhone and the toolchain and SDK20 headers there. If you have VMWare workstation or player / VMWare Fusion (Mac OS X), you can use it to build 2.0 iPhone app using ssh or samba mount access. The VMWare image is very large (about 1.2G compressed).

You should first goto this websever
http://www.iphonefix.de/

and click the download menu
and username password is generated for every visitor on the fly when you click on the ftp sever link

Inside the ftp server goto the folder
iPhoneToolchain VMWare Image / V3



and download the file
iPhoneToolchian_SDK20.rar

MD5 (iPhoneToolchain_SDK20.rar) = 29888ad8a73cf0a9674152c64961c02a
Size (iPhoneToolchain_SDK20.rar) = 1304054096

unrar the file and then use VMWare workstation or VMWare Fusion to open it

login: root
password: toolchain

The instructions are in the README.txt There are 3 sample projects inside the VMWare image

new!!
Install ldid in Linux, so that you can fake codesign it

cd ~/Projects
wget http://svn.telesphoreo.org/trunk/data/ldid/ldid-1.0.476.tgz
tar -zxf ldid-1.0.476.tgz
cd ldid-1.0.476
g++ -I . -o util/ldid{,.cpp} -x c util/{lookup2,sha1}.c
sudo cp -a util/ldid /usr/bin


Updates : The source of of ldid is moved to here
wget http://www.telesphoreo.org/export/477/trunk/data/ldid/ldid-1.0.476.tgz
or updated one here
wget http://svn.telesphoreo.org/trunk/data/ldid/ldid-1.0.610.tgz

Updates : If you compiled it in cgywin, you need to add (uint32_t) in the source code ldid.cpp that has ambiguous overload call error message like this

error: call of overloaded 'Swap(int)' is ambiguous



If you need to codesign the iPhone binary in Linux add this (as one line) to your build script

export CODESIGN_ALLOCATE=/usr/toolchain2/pre/bin/arm-apple-darwin9-codesign_allocate; ldid -S $(PROJECTNAME)

A sample Makefile for Linux toolchain

Makefile: Select all

# Makefile for gcc compiler for Linux iPhone toolchain (SDK Headers)

PROJECTNAME=HelloWorld
APPFOLDER=$(PROJECTNAME).app
INSTALLFOLDER=$(PROJECTNAME).app

IPHONE_IP=10.0.2.2

SDK=/usr/toolchain2/sys
CC=/usr/toolchain2/pre/bin/arm-apple-darwin9-gcc
LD=$(CC)
LDFLAGS += -arch arm -lobjc
LDFLAGS += -framework CoreFoundation
LDFLAGS += -framework Foundation
LDFLAGS += -framework UIKit
LDFLAGS += -framework CoreGraphics
//LDFLAGS += -framework QuartzCore
//LDFLAGS += -framework GraphicsServices
//LDFLAGS += -framework CoreSurface
//LDFLAGS += -framework CoreAudio
//LDFLAGS += -framework Celestial
//LDFLAGS += -framework AudioToolbox
//LDFLAGS += -framework WebCore
//LDFLAGS += -framework WebKit
//LDFLAGS += -framework SystemConfiguration
LDFLAGS += -isysroot $(SDK)
LDFLAGS += -F"$(SDK)/System/Library/Frameworks"
LDFLAGS += -F"$(SDK)/System/Library/PrivateFrameworks"
LDFLAGS += -bind_at_load
LDFLAGS += -multiply_defined suppress
LDFLAGS += -march=armv6
LDFLAGS += -mcpu=arm1176jzf-s

CFLAGS += -isysroot $(SDK)
CFLAGS += -DDEBUG -Wall -std=c99
CFLAGS += -Diphoneos_version_min=2.0

BUILDDIR=./build/2.0
SRCDIR=./Classes
RESDIR=./Resources
OBJS+=$(patsubst %.m,%.o,$(wildcard $(SRCDIR)/*.m))
OBJS+=$(patsubst %.c,%.o,$(wildcard $(SRCDIR)/*.c))
OBJS+=$(patsubst %.m,%.o,$(wildcard ./*.m))
RESOURCES=$(wildcard $(RESDIR)/*)
RESOURCES+=$(wildcard ./*.png)

all: $(PROJECTNAME)

$(PROJECTNAME): $(OBJS)
$(LD) $(LDFLAGS) -o $@ $^

%.o: %.m
$(CC) -c $(CFLAGS) $< -o $@

%.o: %.c
$(CC) -c $(CFLAGS) $< -o $@

dist: $(PROJECTNAME)
rm -rf $(BUILDDIR)
mkdir -p $(BUILDDIR)/$(APPFOLDER)
cp -r $(RESOURCES) $(BUILDDIR)/$(APPFOLDER)
cp Info.plist $(BUILDDIR)/$(APPFOLDER)/Info.plist
@echo "APPL????" > $(BUILDDIR)/$(APPFOLDER)/PkgInfo
export CODESIGN_ALLOCATE=/usr/toolchain2/pre/bin/arm-apple-darwin9-codesign_allocate; ldid -S $(PROJECTNAME)
cp $(PROJECTNAME) $(BUILDDIR)/$(APPFOLDER)

install: dist
ping -t 3 -c 1 $(IPHONE_IP)
ssh root@$(IPHONE_IP) 'rm -fr /Applications/$(INSTALLFOLDER)'
scp -r $(BUILDDIR)/$(APPFOLDER) root@$(IPHONE_IP):/Applications/$(INSTALLFOLDER)
ssh root@$(IPHONE_IP) 'respring'
@echo "Application $(INSTALLFOLDER) installed"

uninstall:
ping -t 3 -c 1 $(IPHONE_IP)
ssh root@$(IPHONE_IP) 'rm -fr /Applications/$(INSTALLFOLDER); respring'
@echo "Application $(INSTALLFOLDER) uninstalled"

clean:
@rm -f $(SRCDIR)/*.o
@rm -rf $(BUILDDIR)
@rm -f $(PROJECTNAME)






19 comments:

Anonymous said...

Great stuff!! I'm a totally iPhone programming novice - virtual machine and the howto are working perfect for my Windo(w)s environment! Thx from Germany, ub17

Anonymous said...

Hi, Thanks for all !
I've just one problem, i'll try to test UICatalog appliaction, it deploy well, but i've a popup at start saying enabled to start UICatalog Application.
An idea ?

Thanks,

G

Anonymous said...

Thanks so much for this How-To. After compiling the toolchain, I managed to compile run a simple "Hello, World" on the iPhone.

I also compiled the WinterBoard example in Linux, but then I don't know what to do afterwards. Can you have another How-To that explains how to deploy an app to iPhone?

Thanks!

javacom said...

if you have downloaded the vmare image, there is a sample project called UICatalog,
It is a full project with build and deploy script by using ssh to iphone 2.x firmware

Anonymous said...

Thanks so much to this toolchain.

It support iPhone 2.0, I'am very want to know if this toolchain2 can support iPhone 2.1 and iPhone 2.2?

Thanks!

하규리 said...

thanx for your greate contribution.
I tried to running your VMWare Image on VMWare6, but It works fine. but, network isn't work!!

please some help~

javacom said...

There is a website link in the readme.txt to solve the network issue

In general you run this to get ipaddress

dhclient

하규리 said...

Oh~ Thank you very much!
I am really appreciate about your help.

Anonymous said...

what is th elogin and password for the system running in the vmware image?

javacom said...

login: root
password: toolchain

donovan said...

This project make iPhone applications will can be deploy for the Apple App Store ? thanks.

javacom said...

toolchain app is for Cydia distribution. For App Store, you need codesign certificate from Apple and use XCode in Mac

Anonymous said...

Under FC10 with kernel 2.6.27.12-170.2.5, when invoking ./build_20.sh I get the error message:

FATAL:/usr/toolchain2/pre/bin/../libexec/gcc/darwin/arm/as: I don't understand 'Q' flag!
make[2]: *** [build/genmodes.o] Error 1
make[2]: leaving directory « /usr/toolchain2/bld/gcc-4.2-iphone/gcc »

Did I forget something ?
Thank's.

javacom said...

I think you did not install the required building packages in FC

Anonymous said...

Awesome thanks! Now I just have to learn how to use Unix... and program in Obtuse-C...

springrider said...

It works for me, great thanks!

I'm using WinXP with CygWin.

To anyone who aoing to do this, Dont extract the package with winrar. Use tar,gzip instead. Or the symbol links will be broken.

veryfinethreads said...

Hands up, I admit I'm a noob here ...
I'm using vmware player on Windows XP. I can access the darwin9 gcc compiler etc but can't fathom ssh or samba access.
I don't have an eth0 device showing when I do ifconfig.
Am I missing something ?
Many thanks if you can point me in the right direction.

Linjoy said...

This tutorial has left me somewhat lost to be honest. I added the repository to the sources list and ran the apt-get update, at which point it decided to install LILO which now says it needs to be configured. During the upgrade process it also said that it wanted to replace my fstab file which I asked it not to do but now when I run liloconfig like it said to do it can't recognize my devices as block devices. I got rid of UUID identification and am using the /dev/sdXY address for my hardware now in /etc/fstab which I read was a common reason for liloconfig to fail and it still isn't working. Do you know if I have to use LILO or if I can just continue to use GRUB? If I can continue to use GRUB what can I do to confirm that GRUB will load on next boot as opposed to LILO. Thanks in advance. Any help would be greatly appreciated.

Mounir said...

hello!

first thanks for this.
i have a question about your toturial
what extension can i program my applications "ipa or pxl" ???