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

Commit eb96685

Browse files
committed
Working build of Python framework.
1 parent e4c004f commit eb96685

File tree

3 files changed

+114
-67
lines changed

3 files changed

+114
-67
lines changed

Makefile

Lines changed: 102 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
PROJECTDIR=$(shell pwd)
22

33
# iOS Build variables.
4-
SDKDESCRIPTION=$(shell xcodebuild -showsdks | fgrep "iphoneos" | tail -n 1)
5-
SDKVER=$(word 2, $(SDKDESCRIPTION))
6-
DEVROOT=$(shell xcode-select -print-path)/Platforms/iPhoneOS.platform/Developer
7-
IOSSDKROOT=$(DEVROOT)/SDKs/iPhoneOS$(SDKVER).sdk
8-
94
OSX_SDK_ROOT=$(shell xcrun --sdk macosx --show-sdk-path)
105

116
# Version of packages that will be compiled by this meta-package
127
PYTHON_VERSION=2.7.1
138
FFI_VERSION=3.0.13
149

15-
# ARM build flags
16-
ARM_CC=$(shell xcrun -find -sdk iphoneos clang)
17-
ARM_AR=$(shell xcrun -find -sdk iphoneos ar)
18-
ARM_LD=$(shell xcrun -find -sdk iphoneos ld)
10+
# IPHONE build commands and flags
11+
IPHONE_SDK_ROOT=$(shell xcrun --sdk iphoneos --show-sdk-path)
12+
IPHONE_CC=$(shell xcrun -find -sdk iphoneos clang)
13+
IPHONE_LD=$(shell xcrun -find -sdk iphoneos ld)
14+
IPHONE_CFLAGS=-arch armv7 -pipe -no-cpp-precomp -isysroot $(IPHONE_SDK_ROOT) -miphoneos-version-min=4.0
15+
IPHONE_LDFLAGS=-arch armv7 -isysroot $(IPHONE_SDK_ROOT) -miphoneos-version-min=4.0
1916

20-
ARM_CFLAGS=-arch armv7 -pipe -no-cpp-precomp -isysroot $(IOSSDKROOT) -miphoneos-version-min=$(SDKVER)
21-
ARM_LDFLAGS=-arch armv7 -isysroot $(IOSSDKROOT) -miphoneos-version-min=$(SDKVER)
17+
# IPHONESIMULATOR build commands and flags
18+
IPHONESIMULATOR_SDK_ROOT=$(shell xcrun --sdk iphonesimulator --show-sdk-path)
19+
IPHONESIMULATOR_CC=$(shell xcrun -find -sdk iphonesimulator clang)
20+
IPHONESIMULATOR_LD=$(shell xcrun -find -sdk iphonesimulator ld)
21+
IPHONESIMULATOR_CFLAGS=-arch i386 -pipe -no-cpp-precomp -isysroot $(IPHONESIMULATOR_SDK_ROOT) -miphoneos-version-min=4.0
22+
IPHONESIMULATOR_LDFLAGS=-arch i386 -isysroot $(IPHONESIMULATOR_SDK_ROOT) -miphoneos-version-min=4.0
2223

2324

2425
all: working-dirs build/ffi.framework build/Python.framework
@@ -80,6 +81,7 @@ build/ffi.framework: src/libffi-$(FFI_VERSION)
8081
clean-Python:
8182
rm -rf src/Python-$(PYTHON_VERSION)
8283
rm -rf build/Python.framework
84+
rm -rf build/python
8385

8486
# Down original Python source code archive.
8587
downloads/Python-$(PYTHON_VERSION).tar.bz2:
@@ -92,60 +94,105 @@ src/Python-$(PYTHON_VERSION): downloads/Python-$(PYTHON_VERSION).tar.bz2
9294

