|
| 1 | +PROJECTDIR=$(shell pwd) |
| 2 | + |
1 | 3 | # iOS Build variables.
|
2 |
| -SDKVER=$(xcodebuild -showsdks | fgrep "iphoneos" | tail -n 1 | awk '{print $2}') |
3 |
| -DEVROOT=$(xcode-select -print-path)/Platforms/iPhoneOS.platform/Developer |
4 |
| -IOSSDKROOT=$DEVROOT/SDKs/iPhoneOS$(SDKVER).sdk |
| 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 | + |
| 9 | +OSX_SDK_ROOT=$(shell xcrun --sdk macosx --show-sdk-path) |
5 | 10 |
|
6 | 11 | # Version of packages that will be compiled by this meta-package
|
7 | 12 | PYTHON_VERSION=2.7.1
|
8 | 13 | FFI_VERSION=3.0.13
|
9 | 14 |
|
10 |
| -all: working-dirs build/ffi.framework |
| 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) |
| 19 | + |
| 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) |
| 22 | + |
| 23 | + |
| 24 | +all: working-dirs build/ffi.framework build/Python.framework |
11 | 25 |
|
12 | 26 | # Clean all builds
|
13 | 27 | clean:
|
@@ -50,20 +64,88 @@ src/libffi-$(FFI_VERSION): downloads/libffi-$(FFI_VERSION).tar.gz
|
50 | 64 | tar xvf downloads/libffi-$(FFI_VERSION).tar.gz
|
51 | 65 | mv libffi-$(FFI_VERSION) src
|
52 | 66 |
|
53 |
| -# Patch libffi source with iOS patches |
54 |
| -# Produce a dummy "patches-applied" file to mark that this has happened. |
55 |
| -src/libffi-$(FFI_VERSION)/patches-applied: src/libffi-$(FFI_VERSION) |
| 67 | +# Patch and build the framework |
| 68 | +build/ffi.framework: src/libffi-$(FFI_VERSION) |
56 | 69 | cd src/libffi-$(FFI_VERSION) && patch -p1 -N < ../../patch/libffi/$(FFI_VERSION)/ffi-sysv.S.patch
|
57 |
| - cd src/libffi-$(FFI_VERSION) && patch -p1 -N < ../../patch/libffi/$(FFI_VERSION)/project.pbxproj.patch | tee patches-applied |
58 |
| - |
59 |
| -# Generate iOS specific source and headers |
60 |
| -src/libffi-$(FFI_VERSION)/ios/include/ffi.h: src/libffi-$(FFI_VERSION)/patches-applied |
| 70 | + cd src/libffi-$(FFI_VERSION) && patch -p1 -N < ../../patch/libffi/$(FFI_VERSION)/project.pbxproj.patch |
61 | 71 | cd src/libffi-$(FFI_VERSION) && python generate-ios-source-and-headers.py
|
62 |
| - |
63 |
| -# Build the iOS project |
64 |
| -src/libffi-$(FFI_VERSION)/build/Release-universal/ffi.framework: src/libffi-$(FFI_VERSION)/ios/include/ffi.h |
65 | 72 | cd src/libffi-$(FFI_VERSION) && xcodebuild -project libffi.xcodeproj -target "Framework" -configuration Release -sdk iphoneos$(SDKVER) OTHER_CFLAGS="-no-integrated-as"
|
66 |
| - |
67 |
| -# Collate the libffi project |
68 |
| -build/ffi.framework: src/libffi-$(FFI_VERSION)/build/Release-universal/ffi.framework |
69 | 73 | cp -a src/libffi-$(FFI_VERSION)/build/Release-universal/ffi.framework build
|
| 74 | + |
| 75 | +########################################################################### |
| 76 | +# Python |
| 77 | +########################################################################### |
| 78 | + |
| 79 | +# Clean the Python project |
| 80 | +clean-Python: |
| 81 | + rm -rf src/Python-$(PYTHON_VERSION) |
| 82 | + rm -rf build/Python.framework |
| 83 | + |
| 84 | +# Down original Python source code archive. |
| 85 | +downloads/Python-$(PYTHON_VERSION).tar.bz2: |
| 86 | + curl -L https://www.python.org/ftp/python/$(PYTHON_VERSION)/Python-$(PYTHON_VERSION).tar.bz2 > downloads/Python-$(PYTHON_VERSION).tar.bz2 |
| 87 | + |
| 88 | +# Unpack Python source archive into src working directory |
| 89 | +src/Python-$(PYTHON_VERSION): downloads/Python-$(PYTHON_VERSION).tar.bz2 |
| 90 | + tar xvf downloads/Python-$(PYTHON_VERSION).tar.bz2 |
| 91 | + mv Python-$(PYTHON_VERSION) src |
| 92 | + |
| 93 | +# Patch Python source with iOS patches |
| 94 | +# Produce a dummy "patches-applied" file to mark that this has happened. |
| 95 | +src/Python-$(PYTHON_VERSION)/build_simulator: src/Python-$(PYTHON_VERSION) |
| 96 | + # Apply patches |
| 97 | + cp patch/Python/$(PYTHON_VERSION)/ModulesSetup src/Python-$(PYTHON_VERSION)/Modules/Setup.local |
| 98 | + cp patch/Python/$(PYTHON_VERSION)/_scproxy.py src/Python-$(PYTHON_VERSION)/Lib/_scproxy.py |
| 99 | + cd src/Python-$(PYTHON_VERSION) && patch -p1 -N < ../../patch/Python/$(PYTHON_VERSION)/dynload.patch |
| 100 | + cd src/Python-$(PYTHON_VERSION) && patch -p1 -N < ../../patch/Python/$(PYTHON_VERSION)/ssize-t-max.patch |
| 101 | + 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 |
| 115 | + 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 |
| 118 | + |
| 119 | +src/Python-$(PYTHON_VERSION)/build_iphone: src/Python-$(PYTHON_VERSION)/build_simulator |
| 120 | + # Apply extra patches for iOS native build |
| 121 | + cp patch/Python/$(PYTHON_VERSION)/ModulesSetup src/Python-$(PYTHON_VERSION)/Modules/Setup.local |
| 122 | + cat patch/Python/$(PYTHON_VERSION)/ModulesSetup.mobile >> src/Python-$(PYTHON_VERSION)/Modules/Setup.local |
| 123 | + 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 |
| 135 | + |
| 136 | +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 |
0 commit comments