11#
22# Useful targets:
33# - all - build everything
4+ # - macOS - build everything for macOS
45# - iOS - build everything for iOS
56# - tvOS - build everything for tvOS
67# - watchOS - build everything for watchOS
8+ # - OpenSSL.framework-macOS - build OpenSSL.framework for macOS
79# - OpenSSL.framework-iOS - build OpenSSL.framework for iOS
810# - OpenSSL.framework-tvOS - build OpenSSL.framework for tvOS
911# - 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
12+ # - BZip2.framework-macOS - build BZip2.framework for macOS
13+ # - BZip2.framework-iOS - build BZip2.framework for iOS
14+ # - BZip2.framework-tvOS - build BZip2.framework for tvOS
15+ # - BZip2.framework-watchOS - build BZip2.framework for watchOS
16+ # - XZ.framework-macOS - build XZ.framework for macOS
17+ # - XZ.framework-iOS - build XZ.framework for iOS
18+ # - XZ.framework-tvOS - build XZ.framework for tvOS
19+ # - XZ.framework-watchOS - build XZ.framework for watchOS
20+ # - Python.framework-macOS - build Python.framework for macOS
1621# - Python.framework-iOS - build Python.framework for iOS
1722# - Python.framework-tvOS - build Python.framework for tvOS
1823# - Python.framework-watchOS - build Python.framework for watchOS
19- # - Python-host - build host python
2024
2125# Current director
2226PROJECT_DIR =$(shell pwd)
2327
24- BUILD_NUMBER =5
28+ BUILD_NUMBER =6
2529
2630# Version of packages that will be compiled by this meta-package
2731PYTHON_VERSION =3.4.2
2832PYTHON_VER =$(basename $(PYTHON_VERSION ) )
2933
3034OPENSSL_VERSION_NUMBER =1.0.2
31- OPENSSL_REVISION =f
35+ OPENSSL_REVISION =h
3236OPENSSL_VERSION =$(OPENSSL_VERSION_NUMBER )$(OPENSSL_REVISION )
3337
3438BZIP2_VERSION =1.0.6
3539
3640XZ_VERSION =5.2.2
3741
3842# Supported OS
39- OS =iOS tvOS watchOS
43+ OS =macOS iOS tvOS watchOS
44+
45+ # macOS targets
46+ TARGETS-macOS =macosx.x86_64
4047
4148# iOS targets
4249TARGETS-iOS =iphonesimulator.x86_64 iphonesimulator.i386 iphoneos.armv7 iphoneos.armv7s iphoneos.arm64
@@ -126,34 +133,20 @@ downloads/xz-$(XZ_VERSION).tgz:
126133
127134# Clean the Python project
128135clean-Python :
129- rm -rf build/Python-$(PYTHON_VERSION ) -host build/* /Python-$(PYTHON_VERSION ) -* \
130- build/* /libpython$(PYTHON_VER ) .a build/* /pyconfig-* .h \
136+ rm -rf \
137+ build/* /Python-$(PYTHON_VERSION ) -* \
138+ build/* /libpython$(PYTHON_VER ) .a \
139+ build/* /pyconfig-* .h \
131140 build/* /Python.framework
132141
133142# Download original Python source code archive.
134143downloads/Python-$(PYTHON_VERSION ) .tgz :
135144 mkdir -p downloads
136145 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
137146
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
147+ PYTHON_DIR-macOS =build/macOS/Python-$(PYTHON_VERSION ) -macosx.x86_64
148+ PYTHON_HOST =$(PYTHON_DIR-macOS ) /dist/lib/libpython$(PYTHON_VER ) .a
150149
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- #
157150# Build for specified target (from $(TARGETS))
158151#
159152# Parameters:
@@ -199,12 +192,19 @@ ifeq ($$(findstring iphone,$$(SDK-$1)),)
199192 # Patch Configure to build for tvOS or watchOS, not iOS
200193 LC_ALL=C sed -ie 's/-D_REENTRANT:iOS/-D_REENTRANT:$2/' $$(OPENSSL_DIR-$1)/Configure
201194endif
195+
202196 # Configure the build
197+ ifeq ($2,macOS)
198+ cd $$(OPENSSL_DIR-$1) && \
199+ CC="$$(CC-$1)" \
200+ ./Configure darwin64-x86_64-cc --openssldir=$(PROJECT_DIR)/$$(OPENSSL_DIR-$1)
201+ else
203202 cd $$(OPENSSL_DIR-$1) && \
204203 CC="$$(CC-$1)" \
205204 CROSS_TOP="$$(dir $$(SDK_ROOT-$1)).." \
206205 CROSS_SDK="$$(notdir $$(SDK_ROOT-$1))" \
207206 ./Configure iphoneos-cross no-asm --openssldir=$(PROJECT_DIR)/$$(OPENSSL_DIR-$1)
207+ endif
208208
209209# Build OpenSSL
210210$$(OPENSSL_DIR-$1 ) /libssl.a $$(OPENSSL_DIR-$1 ) /libcrypto.a: $$(OPENSSL_DIR-$1 ) /Makefile
@@ -253,20 +253,29 @@ $$(PYTHON_DIR-$1)/Makefile: downloads/Python-$(PYTHON_VERSION).tgz $(PYTHON_HOST
253253 tar zxf downloads/Python-$(PYTHON_VERSION ) .tgz --strip-components 1 -C $$(PYTHON_DIR-$1 )
254254 # Apply target Python patches
255255 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
256+
257257 # Configure target Python
258- cd $$(PYTHON_DIR-$1 ) && PATH=$(PROJECT_DIR ) /$(PYTHON_DIR-host ) /dist/bin:$(PATH ) ./configure \
258+ ifeq ($2,macOS)
259+ cd $$(PYTHON_DIR-$1) && PATH=$(PROJECT_DIR)/$(PYTHON_DIR-macOS)/dist/bin:$(PATH) ./configure \
260+ CC="$$(CC-$1)" LD="$$(CC-$1)" \
261+ --prefix=$(PROJECT_DIR)/$$(PYTHON_DIR-$1)/dist \
262+ --without-pymalloc --without-doc-strings --disable-ipv6 --without-ensurepip \
263+ $$(PYTHON_CONFIGURE-$2)
264+ else
265+ cp -f $(PROJECT_DIR)/patch/Python/Setup.embedded $$(PYTHON_DIR-$1)/Modules/Setup.embedded
266+ cd $$(PYTHON_DIR-$1) && PATH=$(PROJECT_DIR)/$(PYTHON_DIR-macOS)/dist/bin:$(PATH) ./configure \
259267 CC="$$(CC-$1)" LD="$$(CC-$1)" \
260268 --host=$$(MACHINE_DETAILED-$1)-apple-ios --build=x86_64-apple-darwin$(shell uname -r) \
261269 --prefix=$(PROJECT_DIR)/$$(PYTHON_DIR-$1)/dist \
262270 --without-pymalloc --without-doc-strings --disable-ipv6 --without-ensurepip \
263271 ac_cv_file__dev_ptmx=no ac_cv_file__dev_ptc=no \
264272 $$(PYTHON_CONFIGURE-$2)
273+ endif
265274
266275# 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
276+ $$(PYTHON_DIR-$1 ) /dist/lib/libpython$(PYTHON_VER ) .a: build/$2/OpenSSL.framework build/$2/BZip2.framework build/$2/XZ.framework $$(PYTHON_DIR-$1 ) /Makefile
268277 # Build target Python
269- cd $$(PYTHON_DIR-$1 ) && PATH=$(PROJECT_DIR ) /$(PYTHON_DIR-host ) /dist/bin:$(PATH ) make all install
278+ cd $$(PYTHON_DIR-$1 ) && PATH=$(PROJECT_DIR ) /$(PYTHON_DIR-macOS ) /dist/bin:$(PATH ) make all install
270279
271280build/$2/$$(pyconfig.h-$1 ) : $$(PYTHON_DIR-$1 ) /dist/include/python$(PYTHON_VER ) /pyconfig.h
272281 cp -f $$^ $$@
@@ -296,8 +305,8 @@ define build
296305$$(foreach target,$$(TARGETS-$1 ) ,$$(eval $$(call build-target,$$(target ) ,$1) ) )
297306
298307OPENSSL_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
308+ BZIP2_FRAMEWORK -$1=build/$1/BZip2.framework
309+ XZ_FRAMEWORK -$1=build/$1/XZ.framework
301310PYTHON_FRAMEWORK-$1=build/$1/Python.framework
302311PYTHON_RESOURCES-$1=$$(PYTHON_FRAMEWORK-$1 ) /Versions/$(PYTHON_VER ) /Resources
303312
@@ -310,14 +319,14 @@ dist/Python-$(PYTHON_VERSION)-$1-support.b$(BUILD_NUMBER).tar.gz: $$(OPENSSL_FRA
310319 mkdir -p dist
311320 tar zcvf $$@ -C build/$1 $$(notdir $$^ )
312321
322+ # Build OpenSSL.framework
313323OpenSSL.framework-$1: $$(OPENSSL_FRAMEWORK-$1 )
314324
315- # Build OpenSSL.framework
316325$$(OPENSSL_FRAMEWORK-$1 ) : build/$1/libssl.a build/$1/libcrypto.a
317326 # Create framework directory structure
318327 mkdir -p $$(OPENSSL_FRAMEWORK-$1 ) /Versions/$(OPENSSL_VERSION )
319328
320- # Copy the headers (use the version from the simulator because reasons)
329+ # Copy the headers
321330 cp -f -r $$(OPENSSL_DIR-$$(firstword $$(TARGETS-$1 ) ) ) /include $$(OPENSSL_FRAMEWORK-$1 ) /Versions/$(OPENSSL_VERSION ) /Headers
322331
323332 # Create the fat library
@@ -337,17 +346,51 @@ build/$1/libcrypto.a: $$(foreach target,$$(TARGETS-$1),$$(OPENSSL_DIR-$$(target)
337346 mkdir -p build/$1
338347 xcrun lipo -create -output $$@ $$^
339348
340- BZip2-$1: $$(BZIP2_LIB-$1 )
349+ # Build BZip2.framework
350+ BZip2.framework-$1: $$(BZIP2_FRAMEWORK-$1 )
351+
352+ $$(BZIP2_FRAMEWORK-$1 ) : build/$1/bzip2/lib/libbz2.a
353+ # Create framework directory structure
354+ mkdir -p $$(BZIP2_FRAMEWORK-$1 ) /Versions/$(BZIP2_VERSION )
355+
356+ # Copy the headers
357+ cp -f -r build/$1/bzip2/include $$(BZIP2_FRAMEWORK-$1 ) /Versions/$(BZIP2_VERSION ) /Headers
358+
359+ # Create the fat library
360+ xcrun libtool -no_warning_for_no_symbols -static \
361+ -o $$(BZIP2_FRAMEWORK-$1 ) /Versions/$(BZIP2_VERSION ) /bzip2 $$^
362+
363+ # Create symlinks
364+ ln -fs $(BZIP2_VERSION ) $$(BZIP2_FRAMEWORK-$1 ) /Versions/Current
365+ ln -fs Versions/Current/Headers $$(BZIP2_FRAMEWORK-$1 )
366+ ln -fs Versions/Current/bzip2 $$(BZIP2_FRAMEWORK-$1 )
341367
342368build/$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 ) $$^
369+ mkdir -p build/$1
370+ xcrun lipo -create -o $$@ $$^
345371
346- XZ-$1: $$(XZ_LIB-$1 )
372+ # Build XZ.framework
373+ XZ.framework-$1: $$(XZ_FRAMEWORK-$1 )
374+
375+ $$(XZ_FRAMEWORK-$1 ) : build/$1/xz/lib/liblzma.a
376+ # Create framework directory structure
377+ mkdir -p $$(XZ_FRAMEWORK-$1 ) /Versions/$(XZ_VERSION )
378+
379+ # Copy the headers
380+ cp -f -r build/$1/xz/include $$(XZ_FRAMEWORK-$1 ) /Versions/$(XZ_VERSION ) /Headers
381+
382+ # Create the fat library
383+ xcrun libtool -no_warning_for_no_symbols -static \
384+ -o $$(XZ_FRAMEWORK-$1 ) /Versions/$(XZ_VERSION ) /xz $$^
385+
386+ # Create symlinks
387+ ln -fs $(XZ_VERSION ) $$(XZ_FRAMEWORK-$1 ) /Versions/Current
388+ ln -fs Versions/Current/Headers $$(XZ_FRAMEWORK-$1 )
389+ ln -fs Versions/Current/xz $$(XZ_FRAMEWORK-$1 )
347390
348391build/$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 ) $$^
392+ mkdir -p build/$1
393+ xcrun lipo -create -o $$@ $$^
351394
352395Python.framework-$1: $$(PYTHON_FRAMEWORK-$1 )
353396
0 commit comments