9395
# Patch Python source with iOS patches
9496
# Produce a dummy "patches-applied" file to mark that this has happened.
95-
src/Python-$(PYTHON_VERSION)/build_simulator: src/Python-$(PYTHON_VERSION)
97+
src/Python-$(PYTHON_VERSION)/build: src/Python-$(PYTHON_VERSION)
9698
# Apply patches
9799
cp patch/Python/$(PYTHON_VERSION)/ModulesSetup src/Python-$(PYTHON_VERSION)/Modules/Setup.local
98100
cp patch/Python/$(PYTHON_VERSION)/_scproxy.py src/Python-$(PYTHON_VERSION)/Lib/_scproxy.py
99101
cd src/Python-$(PYTHON_VERSION) && patch -p1 -N < ../../patch/Python/$(PYTHON_VERSION)/dynload.patch
100102
cd src/Python-$(PYTHON_VERSION) && patch -p1 -N < ../../patch/Python/$(PYTHON_VERSION)/ssize-t-max.patch
101103
cd src/Python-$(PYTHON_VERSION) && patch -p1 -N < ../../patch/Python/$(PYTHON_VERSION)/static-_sqlite3.patch
102-
# Configure and make the x86 (simulator) build
103-
cd src/Python-$(PYTHON_VERSION) && ./configure CC="clang -Qunused-arguments -fcolor-diagnostics" LDFLAGS="-lsqlite3 -L../../build/ffi.framework" CFLAGS="-I../../build/ffi.framework/Headers --sysroot=$(OSX_SDK_ROOT)" --prefix=$(PROJECTDIR)/src/Python-$(PYTHON_VERSION)/build_simulator
104-
cd src/Python-$(PYTHON_VERSION) && make -j4 python.exe Parser/pgen libpython$(basename $(PYTHON_VERSION)).a install
105-
# Create the framework directory from the compiled resrouces
106-
mkdir -p build/Python.framework/Versions/$(basename $(PYTHON_VERSION))/
107-
cd build/Python.framework/Versions && ln -fs $(basename $(PYTHON_VERSION)) Current
108-
cp -r src/Python-$(PYTHON_VERSION)/build_simulator/include/python$(basename $(PYTHON_VERSION)) build/Python.framework/Versions/$(basename $(PYTHON_VERSION))/Headers
109-
cd build/Python.framework && ln -fs Versions/Current/Headers
110-
cp -r src/Python-$(PYTHON_VERSION)/build_simulator/lib/python$(basename $(PYTHON_VERSION)) build/Python.framework/Versions/$(basename $(PYTHON_VERSION))/Resources
111-
cd build/Python.framework && ln -fs Versions/Current/Resources
112-
# Temporarily move the x86 library into the framework dir to protect it from distclean
113-
mv src/Python-$(PYTHON_VERSION)/libpython$(basename $(PYTHON_VERSION)).a build/Python.framework
114-
# Clean out all the x86 build data
104+
# Configure and make the local build, providing compiled resources.
105+
# cd src/Python-$(PYTHON_VERSION) && ./configure CC="clang -Qunused-arguments -fcolor-diagnostics" LDFLAGS="-lsqlite3 -L../../build/ffi.framework" CFLAGS="-I../../build/ffi.framework/Headers --sysroot=$(OSX_SDK_ROOT)" --prefix=$(PROJECTDIR)/src/Python-$(PYTHON_VERSION)/build
106+
cd src/Python-$(PYTHON_VERSION) && ./configure CC="clang -Qunused-arguments -fcolor-diagnostics" LDFLAGS="-lsqlite3" CFLAGS="--sysroot=$(OSX_SDK_ROOT)" --prefix=$(PROJECTDIR)/src/Python-$(PYTHON_VERSION)/build
107+
cd src/Python-$(PYTHON_VERSION) && make -j4 python.exe Parser/pgen
108+
cd src/Python-$(PYTHON_VERSION) && mv python.exe hostpython
109+
cd src/Python-$(PYTHON_VERSION) && mv Parser/pgen Parser/hostpgen
110+
# # Clean out all the build data
115111
cd src/Python-$(PYTHON_VERSION) && make distclean
116-
# Restore the x86 library
117-
mv build/Python.framework/libpython$(basename $(PYTHON_VERSION)).a src/Python-$(PYTHON_VERSION)/build_simulator
118112

119-
src/Python-$(PYTHON_VERSION)/build_iphone: src/Python-$(PYTHON_VERSION)/build_simulator
120-
# Apply extra patches for iOS native build
113+
build/python/ios-simulator/Python: src/Python-$(PYTHON_VERSION)/build
114+
# Apply extra patches for iOS simulator build
115+
cp patch/Python/$(PYTHON_VERSION)/ModulesSetup src/Python-$(PYTHON_VERSION)/Modules/Setup.local
116+
cat patch/Python/$(PYTHON_VERSION)/ModulesSetup.mobile >> src/Python-$(PYTHON_VERSION)/Modules/Setup.local
117+
cp patch/Python/$(PYTHON_VERSION)/_scproxy.py src/Python-$(PYTHON_VERSION)/Lib/_scproxy.py
118+
cd src/Python-$(PYTHON_VERSION) && patch -p1 < ../../patch/Python/$(PYTHON_VERSION)/xcompile.patch
119+
cd src/Python-$(PYTHON_VERSION) && patch -p1 < ../../patch/Python/$(PYTHON_VERSION)/setuppath.patch
120+
# Configure and build Simulator library
121+
cd src/Python-$(PYTHON_VERSION) && ./configure CC="$(IPHONESIMULATOR_CC)" LD="$(IPHONESIMULATOR_LD)" CFLAGS="$(IPHONESIMULATOR_CFLAGS) -I../../build/ffi.framework/Headers" LDFLAGS="$(IPHONESIMULATOR_LDFLAGS) -L../../build/ffi.framework/ -lsqlite3 -undefined dynamic_lookup" --without-pymalloc --disable-toolbox-glue --prefix=/python --without-doc-strings
122+
cd src/Python-$(PYTHON_VERSION) && patch -p1 < ../../patch/Python/$(PYTHON_VERSION)/ctypes_duplicate.patch
123+
cd src/Python-$(PYTHON_VERSION) && patch -p1 < ../../patch/Python/$(PYTHON_VERSION)/pyconfig.patch
124+
mkdir -p build/python/ios-simulator
125+
cd src/Python-$(PYTHON_VERSION) && make altbininstall libinstall inclinstall libainstall HOSTPYTHON=./hostpython CROSS_COMPILE_TARGET=yes prefix="../../build/python/ios-simulator"
126+
# Relocate and rename the libpython binary
127+
cd build/python/ios-simulator/lib && mv libpython$(basename $(PYTHON_VERSION)).a ../Python
128+
# Clean out all the build data
129+
cd src/Python-$(PYTHON_VERSION) && make distclean
130+
# Reverse the source patches.
131+
cd src/Python-$(PYTHON_VERSION) && patch -p1 -R < ../../patch/Python/$(PYTHON_VERSION)/xcompile.patch
132+
cd src/Python-$(PYTHON_VERSION) && patch -p1 -R < ../../patch/Python/$(PYTHON_VERSION)/setuppath.patch
133+
cd src/Python-$(PYTHON_VERSION) && patch -p1 -R < ../../patch/Python/$(PYTHON_VERSION)/ctypes_duplicate.patch
134+
# cd src/Python-$(PYTHON_VERSION) && patch -p1 -R < ../../patch/Python/$(PYTHON_VERSION)/pyconfig.patch
135+
# Clean up build directory
136+
cd build/python/ios-simulator/lib/python2.7 && rm -rf *test* lib* wsgiref bsddb curses idlelib hotshot
137+
cd build/python/ios-simulator/lib/python2.7 && find . -iname '*.pyc' | xargs rm
138+
cd build/python/ios-simulator/lib/python2.7 && find . -iname '*.py' | xargs rm
139+
cd build/python/ios-simulator/lib && rm -rf pkgconfig
140+
141+
build/python/ios-armv7/Python: src/Python-$(PYTHON_VERSION)/build
142+
# Apply extra patches for iPhone build
121143
cp patch/Python/$(PYTHON_VERSION)/ModulesSetup src/Python-$(PYTHON_VERSION)/Modules/Setup.local
122144
cat patch/Python/$(PYTHON_VERSION)/ModulesSetup.mobile >> src/Python-$(PYTHON_VERSION)/Modules/Setup.local
123145
cp patch/Python/$(PYTHON_VERSION)/_scproxy.py src/Python-$(PYTHON_VERSION)/Lib/_scproxy.py
124-
cd src/Python-$(PYTHON_VERSION) && patch -p1 -N < ../../patch/Python/$(PYTHON_VERSION)/xcompile.patch
125-
cd src/Python-$(PYTHON_VERSION) && patch -p1 -N < ../../patch/Python/$(PYTHON_VERSION)/setuppath.patch
126-
# Configure and build iOS library
127-
cd src/Python-$(PYTHON_VERSION) && ./configure CC="$(ARM_CC)" LD="$(ARM_LD)" CFLAGS="$(ARM_CFLAGS) -I../../build/ffi.framework/Headers" LDFLAGS="$(ARM_LDFLAGS) -L../../build/ffi.framework/ -lsqlite3 -undefined dynamic_lookup" --without-pymalloc --disable-toolbox-glue --host=armv7-apple-darwin --prefix=/python --without-doc-strings
128-
cd src/Python-$(PYTHON_VERSION) && patch -p1 -N < ../../patch/Python/$(PYTHON_VERSION)/ctypes_duplicate.patch
129-
cd src/Python-$(PYTHON_VERSION) && patch -p1 -N < ../../patch/Python/$(PYTHON_VERSION)/pyconfig.patch
130-
cd src/Python-$(PYTHON_VERSION) && make -j4 libpython$(basename $(PYTHON_VERSION)).a
131-
132-
build/Python.framework: src/Python-$(PYTHON_VERSION)/build_iphone
133-
xcrun lipo -create -output build/Python.framework/Versions/Current/libpython.a src/Python-$(PYTHON_VERSION)/build_simulator/libpython$(basename $(PYTHON_VERSION)).a src/Python-$(PYTHON_VERSION)/libpython$(basename $(PYTHON_VERSION)).a
134-
cd build/Python.framework && ln -fs Versions/Current/libpython.a
146+
cd src/Python-$(PYTHON_VERSION) && patch -p1 < ../../patch/Python/$(PYTHON_VERSION)/xcompile.patch
147+
cd src/Python-$(PYTHON_VERSION) && patch -p1 < ../../patch/Python/$(PYTHON_VERSION)/setuppath.patch
148+
# Configure and build iPhone library
149+
cd src/Python-$(PYTHON_VERSION) && ./configure CC="$(IPHONE_CC)" LD="$(IPHONE_LD)" CFLAGS="$(IPHONE_CFLAGS) -I../../build/ffi.framework/Headers" LDFLAGS="$(IPHONE_LDFLAGS) -L../../build/ffi.framework/ -lsqlite3 -undefined dynamic_lookup" --without-pymalloc --disable-toolbox-glue --host=armv7-apple-darwin --prefix=/python --without-doc-strings
150+
cd src/Python-$(PYTHON_VERSION) && patch -p1 < ../../patch/Python/$(PYTHON_VERSION)/ctypes_duplicate.patch
151+
cd src/Python-$(PYTHON_VERSION) && patch -p1 < ../../patch/Python/$(PYTHON_VERSION)/pyconfig.patch
152+
mkdir -p build/python/ios-armv7
153+
cd src/Python-$(PYTHON_VERSION) && make altbininstall libinstall inclinstall libainstall HOSTPYTHON=./hostpython CROSS_COMPILE_TARGET=yes prefix="../../build/python/ios-armv7"
154+
# Relocate and rename the libpython binary
155+
cd build/python/ios-armv7/lib && mv libpython$(basename $(PYTHON_VERSION)).a ../Python
156+
# Clean out all the build data
157+
cd src/Python-$(PYTHON_VERSION) && make distclean
158+
# Reverse the source patches.
159+
cd src/Python-$(PYTHON_VERSION) && patch -p1 -R < ../../patch/Python/$(PYTHON_VERSION)/xcompile.patch
160+
cd src/Python-$(PYTHON_VERSION) && patch -p1 -R < ../../patch/Python/$(PYTHON_VERSION)/setuppath.patch
161+
cd src/Python-$(PYTHON_VERSION) && patch -p1 -R < ../../patch/Python/$(PYTHON_VERSION)/ctypes_duplicate.patch
162+
# cd src/Python-$(PYTHON_VERSION) && patch -p1 -R < ../../patch/Python/$(PYTHON_VERSION)/pyconfig.patch
163+
# Clean up build directory
164+
cd build/python/ios-armv7/lib/python2.7 && rm -rf *test* lib* wsgiref bsddb curses idlelib hotshot
165+
cd build/python/ios-armv7/lib/python2.7 && find . -iname '*.pyc' | xargs rm
166+
cd build/python/ios-armv7/lib/python2.7 && find . -iname '*.py' | xargs rm
167+
cd build/python/ios-armv7/lib && rm -rf pkgconfig
168+
169+
build/Python.framework: build/python/ios-simulator/Python build/python/ios-armv7/Python
170+
# Create the framework directory from the compiled resrouces
171+
mkdir -p build/Python.framework/Versions/$(basename $(PYTHON_VERSION))/
172+
cd build/Python.framework/Versions && ln -fs $(basename $(PYTHON_VERSION)) Current
173+
# Use the include and .pyo files from the simulator build.
174+
cp -r build/python/ios-simulator/include/python$(basename $(PYTHON_VERSION)) build/Python.framework/Versions/$(basename $(PYTHON_VERSION))/Headers
175+
cd build/Python.framework && ln -fs Versions/Current/Headers
176+
mkdir -p build/Python.framework/Versions/$(basename $(PYTHON_VERSION))/Resources
177+
cp -r build/python/ios-simulator/lib build/Python.framework/Versions/$(basename $(PYTHON_VERSION))/Resources/lib
178+
mkdir -p build/Python.framework/Versions/$(basename $(PYTHON_VERSION))/Resources/include/python2.7
179+
cp -r build/python/ios-simulator/include/python2.7/pyconfig.h build/Python.framework/Versions/$(basename $(PYTHON_VERSION))/Resources/include/python2.7/pyconfig.h
180+
cd build/Python.framework && ln -fs Versions/Current/Resources
181+
# Build a fat library with all targets included.
182+
xcrun lipo -create -output build/Python.framework/Versions/Current/Python build/python/ios-simulator/Python build/python/ios-armv7/Python
183+
cd build/Python.framework && ln -fs Versions/Current/Python
135184

136185
env:
137-
echo "SDKDESCRIPTION" $(SDKDESCRIPTION)
138-
echo "SDKVER" $(SDKVER)
139-
echo "DEVROOT" $(DEVROOT)
140-
echo "IOSSDKROOT" $(IOSSDKROOT)
141-
echo "OSX_SDK_ROOT" $(OSX_SDK_ROOT)
142-
echo "PYTHON_VERSION" $(PYTHON_VERSION)
143-
echo "FFI_VERSION" $(FFI_VERSION)
144-
echo "ARM_CC" $(ARM_CC)
145-
echo "ARM_AR" $(ARM_AR)
146-
echo "ARM_LD" $(ARM_LD)
147-
echo "ARM_CFLAGS" $(ARM_CFLAGS)
148-
echo "ARM_LDFLAGS" $(ARM_LDFLAGS)
149-
150-
151-
# build/Python.framework: src/Python-$(PYTHON_VERSION)/hostpython
186+
# PYTHON_VERSION $(PYTHON_VERSION)
187+
# FFI_VERSION $(FFI_VERSION)
188+
# OSX_SDK_ROOT $(OSX_SDK_ROOT)
189+
# IPHONE_SDK_ROOT $(IPHONE_SDK_ROOT)
190+
# IPHONE_CC $(IPHONE_CC)
191+
# IPHONE_LD $(IPHONE_LD)
192+
# IPHONE_CFLAGS $(IPHONE_CFLAGS)
193+
# IPHONE_LDFLAGS $(IPHONE_LDFLAGS)
194+
# IPHONESIMULATOR_SDK_ROOT $(IPHONESIMULATOR_SDK_ROOT)
195+
# IPHONESIMULATOR_CC $(IPHONESIMULATOR_CC)
196+
# IPHONESIMULATOR_LD $(IPHONESIMULATOR_LD)
197+
# IPHONESIMULATOR_CFLAGS $(IPHONESIMULATOR_CFLAGS)
198+
# IPHONESIMULATOR_LDFLAGS $(IPHONESIMULATOR_LDFLAGS)

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ Acknowledgements
2727
This work draws on the groundwork provided by `Kivy's iOS packaging tools.`_
2828

