1
1
#
2
2
# Useful targets:
3
- # - all - build everything
4
- # - macOS - build everything for macOS
5
- # - iOS - build everything for iOS
6
- # - tvOS - build everything for tvOS
7
- # - watchOS - build everything for watchOS
3
+ # - all - build everything
4
+ # - macOS - build everything for macOS
5
+ # - iOS - build everything for iOS
6
+ # - tvOS - build everything for tvOS
7
+ # - watchOS - build everything for watchOS
8
8
# - OpenSSL-macOS - build OpenSSL for macOS
9
9
# - OpenSSL-iOS - build OpenSSL for iOS
10
10
# - OpenSSL-tvOS - build OpenSSL for tvOS
@@ -46,6 +46,7 @@ OS=macOS iOS tvOS watchOS
46
46
47
47
# macOS targets
48
48
TARGETS-macOS =macosx.x86_64
49
+ PYTHON_TARGETS-macOS =macOS
49
50
CFLAGS-macOS=-mmacosx-version-min =$(MACOSX_DEPLOYMENT_TARGET )
50
51
51
52
# iOS targets
@@ -88,7 +89,7 @@ update-patch:
88
89
# Generate a diff from the clone of the python/cpython Github repository
89
90
# Requireds patchutils (installable via `brew install patchutils`)
90
91
if [ -z " $( PYTHON_REPO_DIR) " ]; then echo " \n\nPYTHON_REPO_DIR must be set to the root of your Python github checkout\n\n" ; fi
91
- cd $(PYTHON_REPO_DIR ) && git diff -D v$(PYTHON_VERSION ) $(PYTHON_VER ) | filterdiff -X $(PROJECT_DIR ) /patch/Python/diff-exclude.lst -p 1 --clean > $(PROJECT_DIR ) /patch/Python/Python.patch
92
+ cd $(PYTHON_REPO_DIR ) && git diff -D v$(PYTHON_VERSION ) $(PYTHON_VER ) | filterdiff -X $(PROJECT_DIR ) /patch/Python/diff.exclude -p 1 --clean > $(PROJECT_DIR ) /patch/Python/Python.patch
92
93
93
94
# ##########################################################################
94
95
# OpenSSL
@@ -99,8 +100,9 @@ update-patch:
99
100
# Clean the OpenSSL project
100
101
clean-OpenSSL :
101
102
rm -rf build/* /openssl-$(OPENSSL_VERSION ) -* \
103
+ build/* /openssl \
102
104
build/* /libssl.a build/* /libcrypto.a \
103
- build/* /OpenSSL
105
+ build/* /Support/ OpenSSL
104
106
105
107
# Download original OpenSSL source code archive.
106
108
downloads/openssl-$(OPENSSL_VERSION ) .tgz :
@@ -114,9 +116,10 @@ downloads/openssl-$(OPENSSL_VERSION).tgz:
114
116
# ##########################################################################
115
117
116
118
# Clean the bzip2 project
117
- clean-bzip2 :
119
+ clean-BZip2 :
118
120
rm -rf build/* /bzip2-$(BZIP2_VERSION ) -* \
119
- build/* /bzip2
121
+ build/* /bzip2 \
122
+ build/* /Support/BZip2
120
123
121
124
# Download original BZip2 source code archive.
122
125
downloads/bzip2-$(BZIP2_VERSION ) .tgz :
@@ -128,9 +131,10 @@ downloads/bzip2-$(BZIP2_VERSION).tgz:
128
131
# ##########################################################################
129
132
130
133
# Clean the XZ project
131
- clean-xz :
134
+ clean-XZ :
132
135
rm -rf build/* /xz-$(XZ_VERSION ) -* \
133
- build/* /xz
136
+ build/* /xz \
137
+ build/* /Support/XZ
134
138
135
139
# Download original XZ source code archive.
136
140
downloads/xz-$(XZ_VERSION ) .tgz :
@@ -147,14 +151,15 @@ clean-Python:
147
151
build/* /Python-$(PYTHON_VERSION ) -* \
148
152
build/* /libpython$(PYTHON_VER ) .a \
149
153
build/* /pyconfig-* .h \
150
- build/* /Python
154
+ build/* /Support/ Python
151
155
152
156
# Download original Python source code archive.
153
157
downloads/Python-$(PYTHON_VERSION ) .tgz :
154
158
mkdir -p downloads
155
159
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
156
160
157
- PYTHON_DIR-macOS =build/macOS/Python-$(PYTHON_VERSION ) -macosx.x86_64
161
+ # Some Python targets needed to identify the host build
162
+ PYTHON_DIR-macOS =build/macOS/Python-$(PYTHON_VERSION ) -macOS
158
163
PYTHON_HOST =$(PYTHON_DIR-macOS ) /dist/lib/libpython$(PYTHON_VER ) .a
159
164
160
165
# Build for specified target (from $(TARGETS))
@@ -186,14 +191,6 @@ LDFLAGS-$1=-arch $$(ARCH-$1) -isysroot=$$(SDK_ROOT-$1)
186
191
OPENSSL_DIR-$1=build/$2/openssl-$(OPENSSL_VERSION ) -$1
187
192
BZIP2_DIR-$1=build/$2/bzip2-$(BZIP2_VERSION ) -$1
188
193
XZ_DIR-$1=build/$2/xz-$(XZ_VERSION ) -$1
189
- PYTHON_DIR-$1=build/$2/Python-$(PYTHON_VERSION ) -$1
190
- pyconfig.h-$1=pyconfig-$$(ARCH-$1 ) .h
191
-
192
- ifeq ($2,macOS)
193
- PYTHON_HOST_DEP-$1 =
194
- else
195
- PYTHON_HOST-$1 =$(PYTHON_HOST )
196
- endif
197
194
198
195
# Unpack OpenSSL
199
196
$$(OPENSSL_DIR-$1 ) /Makefile: downloads/openssl-$(OPENSSL_VERSION ) .tgz
@@ -216,7 +213,7 @@ endif
216
213
ifeq ($2,macOS)
217
214
cd $$(OPENSSL_DIR-$1) && \
218
215
CC="$$(CC-$1)" MACOSX_DEPLOYMENT_TARGET=$$(MACOSX_DEPLOYMENT_TARGET) \
219
- ./Configure darwin64-x86_64 -cc no-tests --prefix=$(PROJECT_DIR)/build/$2/openssl --openssldir=$(PROJECT_DIR)/build/$2/openssl
216
+ ./Configure darwin64-$$(ARCH-$1) -cc no-tests --prefix=$(PROJECT_DIR)/build/$2/openssl --openssldir=$(PROJECT_DIR)/build/$2/openssl
220
217
else
221
218
cd $$(OPENSSL_DIR-$1) && \
222
219
CC="$$(CC-$1)" \
@@ -265,38 +262,33 @@ $$(XZ_DIR-$1)/Makefile: downloads/xz-$(XZ_VERSION).tgz
265
262
$$(XZ_DIR-$1 ) /src/liblzma/.libs/liblzma.a: $$(XZ_DIR-$1 ) /Makefile
266
263
cd $$(XZ_DIR-$1 ) && make && make install
267
264
265
+ # macOS builds are compiled as a single build. As a result, the macOS Python
266
+ # build is configured in the `build` macro, rather than the `build-target` macro.
267
+ ifneq ($2,macOS)
268
+ PYTHON_DIR-$1 =build/$2/Python-$(PYTHON_VERSION ) -$1
269
+ pyconfig.h-$1 =pyconfig-$$(ARCH-$1 ) .h
270
+ PYTHON_HOST-$1 =$(PYTHON_HOST )
271
+
268
272
# Unpack Python
269
273
$$(PYTHON_DIR-$1 ) /Makefile : downloads/Python-$(PYTHON_VERSION ) .tgz $$(PYTHON_HOST-$1 )
270
274
# Unpack target Python
271
275
mkdir -p $$(PYTHON_DIR-$1 )
272
276
tar zxf downloads/Python-$(PYTHON_VERSION ) .tgz --strip-components 1 -C $$(PYTHON_DIR-$1 )
273
277
# Apply target Python patches
274
278
cd $$(PYTHON_DIR-$1 ) && patch -p1 < $(PROJECT_DIR ) /patch/Python/Python.patch
275
- # Configure target Python
276
- ifeq ($2,macOS)
277
- # A locally hosted Python requires a full Setup.local configuration
278
- # because there's no PYTHON_HOST_PLATFORM to cause Setup.local to be
279
- # generated
280
- cat $(PROJECT_DIR)/patch/Python/Setup.embedded $(PROJECT_DIR)/patch/Python/Setup.macOS-x86_64 > $$(PYTHON_DIR-$1)/Modules/Setup.local
281
- # Make a fully embedded macOS build
282
- cd $$(PYTHON_DIR-$1) && MACOSX_DEPLOYMENT_TARGET=$$(MACOSX_DEPLOYMENT_TARGET) ./configure \
283
- --prefix=$(PROJECT_DIR)/$$(PYTHON_DIR-$1)/dist \
284
- --without-doc-strings --enable-ipv6 --without-ensurepip \
285
- $$(PYTHON_CONFIGURE-$2)
286
- else
287
279
# Copy in the embedded and platform/arch configuration
288
280
cp -f $(PROJECT_DIR ) /patch/Python/Setup.embedded $$(PYTHON_DIR-$1 ) /Modules/Setup.embedded
289
281
if [ -e " $( PROJECT_DIR) /patch/Python/Setup.$2 -$$ (ARCH-$1 )" ]; then \
290
282
cp -f $(PROJECT_DIR ) /patch/Python/Setup.$2 -$$(ARCH-$1 ) $$(PYTHON_DIR-$1 ) /Modules/Setup.$2 -$$(ARCH-$1 ) ; fi
283
+ # Configure target Python
291
284
cd $$(PYTHON_DIR-$1 ) && PATH=$(PROJECT_DIR ) /$(PYTHON_DIR-macOS ) /dist/bin:$(PATH ) ./configure \
292
285
CC=" $$ (CC-$1 )" LD=" $$ (CC-$1 )" \
293
286
--host=$$(MACHINE_DETAILED-$1 ) -apple-$(shell echo $2 | tr '[:upper:]' '[:lower:]') \
294
- --build=x86_64-apple-darwin$(shell uname -r) \
287
+ --build=x86_64-apple-darwin \
295
288
--prefix=$(PROJECT_DIR ) /$$(PYTHON_DIR-$1 ) /dist \
296
289
--without-doc-strings --enable-ipv6 --without-ensurepip \
297
290
ac_cv_file__dev_ptmx=no ac_cv_file__dev_ptc=no \
298
291
$$(PYTHON_CONFIGURE-$2 )
299
- endif
300
292
301
293
# Build Python
302
294
$$(PYTHON_DIR-$1 ) /dist/lib/libpython$(PYTHON_VER ) .a : build/$2/Support/OpenSSL build/$2/Support/BZip2 build/$2/Support/XZ $$(PYTHON_DIR-$1 ) /Makefile
@@ -306,13 +298,21 @@ $$(PYTHON_DIR-$1)/dist/lib/libpython$(PYTHON_VER).a: build/$2/Support/OpenSSL bu
306
298
build/$2/$$(pyconfig.h-$1 ) : $$(PYTHON_DIR-$1 ) /dist/include/python$(PYTHON_VER ) /pyconfig.h
307
299
cp -f $$^ $$@
308
300
301
+ endif
302
+
309
303
# Dump vars (for test)
310
304
vars-$1:
311
305
@echo "ARCH-$1: $$(ARCH-$1 ) "
312
306
@echo "MACHINE_DETAILED-$1: $$(MACHINE_DETAILED-$1 ) "
313
307
@echo "SDK-$1: $$(SDK-$1 ) "
314
308
@echo "SDK_ROOT-$1: $$(SDK_ROOT-$1 ) "
315
309
@echo "CC-$1: $$(CC-$1 ) "
310
+ @echo "OPENSSL_DIR-$1: $$(OPENSSL_DIR-$1 ) "
311
+ @echo "BZIP2_DIR-$1: $$(BZIP2_DIR-$1 ) "
312
+ @echo "XZ_DIR-$1: $$(XZ_DIR-$1 ) "
313
+ @echo "PYTHON_DIR-$1: $$(PYTHON_DIR-$1 ) "
314
+ @echo "pyconfig.h-$1: $$(pyconfig.h-$1 ) "
315
+
316
316
endef
317
317
318
318
#
@@ -341,16 +341,11 @@ dist/Python-$(PYTHON_VER)-$1-support.$(BUILD_NUMBER).tar.gz: $$(BZIP2_FRAMEWORK-
341
341
echo "BZip2: $(BZIP2_VERSION ) " >> build/$1/Support/VERSIONS
342
342
echo "OpenSSL: $(OPENSSL_VERSION ) " >> build/$1/Support/VERSIONS
343
343
echo "XZ: $(XZ_VERSION ) " >> build/$1/Support/VERSIONS
344
- ifeq ($1,macOS)
345
- cp -r build/$1/Python-$(PYTHON_VERSION)-macosx.x86_64/dist build/$1/python
346
- mv build/$1/Support/VERSIONS build/$1/python/VERSIONS
347
- tar zcvf $$@ -X patch/Python/exclude.macOS -C build/$1/python `ls -A build/$1/python`
348
- else
344
+
349
345
# Build a "full" tarball with all content for test purposes
350
- tar zcvf dist/Python-$(PYTHON_VER)-$1-support.test-$(BUILD_NUMBER).tar.gz -X patch/Python/test-exclude.embedded -C build/$1/Support `ls -A build/$1/Support`
346
+ tar zcvf dist/Python-$(PYTHON_VER ) -$1-support.test-$(BUILD_NUMBER ) .tar.gz -X patch/Python/test.exclude -C build/$1/Support `ls -A build/$1/Support`
351
347
# Build a distributable tarball
352
- tar zcvf $$@ -X patch/Python/exclude.embedded -C build/$1/Support `ls -A build/$1/Support`
353
- endif
348
+ tar zcvf $$@ -X patch/Python/release.exclude -C build/$1/Support `ls -A build/$1/Support`
354
349
355
350
# Build OpenSSL
356
351
OpenSSL-$1: $$(OPENSSL_FRAMEWORK-$1 )
@@ -412,42 +407,81 @@ build/$1/xz/lib/liblzma.a: $$(foreach target,$$(TARGETS-$1),$$(XZ_DIR-$$(target)
412
407
mkdir -p build/$1
413
408
xcrun lipo -create -o $$@ $$^
414
409
410
+ # macOS builds a single Python target; thus it needs to be
411
+ # configured in the `build` macro, not the `build-target` macro.
412
+ ifeq ($1,macOS)
413
+ # Some targets that are needed for consistency between macOS and other builds,
414
+ # but are no-ops on macOS.
415
+ build/$1/$$(pyconfig.h-$1 ) :
416
+
417
+ # Unpack Python
418
+ $$(PYTHON_DIR-$1 ) /Makefile : downloads/Python-$(PYTHON_VERSION ) .tgz
419
+ # Unpack target Python
420
+ mkdir -p $$(PYTHON_DIR-$1 )
421
+ tar zxf downloads/Python-$(PYTHON_VERSION ) .tgz --strip-components 1 -C $$(PYTHON_DIR-$1 )
422
+ # Apply target Python patches
423
+ cd $$(PYTHON_DIR-$1 ) && patch -p1 < $(PROJECT_DIR ) /patch/Python/Python.patch
424
+ # A locally hosted Python requires a full Setup.local configuration
425
+ # because there's no PYTHON_HOST_PLATFORM to cause Setup.local to be
426
+ # generated
427
+ cat $(PROJECT_DIR ) /patch/Python/Setup.embedded $(PROJECT_DIR ) /patch/Python/Setup.macOS-x86_64 > $$(PYTHON_DIR-$1 ) /Modules/Setup.local
428
+ # Configure target Python
429
+ cd $$(PYTHON_DIR-$1 ) && MACOSX_DEPLOYMENT_TARGET=$$(MACOSX_DEPLOYMENT_TARGET ) ./configure \
430
+ --prefix=$(PROJECT_DIR ) /$$(PYTHON_DIR-$1 ) /dist \
431
+ --without-doc-strings --enable-ipv6 --without-ensurepip \
432
+ $$(PYTHON_CONFIGURE-$1 )
433
+
434
+ # Build Python
435
+ $$(PYTHON_DIR-$1 ) /dist/lib/libpython$(PYTHON_VER ) .a : build/$1/Support/OpenSSL build/$1/Support/BZip2 build/$1/Support/XZ $$(PYTHON_DIR-$1 ) /Makefile
436
+ # Build target Python
437
+ cd $$(PYTHON_DIR-$1 ) && PATH=" $( PROJECT_DIR) /$( PYTHON_DIR-$1 ) /dist/bin:$( PATH) " make all install
438
+
439
+ else
440
+ # The Python targets are the same as they are for every other library
441
+ PYTHON_TARGETS-$1 =$$(TARGETS-$1 )
442
+
443
+ endif
444
+
415
445
$1: Python-$1
416
446
417
447
Python-$1: dist/Python-$(PYTHON_VER ) -$1-support.$(BUILD_NUMBER ) .tar.gz
418
448
419
449
# Build Python
420
- $$(PYTHON_FRAMEWORK-$1 ) : build/$1/libpython$(PYTHON_VER ) .a $$(foreach target,$$(TARGETS -$1 ) ,build/$1/$$(pyconfig.h-$$(target ) ) )
450
+ $$(PYTHON_FRAMEWORK-$1 ) : build/$1/libpython$(PYTHON_VER ) .a $$(foreach target,$$(PYTHON_TARGETS -$1 ) ,build/$1/$$(pyconfig.h-$$(target ) ) )
421
451
mkdir -p $$(PYTHON_RESOURCES-$1 ) /include/python$(PYTHON_VER )
422
452
423
453
# Copy the headers. The headers are the same for every platform, except for pyconfig.h
424
454
# We ship a master pyconfig.h for iOS, tvOS and watchOS that delegates to architecture
425
455
# specific versions; on macOS, we can use the original version as-is.
426
- cp -f -r $$(PYTHON_DIR-$$(firstword $$(TARGETS-$1 ) ) ) /dist/include/python$(PYTHON_VER ) $$(PYTHON_FRAMEWORK-$1 ) /Headers
456
+ cp -f -r $$(PYTHON_DIR-$$(firstword $$(PYTHON_TARGETS-$1 ) ) ) /dist/include/python$(PYTHON_VER ) $$(PYTHON_FRAMEWORK-$1 ) /Headers
457
+ ifneq ($1,macOS)
427
458
cp -f $$(filter %.h,$$^) $$(PYTHON_FRAMEWORK-$1)/Headers
428
- ifeq ($1,macOS)
429
- mv $$(PYTHON_FRAMEWORK-$1)/Headers/pyconfig-x86_64.h $$(PYTHON_FRAMEWORK-$1)/Headers/pyconfig.h
430
- else
431
459
cp -f $(PROJECT_DIR)/patch/Python/pyconfig-$1.h $$(PYTHON_FRAMEWORK-$1)/Headers/pyconfig.h
432
460
endif
433
461
# Copy Python.h and pyconfig.h into the resources include directory
434
462
cp -f -r $$(PYTHON_FRAMEWORK-$1 ) /Headers/pyconfig*.h $$(PYTHON_RESOURCES-$1 ) /include/python$(PYTHON_VER )
435
463
cp -f -r $$(PYTHON_FRAMEWORK-$1 ) /Headers/Python.h $$(PYTHON_RESOURCES-$1 ) /include/python$(PYTHON_VER )
436
464
437
465
# Copy the standard library from the simulator build
438
- cp -f -r $$(PYTHON_DIR-$$(firstword $$(TARGETS -$1 ) ) ) /dist/lib $$(PYTHON_RESOURCES-$1 )
466
+ cp -f -r $$(PYTHON_DIR-$$(firstword $$(PYTHON_TARGETS -$1 ) ) ) /dist/lib $$(PYTHON_RESOURCES-$1 )
439
467
440
468
# Copy fat library
441
469
cp -f $$(filter % .a,$$^ ) $$(PYTHON_FRAMEWORK-$1 ) /libPython.a
442
470
443
471
444
472
# Build libpython fat library
445
- build/$1/libpython$(PYTHON_VER ) .a: $$(foreach target,$$(TARGETS -$1 ) ,$$(PYTHON_DIR-$$(target ) ) /dist/lib/libpython$(PYTHON_VER ) .a)
473
+ build/$1/libpython$(PYTHON_VER ) .a: $$(foreach target,$$(PYTHON_TARGETS -$1 ) ,$$(PYTHON_DIR-$$(target ) ) /dist/lib/libpython$(PYTHON_VER ) .a)
446
474
# Create a fat binary for the libPython library
447
475
mkdir -p build/$1
448
476
xcrun lipo -create -output $$@ $$^
449
477
450
478
vars-$1: $$(foreach target,$$(TARGETS-$1 ) ,vars-$$(target ) )
479
+ @echo "OPENSSL_FRAMEWORK-$1: $$(OPENSSL_FRAMEWORK-$1 ) "
480
+ @echo "BZIP2_FRAMEWORK-$1: $$(BZIP2_FRAMEWORK-$1 ) "
481
+ @echo "XZ_FRAMEWORK-$1: $$(XZ_FRAMEWORK-$1 ) "
482
+ @echo "PYTHON_FRAMEWORK-$1: $$(PYTHON_FRAMEWORK-$1 ) "
483
+ @echo "PYTHON_RESOURCES-$1: $$(PYTHON_RESOURCES-$1 ) "
484
+ @echo "PYTHON_TARGETS-$1: $$(PYTHON_TARGETS-$1 ) "
451
485
452
486
endef
453
487
0 commit comments