├── .gitignore ├── CONTRIBUTING.md ├── patch └── Python │ ├── lib-exclude.lst │ └── Setup.embedded ├── LICENSE ├── README.rst └── Makefile /.gitignore: -------------------------------------------------------------------------------- 1 | *.swo 2 | *.swp 3 | src/* 4 | archive/* 5 | build/* 6 | downloads/* 7 | diff/* 8 | dist/* 9 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | PyBee <3's contributions! 4 | 5 | Please be aware, PyBee operates under a Code of Conduct. 6 | 7 | See [CONTRIBUTING to PyBee](http://pybee.org/contributing) for details. 8 | 9 | -------------------------------------------------------------------------------- /patch/Python/lib-exclude.lst: -------------------------------------------------------------------------------- 1 | config-* 2 | ctypes/test/* 3 | curses/* 4 | distutils/tests/* 5 | ensurepip/* 6 | idlelib/* 7 | lib2to3/tests/* 8 | site-packages/* 9 | sqlite3/test/* 10 | test/* 11 | tkinter/* 12 | turtle.py 13 | turtledemo/* 14 | wsgiref/* 15 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014-2016 Russell Keith-Magee. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | WARNING: This project is DEPRECATED 2 | ----------------------------------- 3 | 4 | It has been replaced by the multi-platform `Python-Apple-support`_ package 5 | 6 | .. _Python-Apple-support: https://github.com/pybee/Python-Apple-support 7 | 8 | Python iOS Support 9 | ================== 10 | 11 | This is a meta-package for building a version of Python that can be embedded 12 | into an iOS, tvOS or watchOS project. 13 | 14 | It works by downloading, patching, and building a fat binary OpenSSL and 15 | Python, and packaging them both in iOS Framework format. 16 | 17 | The binaries support the ``$(ARCHS_STANDARD)`` set - that is, armv7 and 18 | arm64 for iOS devices, arm64 for appleTV devices, and armv7k for watchOS. 19 | This should enable the code to run on: 20 | 21 | * iPhone 22 | - iPhone 4s 23 | - iPhone 5 24 | - iPhone 5c 25 | - iPhone 5s 26 | - iPhone 6 27 | - iPhone 6 Plus 28 | - iPhone 6s 29 | - iPhone 6s Plus 30 | * iPad Pro 31 | * iPad 32 | - iPad 2 33 | - iPad (3rd gen) 34 | - iPad (4th gen) 35 | - iPad Air 36 | - iPad Air 2 37 | - iPad retina 38 | * iPad Mini 39 | - iPad Mini (1st gen) 40 | - iPad Mini 2 41 | - iPad Mini 3 42 | - iPad Mini 4 43 | * iPod Touch 44 | - iPod Touch (4th gen) 45 | - iPod Touch (5th gen) 46 | - iPod Touch (6th gen) 47 | * Apple TV 48 | - 4th gen 49 | * Apple Watch 50 | 51 | This repository branch builds a packaged version of **Python 3.5.1**. 52 | Other Python versions are available by cloning other branches of the main 53 | repository. 54 | 55 | Quickstart 56 | ---------- 57 | 58 | Pre-built versions of the frameworks can be downloaded `for iOS`_, 59 | `for tvOS`_, and `for watchOS`_, and added to your project. 60 | 61 | Alternatively, to build the frameworks on your own, download/clone this 62 | repository, and then in the root directory, and run: 63 | 64 | * `make` (or `make all`) to build everything. 65 | * `make iOS` to build everything for iOS. 66 | * `make tvOS` to build everything for tvOS. 67 | * `make watchOS` to build everything for watchOS. 68 | 69 | This should: 70 | 71 | 1. Download the original source packages 72 | 2. Patch them as required for compatibility with the selected OS 73 | 3. Build the packages as XCode-compatible frameworks. 74 | 75 | The build products will be in the `build` directory; the compiled frameworks 76 | will be in the `dist` directory. 77 | 78 | .. _for iOS: https://github.com/pybee/Python-iOS-support/releases/download/3.4.2-b5/Python-3.4.2-iOS-support.b5.tar.gz 79 | .. _for tvOS: https://github.com/pybee/Python-iOS-support/releases/download/3.4.2-b5/Python-3.4.2-iOS-support.b5.tar.gz 80 | .. _for watchOS: https://github.com/pybee/Python-iOS-support/releases/download/3.4.2-b5/Python-3.4.2-iOS-support.b5.tar.gz 81 | 82 | Acknowledgements 83 | ---------------- 84 | 85 | The approach to framework packaging is drawn from `Jeff Verkoeyen`_, and 86 | `Ernesto García's`_ tutorials. 87 | 88 | .. _Jeff Verkoeyen: https://github.com/jverkoey/iOS-Framework 89 | .. _Ernesto García's: http://www.raywenderlich.com/41377/creating-a-static-library-in-ios-tutorial 90 | -------------------------------------------------------------------------------- /patch/Python/Setup.embedded: -------------------------------------------------------------------------------- 1 | ##################################################################### 2 | # Static compilation instructions for all binary modules. 3 | ##################################################################### 4 | 5 | _bisect _bisectmodule.c 6 | _bz2 _bz2module.c -I$(srcdir)/../bzip2/include -L$(srcdir)/../bzip2/lib -lbz2 7 | _codecs_cn cjkcodecs/_codecs_cn.c 8 | _codecs_hk cjkcodecs/_codecs_hk.c 9 | _codecs_iso2022 cjkcodecs/_codecs_iso2022.c 10 | _codecs_jp cjkcodecs/_codecs_jp.c 11 | _codecs_kr cjkcodecs/_codecs_kr.c 12 | _codecs_tw cjkcodecs/_codecs_tw.c 13 | _crypt _cryptmodule.c 14 | _csv _csv.c 15 | _datetime _datetimemodule.c 16 | _elementtree _elementtree.c \ 17 | -I$(srcdir)/Modules/expat 18 | -DHAVE_EXPAT_CONFIG_H -DUSE_PYEXPAT_CAPI 19 | _heapq _heapqmodule.c 20 | _json _json.c 21 | _lsprof _lsprof.o rotatingtree.c 22 | _lzma _lzmamodule.c -I$(srcdir)/../xz/include -L$(srcdir)/../xz/lib -llzma 23 | _md5 md5module.c 24 | _multibytecodec cjkcodecs/multibytecodec.c 25 | _multiprocessing _multiprocessing/multiprocessing.c _multiprocessing/semaphore.c 26 | _opcode _opcode.c 27 | _pickle _pickle.c 28 | _posixsubprocess _posixsubprocess.c 29 | _random _randommodule.c 30 | _sha1 sha1module.c 31 | _sha256 sha256module.c 32 | _sha512 sha512module.c 33 | _socket socketmodule.c 34 | _sqlite3 -I$(srcdir)/Modules/_sqlite -DMODULE_NAME='\"sqlite3\"' -DSQLITE_OMIT_LOAD_EXTENSION -lsqlite3 \ 35 | _sqlite/cache.c \ 36 | _sqlite/connection.c \ 37 | _sqlite/cursor.c \ 38 | _sqlite/microprotocols.c \ 39 | _sqlite/module.c \ 40 | _sqlite/prepare_protocol.c \ 41 | _sqlite/row.c \ 42 | _sqlite/statement.c \ 43 | _sqlite/util.c 44 | _ssl _ssl.c -I$(srcdir)/../OpenSSL.framework/Headers -framework OpenSSL -F$(srcdir)/.. -DUSE_SSL 45 | _struct _struct.c 46 | array arraymodule.c 47 | audioop audioop.c 48 | binascii binascii.c 49 | cmath cmathmodule.c _math.c 50 | fcntl fcntlmodule.c 51 | grp grpmodule.c 52 | math mathmodule.c 53 | mmap mmapmodule.c 54 | parser parsermodule.c 55 | pyexpat expat/xmlparse.c \ 56 | expat/xmlrole.c \ 57 | expat/xmltok.c \ 58 | pyexpat.c \ 59 | -I$(srcdir)/Modules/expat \ 60 | -DHAVE_EXPAT_CONFIG_H -DUSE_PYEXPAT_CAPI 61 | resource resource.c 62 | select selectmodule.c 63 | syslog syslogmodule.c 64 | termios termios.c 65 | time timemodule.c 66 | unicodedata unicodedata.c 67 | zlib zlibmodule.c -I$(prefix)/include -lz 68 | 69 | ##################################################################### 70 | # Testing modules 71 | ##################################################################### 72 | _ctypes_test _ctypes/_ctypes_test.c 73 | _testbuffer _testbuffer.c 74 | _testcapi _testcapimodule.c 75 | _testimportmultiple _testimportmultiple.c 76 | 77 | ##################################################################### 78 | # Modules that require additional frameworks 79 | ##################################################################### 80 | #_curses _cursesmodule.c -lcurses -ltermcap 81 | #_curses_panel _curses_panel.c -lpanel -lncurses 82 | #_dbm _dbmmodule.c 83 | #_gdbm _gdbmmodule.c -I/usr/local/include -L/usr/local/lib -lgdbm 84 | #_tkinter _tkinter.c tkappinit.c -DWITH_APPINIT -I... -L... 85 | #nis nismodule.c -lnsl 86 | #ossaudiodev 87 | #readline readline.c -lreadline -ltermcap 88 | #spwd spwdmodule.c 89 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Useful targets: 3 | # - all - build everything 4 | # - iOS - build everything for iOS 5 | # - tvOS - build everything for tvOS 6 | # - watchOS - build everything for watchOS 7 | # - OpenSSL.framework-iOS - build OpenSSL.framework for iOS 8 | # - OpenSSL.framework-tvOS - build OpenSSL.framework for tvOS 9 | # - OpenSSL.framework-watchOS - build OpenSSL.framework for watchOS 10 | # - BZip2-iOS - build BZip2 library for iOS 11 | # - BZip2-tvOS - build BZip2 library for tvOS 12 | # - BZip2-watchOS - build BZip2 library for watchOS 13 | # - XZ-iOS - build XZ library for iOS 14 | # - XZ-tvOS - build XZ library for tvOS 15 | # - XZ-watchOS - build XZ library for watchOS 16 | # - Python.framework-iOS - build Python.framework for iOS 17 | # - Python.framework-tvOS - build Python.framework for tvOS 18 | # - Python.framework-watchOS - build Python.framework for watchOS 19 | # - Python-host - build host python 20 | 21 | # Current director 22 | PROJECT_DIR=$(shell pwd) 23 | 24 | BUILD_NUMBER=5 25 | 26 | # Version of packages that will be compiled by this meta-package 27 | PYTHON_VERSION=3.4.2 28 | PYTHON_VER=$(basename $(PYTHON_VERSION)) 29 | 30 | OPENSSL_VERSION_NUMBER=1.0.2 31 | OPENSSL_REVISION=f 32 | OPENSSL_VERSION=$(OPENSSL_VERSION_NUMBER)$(OPENSSL_REVISION) 33 | 34 | BZIP2_VERSION=1.0.6 35 | 36 | XZ_VERSION=5.2.2 37 | 38 | # Supported OS 39 | OS=iOS tvOS watchOS 40 | 41 | # iOS targets 42 | TARGETS-iOS=iphonesimulator.x86_64 iphonesimulator.i386 iphoneos.armv7 iphoneos.armv7s iphoneos.arm64 43 | CFLAGS-iOS=-miphoneos-version-min=7.0 44 | CFLAGS-iphoneos.armv7=-fembed-bitcode 45 | CFLAGS-iphoneos.armv7s=-fembed-bitcode 46 | CFLAGS-iphoneos.arm64=-fembed-bitcode 47 | 48 | # tvOS targets 49 | TARGETS-tvOS=appletvsimulator.x86_64 appletvos.arm64 50 | CFLAGS-tvOS=-mtvos-version-min=9.0 51 | CFLAGS-appletvos.arm64=-fembed-bitcode 52 | PYTHON_CONFIGURE-tvOS=ac_cv_func_sigaltstack=no 53 | 54 | # watchOS targets 55 | TARGETS-watchOS=watchsimulator.i386 watchos.armv7k 56 | CFLAGS-watchOS=-mwatchos-version-min=2.0 57 | CFLAGS-watchos.armv7k=-fembed-bitcode 58 | PYTHON_CONFIGURE-watchOS=ac_cv_func_sigaltstack=no 59 | 60 | # override machine types for arm64 61 | MACHINE_DETAILED-arm64=aarch64 62 | MACHINE_SIMPLE-arm64=arm 63 | 64 | all: $(foreach os,$(OS),$(os)) 65 | 66 | # Clean all builds 67 | clean: 68 | rm -rf build dist 69 | 70 | # Full clean - includes all downloaded products 71 | distclean: clean 72 | rm -rf downloads 73 | 74 | downloads: downloads/openssl-$(OPENSSL_VERSION).tgz downloads/bzip2-$(BZIP2_VERSION).tgz downloads/xz-$(XZ_VERSION).tgz downloads/Python-$(PYTHON_VERSION).tgz 75 | 76 | ########################################################################### 77 | # OpenSSL 78 | # These build instructions adapted from the scripts developed by 79 | # Felix Shchulze (@x2on) https://github.com/x2on/OpenSSL-for-iPhone 80 | ########################################################################### 81 | 82 | # Clean the OpenSSL project 83 | clean-OpenSSL: 84 | rm -rf build/*/openssl-$(OPENSSL_VERSION)-* \ 85 | build/*/libssl.a build/*/libcrypto.a \ 86 | build/*/OpenSSL.framework 87 | 88 | # Download original OpenSSL source code archive. 89 | downloads/openssl-$(OPENSSL_VERSION).tgz: 90 | mkdir -p downloads 91 | -if [ ! -e downloads/openssl-$(OPENSSL_VERSION).tgz ]; then curl --fail -L http://openssl.org/source/openssl-$(OPENSSL_VERSION).tar.gz -o downloads/openssl-$(OPENSSL_VERSION).tgz; fi 92 | if [ ! -e downloads/openssl-$(OPENSSL_VERSION).tgz ]; then curl --fail -L http://openssl.org/source/old/$(OPENSSL_VERSION_NUMBER)/openssl-$(OPENSSL_VERSION).tar.gz -o downloads/openssl-$(OPENSSL_VERSION).tgz; fi 93 | 94 | 95 | ########################################################################### 96 | # BZip2 97 | ########################################################################### 98 | 99 | # Clean the bzip2 project 100 | clean-bzip2: 101 | rm -rf build/*/bzip2-$(BZIP2_VERSION)-* \ 102 | build/*/bzip2 103 | 104 | # Download original OpenSSL source code archive. 105 | downloads/bzip2-$(BZIP2_VERSION).tgz: 106 | mkdir -p downloads 107 | if [ ! -e downloads/bzip2-$(BZIP2_VERSION).tgz ]; then curl --fail -L http://www.bzip.org/$(BZIP2_VERSION)/bzip2-$(BZIP2_VERSION).tar.gz -o downloads/bzip2-$(BZIP2_VERSION).tgz; fi 108 | 109 | ########################################################################### 110 | # XZ (LZMA) 111 | ########################################################################### 112 | 113 | # Clean the XZ project 114 | clean-xz: 115 | rm -rf build/*/xz-$(XZ_VERSION)-* \ 116 | build/*/xz 117 | 118 | # Download original OpenSSL source code archive. 119 | downloads/xz-$(XZ_VERSION).tgz: 120 | mkdir -p downloads 121 | if [ ! -e downloads/xz-$(XZ_VERSION).tgz ]; then curl --fail -L http://tukaani.org/xz/xz-$(XZ_VERSION).tar.gz -o downloads/xz-$(XZ_VERSION).tgz; fi 122 | 123 | ########################################################################### 124 | # Python 125 | ########################################################################### 126 | 127 | # Clean the Python project 128 | clean-Python: 129 | rm -rf build/Python-$(PYTHON_VERSION)-host build/*/Python-$(PYTHON_VERSION)-* \ 130 | build/*/libpython$(PYTHON_VER).a build/*/pyconfig-*.h \ 131 | build/*/Python.framework 132 | 133 | # Download original Python source code archive. 134 | downloads/Python-$(PYTHON_VERSION).tgz: 135 | mkdir -p downloads 136 | if [ ! -e downloads/Python-$(PYTHON_VERSION).tgz ]; then curl -L https://www.python.org/ftp/python/$(PYTHON_VERSION)/Python-$(PYTHON_VERSION).tgz > downloads/Python-$(PYTHON_VERSION).tgz; fi 137 | 138 | PYTHON_DIR-host=build/Python-$(PYTHON_VERSION)-host 139 | PYTHON_HOST=$(PYTHON_DIR-host)/dist/bin/python$(PYTHON_VER) 140 | 141 | Python-host: $(PYTHON_HOST) 142 | 143 | # Unpack host Python 144 | $(PYTHON_DIR-host)/Makefile: downloads/Python-$(PYTHON_VERSION).tgz 145 | # Unpack host Python 146 | mkdir -p $(PYTHON_DIR-host) 147 | tar zxf downloads/Python-$(PYTHON_VERSION).tgz --strip-components 1 -C $(PYTHON_DIR-host) 148 | # Configure host Python 149 | cd $(PYTHON_DIR-host) && ./configure --prefix=$(PROJECT_DIR)/$(PYTHON_DIR-host)/dist --without-ensurepip 150 | 151 | # Build host Python 152 | $(PYTHON_DIR-host)/dist/bin/python$(PYTHON_VER): $(PYTHON_DIR-host)/Makefile 153 | # Build host Python 154 | make -C $(PYTHON_DIR-host) all install 155 | 156 | # 157 | # Build for specified target (from $(TARGETS)) 158 | # 159 | # Parameters: 160 | # - $1 - target 161 | # - $2 - OS 162 | define build-target 163 | ARCH-$1=$$(subst .,,$$(suffix $1)) 164 | ifdef MACHINE_DETAILED-$$(ARCH-$1) 165 | MACHINE_DETAILED-$1=$$(MACHINE_DETAILED-$$(ARCH-$1)) 166 | else 167 | MACHINE_DETAILED-$1=$$(ARCH-$1) 168 | endif 169 | ifdef MACHINE_SIMPLE-$$(ARCH-$1) 170 | MACHINE_SIMPLE-$1=$$(MACHINE_SIMPLE-$$(ARCH-$1)) 171 | else 172 | MACHINE_SIMPLE-$1=$$(ARCH-$1) 173 | endif 174 | SDK-$1=$$(basename $1) 175 | 176 | SDK_ROOT-$1=$$(shell xcrun --sdk $$(SDK-$1) --show-sdk-path) 177 | CC-$1=xcrun --sdk $$(SDK-$1) clang\ 178 | -arch $$(ARCH-$1) --sysroot=$$(SDK_ROOT-$1) $$(CFLAGS-$2) $$(CFLAGS-$1) 179 | LDFLAGS-$1=-arch $$(ARCH-$1) -isysroot=$$(SDK_ROOT-$1) 180 | 181 | OPENSSL_DIR-$1=build/$2/openssl-$(OPENSSL_VERSION)-$1 182 | BZIP2_DIR-$1=build/$2/bzip2-$(BZIP2_VERSION)-$1 183 | XZ_DIR-$1=build/$2/xz-$(XZ_VERSION)-$1 184 | PYTHON_DIR-$1=build/$2/Python-$(PYTHON_VERSION)-$1 185 | pyconfig.h-$1=pyconfig-$$(ARCH-$1).h 186 | 187 | # Unpack OpenSSL 188 | $$(OPENSSL_DIR-$1)/Makefile: downloads/openssl-$(OPENSSL_VERSION).tgz 189 | # Unpack sources 190 | mkdir -p $$(OPENSSL_DIR-$1) 191 | tar zxf downloads/openssl-$(OPENSSL_VERSION).tgz --strip-components 1 -C $$(OPENSSL_DIR-$1) 192 | ifeq ($$(findstring simulator,$$(SDK-$1)),) 193 | # Tweak ui_openssl.c 194 | sed -ie "s!static volatile sig_atomic_t intr_signal;!static volatile intr_signal;!" $$(OPENSSL_DIR-$1)/crypto/ui/ui_openssl.c 195 | endif 196 | ifeq ($$(findstring iphone,$$(SDK-$1)),) 197 | # Patch apps/speed.c to not use fork() since it's not available on tvOS 198 | sed -ie 's/define HAVE_FORK 1/define HAVE_FORK 0/' $$(OPENSSL_DIR-$1)/apps/speed.c 199 | # Patch Configure to build for tvOS or watchOS, not iOS 200 | LC_ALL=C sed -ie 's/-D_REENTRANT:iOS/-D_REENTRANT:$2/' $$(OPENSSL_DIR-$1)/Configure 201 | endif 202 | # Configure the build 203 | cd $$(OPENSSL_DIR-$1) && \ 204 | CC="$$(CC-$1)" \ 205 | CROSS_TOP="$$(dir $$(SDK_ROOT-$1)).." \ 206 | CROSS_SDK="$$(notdir $$(SDK_ROOT-$1))" \ 207 | ./Configure iphoneos-cross no-asm --openssldir=$(PROJECT_DIR)/$$(OPENSSL_DIR-$1) 208 | 209 | # Build OpenSSL 210 | $$(OPENSSL_DIR-$1)/libssl.a $$(OPENSSL_DIR-$1)/libcrypto.a: $$(OPENSSL_DIR-$1)/Makefile 211 | # Make the build 212 | cd $$(OPENSSL_DIR-$1) && \ 213 | CC="$$(CC-$1)" \ 214 | CROSS_TOP="$$(dir $$(SDK_ROOT-$1)).." \ 215 | CROSS_SDK="$$(notdir $$(SDK_ROOT-$1))" \ 216 | make all 217 | 218 | # Unpack BZip2 219 | $$(BZIP2_DIR-$1)/Makefile: downloads/bzip2-$(BZIP2_VERSION).tgz 220 | # Unpack sources 221 | mkdir -p $$(BZIP2_DIR-$1) 222 | tar zxf downloads/bzip2-$(BZIP2_VERSION).tgz --strip-components 1 -C $$(BZIP2_DIR-$1) 223 | # Patch sources to use correct compiler 224 | sed -ie 's#CC=gcc#CC=$$(CC-$1)#' $$(BZIP2_DIR-$1)/Makefile 225 | # Patch sources to use correct install directory 226 | sed -ie 's#PREFIX=/usr/local#PREFIX=$(PROJECT_DIR)/build/$2/bzip2#' $$(BZIP2_DIR-$1)/Makefile 227 | 228 | # Build BZip2 229 | $$(BZIP2_DIR-$1)/libbz2.a: $$(BZIP2_DIR-$1)/Makefile 230 | cd $$(BZIP2_DIR-$1) && make install 231 | 232 | # Unpack XZ 233 | $$(XZ_DIR-$1)/Makefile: downloads/xz-$(XZ_VERSION).tgz 234 | # Unpack sources 235 | mkdir -p $$(XZ_DIR-$1) 236 | tar zxf downloads/xz-$(XZ_VERSION).tgz --strip-components 1 -C $$(XZ_DIR-$1) 237 | # Configure the build 238 | cd $$(XZ_DIR-$1) && ./configure \ 239 | CC="$$(CC-$1)" \ 240 | LDFLAGS="$$(LDFLAGS-$1)" \ 241 | --disable-shared --enable-static \ 242 | --host=$$(MACHINE_SIMPLE-$1)-apple-darwin \ 243 | --prefix=$(PROJECT_DIR)/build/$2/xz 244 | 245 | # Build XZ 246 | $$(XZ_DIR-$1)/src/liblzma/.libs/liblzma.a: $$(XZ_DIR-$1)/Makefile 247 | cd $$(XZ_DIR-$1) && make && make install 248 | 249 | # Unpack Python 250 | $$(PYTHON_DIR-$1)/Makefile: downloads/Python-$(PYTHON_VERSION).tgz $(PYTHON_HOST) 251 | # Unpack target Python 252 | mkdir -p $$(PYTHON_DIR-$1) 253 | tar zxf downloads/Python-$(PYTHON_VERSION).tgz --strip-components 1 -C $$(PYTHON_DIR-$1) 254 | # Apply target Python patches 255 | cd $$(PYTHON_DIR-$1) && patch -p1 < $(PROJECT_DIR)/patch/Python/Python.patch 256 | cp -f $(PROJECT_DIR)/patch/Python/Setup.embedded $$(PYTHON_DIR-$1)/Modules/Setup.embedded 257 | # Configure target Python 258 | cd $$(PYTHON_DIR-$1) && PATH=$(PROJECT_DIR)/$(PYTHON_DIR-host)/dist/bin:$(PATH) ./configure \ 259 | CC="$$(CC-$1)" LD="$$(CC-$1)" \ 260 | --host=$$(MACHINE_DETAILED-$1)-apple-ios --build=x86_64-apple-darwin$(shell uname -r) \ 261 | --prefix=$(PROJECT_DIR)/$$(PYTHON_DIR-$1)/dist \ 262 | --without-pymalloc --without-doc-strings --disable-ipv6 --without-ensurepip \ 263 | ac_cv_file__dev_ptmx=no ac_cv_file__dev_ptc=no \ 264 | $$(PYTHON_CONFIGURE-$2) 265 | 266 | # Build Python 267 | $$(PYTHON_DIR-$1)/dist/lib/libpython$(PYTHON_VER).a: build/$2/OpenSSL.framework build/$2/bzip2/lib/libbz2.a build/$2/xz/lib/liblzma.a $$(PYTHON_DIR-$1)/Makefile 268 | # Build target Python 269 | cd $$(PYTHON_DIR-$1) && PATH=$(PROJECT_DIR)/$(PYTHON_DIR-host)/dist/bin:$(PATH) make all install 270 | 271 | build/$2/$$(pyconfig.h-$1): $$(PYTHON_DIR-$1)/dist/include/python$(PYTHON_VER)/pyconfig.h 272 | cp -f $$^ $$@ 273 | 274 | # Dump vars (for test) 275 | vars-$1: 276 | @echo "ARCH-$1: $$(ARCH-$1)" 277 | @echo "MACHINE_DETAILED-$1: $$(MACHINE_DETAILED-$1)" 278 | @echo "SDK-$1: $$(SDK-$1)" 279 | @echo "SDK_ROOT-$1: $$(SDK_ROOT-$1)" 280 | @echo "CC-$1: $$(CC-$1)" 281 | endef 282 | 283 | # 284 | # Install target pyconfig.h 285 | # Parameters: 286 | # - $1 - target 287 | # - $2 - framework directory 288 | define install-target-pyconfig 289 | endef 290 | 291 | # 292 | # Build for specified OS (from $(OS)) 293 | # Parameters: 294 | # - $1 - OS 295 | define build 296 | $$(foreach target,$$(TARGETS-$1),$$(eval $$(call build-target,$$(target),$1))) 297 | 298 | OPENSSL_FRAMEWORK-$1=build/$1/OpenSSL.framework 299 | BZIP2_LIB-$1=build/$1/bzip2/lib/libbz2.a 300 | XZ_LIB-$1=build/$1/xz/lib/liblzma.a 301 | PYTHON_FRAMEWORK-$1=build/$1/Python.framework 302 | PYTHON_RESOURCES-$1=$$(PYTHON_FRAMEWORK-$1)/Versions/$(PYTHON_VER)/Resources 303 | 304 | $1: dist/Python-$(PYTHON_VERSION)-$1-support.b$(BUILD_NUMBER).tar.gz 305 | 306 | clean-$1: 307 | rm -rf build/$1 308 | 309 | dist/Python-$(PYTHON_VERSION)-$1-support.b$(BUILD_NUMBER).tar.gz: $$(OPENSSL_FRAMEWORK-$1) $$(PYTHON_FRAMEWORK-$1) 310 | mkdir -p dist 311 | tar zcvf $$@ -C build/$1 $$(notdir $$^) 312 | 313 | OpenSSL.framework-$1: $$(OPENSSL_FRAMEWORK-$1) 314 | 315 | # Build OpenSSL.framework 316 | $$(OPENSSL_FRAMEWORK-$1): build/$1/libssl.a build/$1/libcrypto.a 317 | # Create framework directory structure 318 | mkdir -p $$(OPENSSL_FRAMEWORK-$1)/Versions/$(OPENSSL_VERSION) 319 | 320 | # Copy the headers (use the version from the simulator because reasons) 321 | cp -f -r $$(OPENSSL_DIR-$$(firstword $$(TARGETS-$1)))/include $$(OPENSSL_FRAMEWORK-$1)/Versions/$(OPENSSL_VERSION)/Headers 322 | 323 | # Create the fat library 324 | xcrun libtool -no_warning_for_no_symbols -static \ 325 | -o $$(OPENSSL_FRAMEWORK-$1)/Versions/$(OPENSSL_VERSION)/OpenSSL $$^ 326 | 327 | # Create symlinks 328 | ln -fs $(OPENSSL_VERSION) $$(OPENSSL_FRAMEWORK-$1)/Versions/Current 329 | ln -fs Versions/Current/Headers $$(OPENSSL_FRAMEWORK-$1) 330 | ln -fs Versions/Current/OpenSSL $$(OPENSSL_FRAMEWORK-$1) 331 | 332 | build/$1/libssl.a: $$(foreach target,$$(TARGETS-$1),$$(OPENSSL_DIR-$$(target))/libssl.a) 333 | mkdir -p build/$1 334 | xcrun lipo -create -output $$@ $$^ 335 | 336 | build/$1/libcrypto.a: $$(foreach target,$$(TARGETS-$1),$$(OPENSSL_DIR-$$(target))/libcrypto.a) 337 | mkdir -p build/$1 338 | xcrun lipo -create -output $$@ $$^ 339 | 340 | BZip2-$1: $$(BZIP2_LIB-$1) 341 | 342 | build/$1/bzip2/lib/libbz2.a: $$(foreach target,$$(TARGETS-$1),$$(BZIP2_DIR-$$(target))/libbz2.a) 343 | mkdir -p build/$1/bzip2/lib 344 | xcrun lipo -create -o $$(BZIP2_LIB-$1) $$^ 345 | 346 | XZ-$1: $$(XZ_LIB-$1) 347 | 348 | build/$1/xz/lib/liblzma.a: $$(foreach target,$$(TARGETS-$1),$$(XZ_DIR-$$(target))/src/liblzma/.libs/liblzma.a) 349 | mkdir -p build/$1/xz/lib 350 | xcrun lipo -create -o $$(XZ_LIB-$1) $$^ 351 | 352 | Python.framework-$1: $$(PYTHON_FRAMEWORK-$1) 353 | 354 | # Build Python.framework 355 | $$(PYTHON_FRAMEWORK-$1): build/$1/libpython$(PYTHON_VER).a $$(foreach target,$$(TARGETS-$1),build/$1/$$(pyconfig.h-$$(target))) 356 | mkdir -p $$(PYTHON_RESOURCES-$1)/include/python$(PYTHON_VER) 357 | 358 | # Copy the headers. The headers are the same for every platform, except for pyconfig.h 359 | cp -f -r $$(PYTHON_DIR-$$(firstword $$(TARGETS-$1)))/dist/include/python$(PYTHON_VER) $$(PYTHON_FRAMEWORK-$1)/Versions/$(PYTHON_VER)/Headers 360 | cp -f $$(filter %.h,$$^) $$(PYTHON_FRAMEWORK-$1)/Versions/$(PYTHON_VER)/Headers 361 | cp -f $$(PYTHON_DIR-$$(firstword $$(TARGETS-$1)))/iOS/include/pyconfig.h $$(PYTHON_FRAMEWORK-$1)/Versions/$(PYTHON_VER)/Headers 362 | 363 | # Copy Python.h and pyconfig.h into the resources include directory 364 | cp -f -r $$(PYTHON_FRAMEWORK-$1)/Versions/$(PYTHON_VER)/Headers/pyconfig*.h $$(PYTHON_RESOURCES-$1)/include/python$(PYTHON_VER) 365 | cp -f -r $$(PYTHON_FRAMEWORK-$1)/Versions/$(PYTHON_VER)/Headers/Python.h $$(PYTHON_RESOURCES-$1)/include/python$(PYTHON_VER) 366 | 367 | # Copy the standard library from the simulator build 368 | ifneq ($(TEST),) 369 | cp -f -r $$(PYTHON_DIR-$$(firstword $$(TARGETS-$1)))/dist/lib $$(PYTHON_RESOURCES-$1) 370 | # Remove the pieces of the resources directory that aren't needed: 371 | rm -f $$(PYTHON_RESOURCES-$1)/lib/libpython$(PYTHON_VER).a 372 | rm -rf $$(PYTHON_RESOURCES-$1)/lib/pkgconfig 373 | else 374 | mkdir -p $$(PYTHON_RESOURCES-$1)/lib 375 | cd $$(PYTHON_DIR-$$(firstword $$(TARGETS-$1)))/dist/lib/python$(PYTHON_VER) && \ 376 | zip -x@$(PROJECT_DIR)/patch/Python/lib-exclude.lst -r $(PROJECT_DIR)/$$(PYTHON_RESOURCES-$1)/lib/python$(subst .,,$(PYTHON_VER)) * 377 | endif 378 | 379 | # Copy fat library 380 | cp -f $$(filter %.a,$$^) $$(PYTHON_FRAMEWORK-$1)/Versions/$(PYTHON_VER)/Python 381 | 382 | # Create symlinks 383 | ln -fs $(PYTHON_VER) $$(PYTHON_FRAMEWORK-$1)/Versions/Current 384 | ln -fs Versions/Current/Headers $$(PYTHON_FRAMEWORK-$1) 385 | ln -fs Versions/Current/Resources $$(PYTHON_FRAMEWORK-$1) 386 | ln -fs Versions/Current/Python $$(PYTHON_FRAMEWORK-$1) 387 | 388 | # Build libpython fat library 389 | build/$1/libpython$(PYTHON_VER).a: $$(foreach target,$$(TARGETS-$1),$$(PYTHON_DIR-$$(target))/dist/lib/libpython$(PYTHON_VER).a) 390 | # Create a fat binary for the libPython library 391 | mkdir -p build/$1 392 | xcrun lipo -create -output $$@ $$^ 393 | endef 394 | 395 | $(foreach os,$(OS),$(eval $(call build,$(os)))) 396 | --------------------------------------------------------------------------------