2929
The approach to framework packaging is drawn from `Jeff Verkoeyen`_, and
30-
`Ray Wenderlich's`_ tutorials.
30+
`Ernesto García's`_ tutorials.
3131

3232
.. _Kivy's iOS packaging tools.: https://github.com/kivy/kivy-ios
3333

3434
.. _Jeff Verkoeyen: https://github.com/jverkoey/iOS-Framework
35-
.. _Ray Wenderlich's: http://www.raywenderlich.com/41377/creating-a-static-library-in-ios-tutorial
35+
.. _Ernesto García's: http://www.raywenderlich.com/41377/creating-a-static-library-in-ios-tutorial

patch/Python/2.7.1/ctypes_duplicate.patch

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
--- Python2.7-old/Modules/_ctypes/cfield.c 2010-05-09 16:46:46.000000000 +0200
2-
+++ Python2.7-new/Modules/_ctypes/cfield.c 2013-08-27 00:21:15.000000000 +0200
3-
@@ -1747,24 +1747,6 @@
1+
--- Python-2.7-old/Modules/_ctypes/cfield.c 2010-05-09 22:46:46.000000000 +0800
2+
+++ Python-2.7-new/Modules/_ctypes/cfield.c 2014-04-27 16:06:06.000000000 +0800
3+
@@ -1747,31 +1747,4 @@
44
} ffi_type;
55
*/
66

@@ -22,13 +22,13 @@
2222
-ffi_type ffi_type_float = { sizeof(float), FLOAT_ALIGN, FFI_TYPE_FLOAT };
2323
-ffi_type ffi_type_double = { sizeof(double), DOUBLE_ALIGN, FFI_TYPE_DOUBLE };
2424
-
25-
#ifdef ffi_type_longdouble
26-
#undef ffi_type_longdouble
27-
#endif
28-
@@ -1772,6 +1754,4 @@
29-
ffi_type ffi_type_longdouble = { sizeof(long double), LONGDOUBLE_ALIGN,
30-
FFI_TYPE_LONGDOUBLE };
31-
25+
-#ifdef ffi_type_longdouble
26+
-#undef ffi_type_longdouble
27+
-#endif
28+
- /* This is already defined on OSX */
29+
-ffi_type ffi_type_longdouble = { sizeof(long double), LONGDOUBLE_ALIGN,
30+
- FFI_TYPE_LONGDOUBLE };
31+
-
3232
-ffi_type ffi_type_pointer = { sizeof(void *), VOID_P_ALIGN, FFI_TYPE_POINTER };
3333
-
3434
/*---------------- EOF ----------------*/

0 commit comments

Comments
 (0)