Skip to content

Instantly share code, notes, and snippets.

@rpetrich
Created May 17, 2010 10:02
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 9 You must be signed in to fork a gist
  • Save rpetrich/403608 to your computer and use it in GitHub Desktop.
Save rpetrich/403608 to your computer and use it in GitHub Desktop.
iPhone Toolchain installer script
#!/bin/sh
SDK=`dirname $0`
SCRIPT=`basename $0`
SDKPARENT=`dirname $SDK`
PLATFORM=`uname -sp`
if [ "$PLATFORM" = "Darwin i386" -o "$PLATFORM" = "Darwin x86_64" ]; then
echo "iPhone Toolchain installer script by rpetrich"
echo ""
if [ "$SDKPARENT" != "/Developer/Platforms/iPhoneOS.platform/Developer/SDKs" ]; then
echo "$SDK is not a valid iPhone SDK. Move this script to /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk/install-sdk"
else
echo "Be sure you have installed APT7 and OpenSSH and have closed Cydia before continuing!"
/bin/echo -n "iPhone IP Address: "
read ADDRESS
pushd $SDK
tar -cvz - . 2> /dev/null | ssh root@$ADDRESS "(mkdir -p /var/sdk && cd /var/sdk && tar xvpzf - && ./$SCRIPT)"
popd
fi
elif [ "$PLATFORM" = "Darwin arm" ]; then
pushd /var/sdk/usr/lib
ln -fs libgcc_s.1.dylib libgcc_s.10.5.dylib
ln -fs dylib1.o dylib1.10.5.o
ln -fs crt1.o crt1.10.5.o
ln -fs libstdc++.6.0.9.dylib libstdc++.6.dylib
ln -fs libstdc++.6.0.9.dylib libstdc++.dylib
ln -fs libobjc.A.dylib libobjc.dylib
ln -fs libSystem.B.dylib libSystem.dylib
popd
ln -fs /usr/include/substrate.h /var/sdk/usr/include/substrate.h
apt-get -y install curl git make ldid less com.ericasadun.utilities nano adv-cmds top rsync file-cmds inetutils
curl -L http://apt.saurik.com/cydia/debs/libgcc_4.2-20080410-1-6_iphoneos-arm.deb -o libgcc.deb
dpkg -i libgcc.deb
rm libgcc.deb
apt-get -y install csu iphone-gcc coreutils cycript
else
echo "Unknown OS and architecture!"
fi
@TooTallNate
Copy link

Which firmware(s) will this work on?

@truehybridx
Copy link

Would this work on iOS 4.x?

@rpetrich
Copy link
Author

It works on all firmwares, but currently iphone-gcc doesn't with headers that include block declarations (up to SDK 3.2 works)

@psychowood
Copy link

I needed to replace every "ln -s" with "ln -fs" to overwrite already existing (but not up-to-date) symlinks, and add "--force-yes" to each apt-get call ('WARNING: The following packages cannot be authenticated!') to allow complete script execution.
Other than that, worked as expected, thanks! :)

Copy link

ghost commented Jan 1, 2011

Thank you, working well.
I'm using the 3.2 SDK and a modified gcc specs file (for -I, -L and -F parameters).
I could not compile fping, as some netinet headers are missing from the iPhoneOS SDK. I used this bash script:

for path in /Developer/Platforms/iPhone*/Developer/SDKs/*; do
    for file in /usr/include/netinet/ip.h \
                /usr/include/netinet/in_systm.h \
                /usr/include/netinet/ip_icmp.h \
                /usr/include/netinet/ip_var.h; do
        if [ ! -f "${path}${file}" ]; then
            sudo ln "${file}" "${path}${file}"
        fi;
    done;
done

from this web site: http://blog.slaunchaman.com/2010/02/13/using-apples-simpleping-on-iphone-os/ and could compile.
Thanks

@ryanchapman
Copy link

Great job on this!

I did have to do two things to get this working:

  1. After doing a git clone, I had to add execute permissions to install-sdk
    chmod +x install-sdk
  2. In the install-sdk file, on line 44, change this:
    curl http://apt.saurik.com/cydia/debs/libgcc_4.2-20080410-1-6_iphoneos-arm.deb -o libgcc.deb
    to this:
    curl -L http://apt.saurik.com/cydia/debs/libgcc_4.2-20080410-1-6_iphoneos-arm.deb -o libgcc.deb
    The reason is apt.saurik.com redirects (HTTP 302) to cache.saurik.com. Without the -L option, curl will not follow to the new location and instead outputs an HTML file in libgcc.deb, which will not work.

Otherwise seems to be working. Thanks!

@ryanchapman
Copy link

One more note... to get programs to compile, I had to tell gcc where the headers and libraries were located by setting a few environment variables.

Before compiling, you may want to run this in bash shell:

export C_INCLUDE_PATH=/var/sdk/usr/include

export CPLUS_INCLUDE_PATH=/var/sdk/usr/include

export LIBRARY_PATH=/var/sdk/usr/lib

@rpetrich
Copy link
Author

ryanchapman: Thanks. I've added those changes. The proper way is to compile+link is to set the sysroot to /var/sdk. Theos, for example, does this already on iOS.

@akhilpo
Copy link

akhilpo commented Oct 26, 2012

Where can I get libobjc.A.dylib? I dont want to download the entire xcode just for that file. Can you point me some other location?

@zxhubo
Copy link

zxhubo commented Jan 20, 2022

After I installed iphone-gcc using the following command:
apt-get install iphone-gcc

Always prompt the following error:

iPhone:~/tmp root# apt-get install iphone-gcc
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package iphone-gcc is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'iphone-gcc' has no installation candidate

Do you know how to solve this error?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment