-
Notifications
You must be signed in to change notification settings - Fork 31
/
iOS-build.sh
executable file
·87 lines (64 loc) · 2.56 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/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
export MIN_IOS_VERSION=5.0
# download python if it isn'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
# 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
./configure CC="xcrun clang"
xcrun make -j 3 python.exe Parser/pgen
mv python.exe hostpython
mv Parser/pgen Parser/hostpgen
xcrun make distclean
# patch python to cross-compile
patch -p1 < ../Python-2.6.5-xcompile.patch
# set up environment variables for simulator compilation
export SDK="iphonesimulator"
export SDKROOT=$(xcodebuild -version -sdk "$SDK" Path)
export IOS_COMPILER=$(xcrun -find -sdk "$SDK" llvm-gcc)
export LD=$(xcrun -find -sdk "$SDK" ld)
export CFLAGS="-m32 -isysroot $SDKROOT -miphoneos-version-min=$MIN_IOS_VERSION"
export LDFLAGS="-isysroot $SDKROOT -static-libgcc -miphoneos-version-min=$MIN_IOS_VERSION"
export CPP=$(xcrun -find -sdk "$SDK" cpp)
# build for iPhone Simulator
./configure CC="$IOS_COMPILER $CFLAGS" \
--disable-toolbox-glue \
--host=i386-apple-darwin
xcrun make -j 3 HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen \
CROSS_COMPILE_TARGET=yes
mv libpython2.6.a libpython2.6-i386.a
xcrun make distclean
# set up environment variables for cross compilation
export SDK="iphoneos"
export SDKROOT=$(xcodebuild -version -sdk "$SDK" Path)
export IOS_COMPILER=$(xcrun -find -sdk "$SDK" llvm-gcc)
export LD=$(xcrun -find -sdk "$SDK" ld)
if [ ! -d "$SDKROOT" ]; then
echo "SDKROOT doesn't exist. SDKROOT=$SDKROOT"
exit 1
fi
if [ ! -f "$IOS_COMPILER" ]; then
echo "Error: compiler not found at $IOS_COMPILER"
exit 1
fi
export CFLAGS="-isysroot $SDKROOT -miphoneos-version-min=$MIN_IOS_VERSION -arch armv7"
export LDFLAGS="-isysroot $SDKROOT -static-libgcc -miphoneos-version-min=$MIN_IOS_VERSION -arch armv7"
export CPP=$(xcrun -find -sdk "$SDK" cpp)
# build for iPhone
./configure CC="$IOS_COMPILER $CFLAGS" \
--disable-toolbox-glue \
--host=arm-apple-darwin
make -j 3 HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen \
CROSS_COMPILE_TARGET=yes
make install HOSTPYTHON=./hostpython CROSS_COMPILE_TARGET=yes prefix="$PWD/_install"
pushd _install/lib
mv libpython2.6.a libpython2.6-arm.a
lipo -create -output libpython2.6.a ../../libpython2.6-i386.a libpython2.6-arm.a