Skip to content
This repository was archived by the owner on Mar 30, 2019. It is now read-only.

Commit 212a5a3

Browse files
committed
Added build for libffi.
0 parents  commit 212a5a3

File tree

7 files changed

+765
-0
lines changed

7 files changed

+765
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*.swo
2+
*.swp
3+
src/*
4+
build/*
5+
.cache

bin/environment.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
3+
if [ "X$VERBOSE" == "X1" ]; then
4+
set -x
5+
fi
6+
7+
try () {
8+
"$@" || exit -1
9+
}
10+
11+
# iOS SDK Environmnent (don't use name "SDKROOT"!!! it will break the compilation)
12+
export SDKVER=`xcodebuild -showsdks | fgrep "iphoneos" | tail -n 1 | awk '{print $2}'`
13+
export DEVROOT=`xcode-select -print-path`/Platforms/iPhoneOS.platform/Developer
14+
export IOSSDKROOT=$DEVROOT/SDKs/iPhoneOS$SDKVER.sdk
15+
16+
# Xcode doesn't include /usr/local/bin
17+
export PATH="$PATH":/usr/local/bin
18+
19+
if [ ! -d $DEVROOT ]; then
20+
echo "Unable to found the Xcode iPhoneOS.platform"
21+
echo
22+
echo "The path is automatically set from 'xcode-select -print-path'"
23+
echo " + /Platforms/iPhoneOS.platform/Developer"
24+
echo
25+
echo "Ensure 'xcode-select -print-path' is set."
26+
exit 1
27+
fi
28+
29+
# version of packages
30+
export PYTHON_VERSION=2.7.1
31+
export FFI_VERSION=3.0.13
32+
33+
# where the build will be located
34+
export PROJECTROOT="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )/../" && pwd )"
35+
export SRCROOT="$PROJECTROOT/src"
36+
export CACHEROOT="$PROJECTROOT/.cache"
37+
export PATCHROOT="$PROJECTROOT/patch"
38+
export BUILDROOT="$PROJECTROOT/build"
39+
40+
# create directories if not found
41+
try mkdir -p $CACHEROOT
42+
try mkdir -p $SRCROOT
43+
try mkdir -p $BUILDROOT

bin/prepare-libffi.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
3+
echo "Building libffi ============================="
4+
5+
. $(dirname $0)/environment.sh
6+
7+
if [ ! -f $CACHEROOT/libffi-$FFI_VERSION.tar.gz ]; then
8+
try curl -L ftp://sourceware.org/pub/libffi/libffi-$FFI_VERSION.tar.gz > $CACHEROOT/libffi-$FFI_VERSION.tar.gz
9+
fi
10+
11+
# Clear out any existing build
12+
if [ -d $SRCROOT/libffi-$FFI_VERSION ]; then
13+
try rm -rf $SRCROOT/libffi-$FFI_VERSION
14+
try tar xvf $CACHEROOT/libffi-$FFI_VERSION.tar.gz
15+
try mv libffi-$FFI_VERSION $SRCROOT
16+
try rm -rf build/ffi.framework
17+
fi
18+
19+
# lib not found, compile it
20+
pushd $SRCROOT/libffi-$FFI_VERSION
21+
22+
try patch -p1 -N < $PATCHROOT/libffi/$FFI_VERSION/ffi-sysv.S.patch
23+
try patch -p1 -N < $PATCHROOT/libffi/$FFI_VERSION/project.pbxproj.patch
24+
25+
# Generate iOS code expected by project.
26+
python generate-ios-source-and-headers.py
27+
28+
# Build the framework
29+
xcodebuild -project libffi.xcodeproj -target "Framework" -configuration Release -sdk iphoneos$SDKVER OTHER_CFLAGS="-no-integrated-as"
30+
31+
# Copy the built framework into the build directory
32+
try cp -a build/Release-universal/ffi.framework $BUILDROOT
33+
34+
popd

bin/prepare-python.sh

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/bin/bash
2+
3+
. $(dirname $0)/environment.sh
4+
5+
# credit to:
6+
# http://randomsplat.com/id5-cross-compiling-python-for-embedded-linux.html
7+
# http://latenitesoft.blogspot.com/2008/10/iphone-programming-tips-building-unix.html
8+
9+
# download python and patch if they aren't there
10+
if [ ! -f $CACHEROOT/Python-$PYTHON_VERSION.tar.bz2 ]; then
11+
curl -L https://www.python.org/ftp//python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tar.bz2 > $CACHEROOT/Python-$PYTHON_VERSION.tar.bz2
12+
fi
13+
14+
# get rid of old build
15+
rm -rf $SRCROOT/Python-$PYTHON_VERSION
16+
try tar -xjf $CACHEROOT/Python-$PYTHON_VERSION.tar.bz2
17+
try mv Python-$PYTHON_VERSION $SRCROOT
18+
try pushd $SRCROOT/Python-$PYTHON_VERSION
19+
20+
# Patch Python for temporary reduce PY_SSIZE_T_MAX otherzise, splitting string doesnet work
21+
try patch -p1 < $PROJECTROOT/src/python_files/Python-$PYTHON_VERSION-ssize-t-max.patch
22+
try patch -p1 < $PROJECTROOT/src/python_files/Python-$PYTHON_VERSION-dynload.patch
23+
try patch -p1 < $PROJECTROOT/src/python_files/Python-$PYTHON_VERSION-static-_sqlite3.patch
24+
25+
# Copy our setup for modules
26+
try cp $PROJECTROOT/src/python_files/ModulesSetup Modules/Setup.local
27+
try cp $PROJECTROOT/src/python_files/_scproxy.py Lib/_scproxy.py
28+
29+
echo "Building for native machine ============================================"
30+
31+
OSX_SDK_ROOT=`xcrun --sdk macosx --show-sdk-path`
32+
try ./configure CC="clang -Qunused-arguments -fcolor-diagnostics" LDFLAGS="-lsqlite3" CFLAGS="--sysroot=$OSX_SDK_ROOT"
33+
try make -j4 python.exe Parser/pgen
34+
try mv python.exe hostpython
35+
try mv Parser/pgen Parser/hostpgen
36+
try make distclean
37+
38+
echo "Building for iOS ======================================================="
39+
40+
# patch python to cross-compile
41+
try patch -p1 < $PROJECTROOT/src/python_files/Python-$PYTHON_VERSION-xcompile.patch
42+
try patch -p1 < $PROJECTROOT/src/python_files/Python-$PYTHON_VERSION-setuppath.patch
43+
44+
# set up environment variables for cross compilation
45+
#export CPPFLAGS="-I$IOSSDKROOT/usr/lib/gcc/arm-apple-darwin11/4.2.1/include/ -I$IOSSDKROOT/usr/include/"
46+
export CPP="$CCACHE /usr/bin/cpp $CPPFLAGS"
47+
export MACOSX_DEPLOYMENT_TARGET=
48+
49+
# make a link to a differently named library for who knows what reason
50+
#mkdir extralibs||echo "foo"
51+
#ln -s "$IOSSDKROOT/usr/lib/libgcc_s.1.dylib" extralibs/libgcc_s.10.4.dylib || echo "sdf"
52+
53+
# Copy our setup for modules
54+
try cp $PROJECTROOT/src/python_files/ModulesSetup Modules/Setup.local
55+
try cat $PROJECTROOT/src/python_files/ModulesSetup.mobile >> Modules/Setup.local
56+
try cp $PROJECTROOT/src/python_files/_scproxy.py Lib/_scproxy.py
57+
58+
try ./configure CC="$ARM_CC" LD="$ARM_LD" \
59+
CFLAGS="$ARM_CFLAGS" \
60+
LDFLAGS="$ARM_LDFLAGS -Lextralibs/ -lsqlite3 -L$BUILDROOT/lib -undefined dynamic_lookup" \
61+
--without-pymalloc \
62+
--disable-toolbox-glue \
63+
--host=armv7-apple-darwin \
64+
--prefix=/python \
65+
--without-doc-strings
66+
67+
# with undefined lookup, checks in configure just failed :(
68+
try patch -p1 < $PROJECTROOT/src/python_files/Python-$PYTHON_VERSION-pyconfig.patch
69+
try patch -p1 < $PROJECTROOT/src/python_files/Python-$PYTHON_VERSION-ctypes_duplicate.patch
70+
71+
try make -j4 HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen \
72+
CROSS_COMPILE_TARGET=yes
73+
74+
try make install HOSTPYTHON=./hostpython CROSS_COMPILE_TARGET=yes \
75+
prefix="$BUILDROOT/python"
76+
77+
try mv -f $BUILDROOT/python/lib/libpython2.7.a $BUILDROOT/lib/
78+
79+
deduplicate $BUILDROOT/lib/libpython2.7.a

bin/prepare.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
. $(dirname $0)/environment.sh
4+
5+
try $(dirname $0)/prepare-libffi.sh
6+
try $(dirname $0)/prepare-python.sh
7+
8+
echo '== Projects prepared'

patch/libffi/3.0.13/ffi-sysv.S.patch

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
--- libffi-3.0.13-old/src/arm/sysv.S 2013-03-16 12:19:39.000000000 +0100
2+
+++ libffi-3.0.13-new/src/arm/sysv.S 2013-08-26 19:33:28.000000000 +0200
3+
@@ -109,58 +109,35 @@
4+
#define UNWIND @
5+
#endif
6+
7+
+.syntax unified
8+
9+
#if defined(__thumb__) && !defined(__THUMB_INTERWORK__)
10+
-.macro ARM_FUNC_START name
11+
- .text
12+
- .align 0
13+
- .thumb
14+
- .thumb_func
15+
-#ifdef __APPLE__
16+
- ENTRY($0)
17+
+#define ARM_FUNC_START(name) \
18+
+ .text; \
19+
+ .align 4; \
20+
+ .thumb; \
21+
+ .thumb_func; \
22+
+ ENTRY(name); \
23+
+ bx pc; \
24+
+ nop; \
25+
+ .arm; \
26+
+ UNWIND .fnstart; \
27+
+_L__##name:
28+
#else
29+
- ENTRY(\name)
30+
-#endif
31+
- bx pc
32+
- nop
33+
- .arm
34+
- UNWIND .fnstart
35+
-/* A hook to tell gdb that we've switched to ARM mode. Also used to call
36+
- directly from other local arm routines. */
37+
-#ifdef __APPLE__
38+
-_L__$0:
39+
-#else
40+
-_L__\name:
41+
-#endif
42+
-.endm
43+
-#else
44+
-.macro ARM_FUNC_START name
45+
- .text
46+
- .align 0
47+
- .arm
48+
-#ifdef __APPLE__
49+
- ENTRY($0)
50+
-#else
51+
- ENTRY(\name)
52+
-#endif
53+
+#define ARM_FUNC_START(name) \
54+
+ .text; \
55+
+ .align 4; \
56+
+ .arm; \
57+
+ ENTRY(name); \
58+
UNWIND .fnstart
59+
-.endm
60+
#endif
61+
62+
-.macro RETLDM regs=, cond=, dirn=ia
63+
+.macro RETLDM
64+
#if defined (__INTERWORKING__)
65+
- .ifc "\regs",""
66+
- ldr\cond lr, [sp], #4
67+
- .else
68+
- ldm\cond\dirn sp!, {\regs, lr}
69+
- .endif
70+
- bx\cond lr
71+
+ ldr lr, [sp], #4
72+
+ bx lr
73+
#else
74+
- .ifc "\regs",""
75+
- ldr\cond pc, [sp], #4
76+
- .else
77+
- ldm\cond\dirn sp!, {\regs, pc}
78+
- .endif
79+
+ ldr pc, [sp], #4
80+
#endif
81+
.endm
82+
83+
@@ -170,8 +147,7 @@
84+
@ r3: fig->flags
85+
@ sp+0: ecif.rvalue
86+
87+
- @ This assumes we are using gas.
88+
-ARM_FUNC_START ffi_call_SYSV
89+
+ARM_FUNC_START(ffi_call_SYSV)
90+
@ Save registers
91+
stmfd sp!, {r0-r3, fp, lr}
92+
UNWIND .save {r0-r3, fp, lr}
93+
@@ -228,7 +204,7 @@
94+
#if defined(__SOFTFP__) || defined(__ARM_EABI__)
95+
cmpne r3, #FFI_TYPE_DOUBLE
96+
#endif
97+
- stmeqia r2, {r0, r1}
98+
+ stmiaeq r2, {r0, r1}
99+
100+
#if !defined(__SOFTFP__) && !defined(__ARM_EABI__)
101+
beq LSYM(Lepilogue)
102+
@@ -266,7 +242,7 @@
103+
void *args;
104+
*/
105+
106+
-ARM_FUNC_START ffi_closure_SYSV
107+
+ARM_FUNC_START(ffi_closure_SYSV)
108+
UNWIND .pad #16
109+
add ip, sp, #16
110+
stmfd sp!, {ip, lr}
111+
@@ -345,7 +321,7 @@
112+
@ r3: fig->flags
113+
@ sp+0: ecif.rvalue
114+
115+
-ARM_FUNC_START ffi_call_VFP
116+
+ARM_FUNC_START(ffi_call_VFP)
117+
@ Save registers
118+
stmfd sp!, {r0-r3, fp, lr}
119+
UNWIND .save {r0-r3, fp, lr}
120+
@@ -410,7 +386,7 @@
121+
beq LSYM(Lepilogue_vfp)
122+
123+
cmp r3, #FFI_TYPE_SINT64
124+
- stmeqia r2, {r0, r1}
125+
+ stmiaeq r2, {r0, r1}
126+
beq LSYM(Lepilogue_vfp)
127+
128+
cmp r3, #FFI_TYPE_FLOAT
129+
@@ -433,7 +409,7 @@
130+
.size CNAME(ffi_call_VFP),.ffi_call_VFP_end-CNAME(ffi_call_VFP)
131+
132+
133+
-ARM_FUNC_START ffi_closure_VFP
134+
+ARM_FUNC_START(ffi_closure_VFP)
135+
fstmfdd sp!, {d0-d7}
136+
@ r0-r3, then d0-d7
137+
UNWIND .pad #80

0 commit comments

Comments
 (0)