forked from cobbal/python-for-iphone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiOS-build.sh
executable file
·62 lines (50 loc) · 2.13 KB
/
iOS-build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/zsh
set -o errexit
# credit to:
# http://randomsplat.com/id5-cross-compiling-python-for-embedded-linux.html
# http://latenitesoft.blogspot.com/2008/10/iphone-programming-tips-building-unix.html
# download python and patch if they aren't there
if [[ ! -a Python-2.6.5.tar.bz2 ]]; then
curl http://www.python.org/ftp/python/2.6.5/Python-2.6.5.tar.bz2 > Python-2.6.5.tar.bz2
fi
if [[ ! -a Python-2.6.5-xcompile.patch ]]; then
curl http://randomsplat.com/wp-content/uploads/2010/04/Python-2.6.5-xcompile.patch > Python-2.6.5-xcompile.patch
fi
# get rid of old build
rm -rf Python-2.6.5
# build for native machine
tar -xjf Python-2.6.5.tar.bz2
pushd ./Python-2.6.5
CC="clang -m32" ./configure
make python.exe Parser/pgen
mv python.exe hostpython
mv Parser/pgen Parser/hostpgen
mv libpython2.6.a hostlibpython2.6.a
make distclean
# patch python to cross-compile
patch -p1 < ../Python-2.6.5-xcompile.patch
#set up environment variables for cross compilation
export DEVROOT="/Developer/Platforms/iPhoneOS.platform/Developer"
export SDKROOT="$DEVROOT/SDKs/iPhoneOS4.0.sdk"
export CPPFLAGS="-I$SDKROOT/usr/lib/gcc/arm-apple-darwin10/4.2.1/include/ -I$SDKROOT/usr/include/"
export CFLAGS="$CPPFLAGS -pipe -no-cpp-precomp -isysroot $SDKROOT"
export LDFLAGS="-isysroot $SDKROOT -Lextralibs/"
export CPP="/usr/bin/cpp $CPPFLAGS"
# make a link to a differently named library for who knows what reason
mkdir extralibs
ln -s "$SDKROOT/usr/lib/libgcc_s.1.dylib" extralibs/libgcc_s.10.4.dylib
# build for iPhone
./configure CC="$DEVROOT/usr/bin/arm-apple-darwin10-llvm-gcc-4.2" \
LD="$DEVROOT/usr/bin/ld" --host=armv6-apple-darwin --prefix=/python
# comment out lines that break build (ugly hack)
sed -i.bak -e 's/MACHDEP_OBJS=/#&/' -e 's/LINKFORSHARED=/#&/' Makefile
make HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen \
CROSS_COMPILE_TARGET=yes
make install HOSTPYTHON=./hostpython CROSS_COMPILE_TARGET=yes prefix="$PWD/_install"
# package library files
pushd _install/lib/python2.6
zip -r -y python26.zip .
popd
pushd _install/lib
mv libpython2.6.a libpython2.6-arm.a
lipo -create -output libpython2.6.a ../../hostlibpython2.6.a libpython2.6-arm.a