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 ) m.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 ) m.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
@@ -215,7 +212,7 @@ endif
215
212
ifeq ($2,macOS)
216
213
cd $$(OPENSSL_DIR-$1) && \
217
214
CC="$$(CC-$1)" MACOSX_DEPLOYMENT_TARGET=$$(MACOSX_DEPLOYMENT_TARGET) \
218
- ./Configure darwin64-x86_64 -cc no-tests --prefix=$(PROJECT_DIR)/build/$2/openssl --openssldir=$(PROJECT_DIR)/build/$2/openssl
215
+ ./Configure darwin64-$$(ARCH-$1) -cc no-tests --prefix=$(PROJECT_DIR)/build/$2/openssl --openssldir=$(PROJECT_DIR)/build/$2/openssl
219
216
else
220
217
cd $$(OPENSSL_DIR-$1) && \
221
218
CC="$$(CC-$1)" \
@@ -264,38 +261,33 @@ $$(XZ_DIR-$1)/Makefile: downloads/xz-$(XZ_VERSION).tgz
264
261
$$(XZ_DIR-$1 ) /src/liblzma/.libs/liblzma.a: $$(XZ_DIR-$1 ) /Makefile
265
262
cd $$(XZ_DIR-$1 ) && make && make install
266
263
264
+ # macOS builds are compiled as a single build. As a result, the macOS Python
265
+ # build is configured in the `build` macro, rather than the `build-target` macro.
266
+ ifneq ($2,macOS)
267
+ PYTHON_DIR-$1 =build/$2/Python-$(PYTHON_VERSION ) -$1
268
+ pyconfig.h-$1 =pyconfig-$$(ARCH-$1 ) .h
269
+ PYTHON_HOST-$1 =$(PYTHON_HOST )
270
+
267
271
# Unpack Python
268
272
$$(PYTHON_DIR-$1 ) /Makefile : downloads/Python-$(PYTHON_VERSION ) .tgz $$(PYTHON_HOST-$1 )
269
273
# Unpack target Python
270
274
mkdir -p $$(PYTHON_DIR-$1 )
271
275
tar zxf downloads/Python-$(PYTHON_VERSION ) .tgz --strip-components 1 -C $$(PYTHON_DIR-$1 )
272
276
# Apply target Python patches
273
277
cd $$(PYTHON_DIR-$1 ) && patch -p1 < $(PROJECT_DIR ) /patch/Python/Python.patch
274
- # Configure target Python
275
- ifeq ($2,macOS)
276
- # A locally hosted Python requires a full Setup.local configuration
277
- # because there's no PYTHON_HOST_PLATFORM to cause Setup.local to be
278
- # generated
279
- cat $(PROJECT_DIR)/patch/Python/Setup.embedded $(PROJECT_DIR)/patch/Python/Setup.macOS-x86_64 > $$(PYTHON_DIR-$1)/Modules/Setup.local
280
- # Make a fully embedded macOS build
281
- cd $$(PYTHON_DIR-$1) && MACOSX_DEPLOYMENT_TARGET=$$(MACOSX_DEPLOYMENT_TARGET) ./configure \
282
- --prefix=$(PROJECT_DIR)/$$(PYTHON_DIR-$1)/dist \
283
- --without-doc-strings --enable-ipv6 --without-ensurepip \
284
- $$(PYTHON_CONFIGURE-$2)
285
- else
286
278
# Copy in the embedded and platform/arch configuration
287
279
cp -f $(PROJECT_DIR ) /patch/Python/Setup.embedded $$(PYTHON_DIR-$1 ) /Modules/Setup.embedded
288
280
if [ -e " $( PROJECT_DIR) /patch/Python/Setup.$2 -$$ (ARCH-$1 )" ]; then \
289
281
cp -f $(PROJECT_DIR ) /patch/Python/Setup.$2 -$$(ARCH-$1 ) $$(PYTHON_DIR-$1 ) /Modules/Setup.$2 -$$(ARCH-$1 ) ; fi
282
+ # Configure target Python
290
283
cd $$(PYTHON_DIR-$1 ) && PATH=$(PROJECT_DIR ) /$(PYTHON_DIR-macOS ) /dist/bin:$(PATH ) ./configure \
291
284
CC=" $$ (CC-$1 )" LD=" $$ (CC-$1 )" \
292
285
--host=$$(MACHINE_DETAILED-$1 ) -apple-$(shell echo $2 | tr '[:upper:]' '[:lower:]') \
293
- --build=x86_64-apple-darwin$(shell uname -r) \
286
+ --build=x86_64-apple-darwin \
294
287
--prefix=$(PROJECT_DIR ) /$$(PYTHON_DIR-$1 ) /dist \
295
288
--without-doc-strings --enable-ipv6 --without-ensurepip \
296
289
ac_cv_file__dev_ptmx=no ac_cv_file__dev_ptc=no \
297
290
$$(PYTHON_CONFIGURE-$2 )
298
- endif
299
291
300
292
# Build Python
301
293
$$(PYTHON_DIR-$1 ) /dist/lib/libpython$(PYTHON_VER ) m.a : build/$2/Support/OpenSSL build/$2/Support/BZip2 build/$2/Support/XZ $$(PYTHON_DIR-$1 ) /Makefile
@@ -305,13 +297,21 @@ $$(PYTHON_DIR-$1)/dist/lib/libpython$(PYTHON_VER)m.a: build/$2/Support/OpenSSL b
305
297
build/$2/$$(pyconfig.h-$1 ) : $$(PYTHON_DIR-$1 ) /dist/include/python$(PYTHON_VER ) m/pyconfig.h
306
298
cp -f $$^ $$@
307
299
300
+ endif
301
+
308
302
# Dump vars (for test)
309
303
vars-$1:
310
304
@echo "ARCH-$1: $$(ARCH-$1 ) "
311
305
@echo "MACHINE_DETAILED-$1: $$(MACHINE_DETAILED-$1 ) "
312
306
@echo "SDK-$1: $$(SDK-$1 ) "
313
307
@echo "SDK_ROOT-$1: $$(SDK_ROOT-$1 ) "
314
308
@echo "CC-$1: $$(CC-$1 ) "
309
+ @echo "OPENSSL_DIR-$1: $$(OPENSSL_DIR-$1 ) "
310
+ @echo "BZIP2_DIR-$1: $$(BZIP2_DIR-$1 ) "
311
+ @echo "XZ_DIR-$1: $$(XZ_DIR-$1 ) "
312
+ @echo "PYTHON_DIR-$1: $$(PYTHON_DIR-$1 ) "
313
+ @echo "pyconfig.h-$1: $$(pyconfig.h-$1 ) "
314
+
315
315
endef
316
316
317
317
#
@@ -340,16 +340,11 @@ dist/Python-$(PYTHON_VER)-$1-support.$(BUILD_NUMBER).tar.gz: $$(BZIP2_FRAMEWORK-
340
340
echo "BZip2: $(BZIP2_VERSION ) " >> build/$1/Support/VERSIONS
341
341
echo "OpenSSL: $(OPENSSL_VERSION ) " >> build/$1/Support/VERSIONS
342
342
echo "XZ: $(XZ_VERSION ) " >> build/$1/Support/VERSIONS
343
- ifeq ($1,macOS)
344
- cp -r build/$1/Python-$(PYTHON_VERSION)-macosx.x86_64/dist build/$1/python
345
- mv build/$1/Support/VERSIONS build/$1/python/VERSIONS
346
- tar zcvf $$@ -X patch/Python/exclude.macOS -C build/$1/python `ls -A build/$1/python`
347
- else
343
+
348
344
# Build a "full" tarball with all content for test purposes
349
- 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`
345
+ 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`
350
346
# Build a distributable tarball
351
- tar zcvf $$@ -X patch/Python/exclude.embedded -C build/$1/Support `ls -A build/$1/Support`
352
- endif
347
+ tar zcvf $$@ -X patch/Python/release.exclude -C build/$1/Support `ls -A build/$1/Support`
353
348
354
349
# Build OpenSSL
355
350
OpenSSL-$1: $$(OPENSSL_FRAMEWORK-$1 )
@@ -411,42 +406,81 @@ build/$1/xz/lib/liblzma.a: $$(foreach target,$$(TARGETS-$1),$$(XZ_DIR-$$(target)
411
406
mkdir -p build/$1
412
407
xcrun lipo -create -o $$@ $$^
413
408
409
+ # macOS builds a single Python target; thus it needs to be
410
+ # configured in the `build` macro, not the `build-target` macro.
411
+ ifeq ($1,macOS)
412
+ # Some targets that are needed for consistency between macOS and other builds,
413
+ # but are no-ops on macOS.
414
+ build/$1/$$(pyconfig.h-$1 ) :
415
+
416
+ # Unpack Python
417
+ $$(PYTHON_DIR-$1 ) /Makefile : downloads/Python-$(PYTHON_VERSION ) .tgz
418
+ # Unpack target Python
419
+ mkdir -p $$(PYTHON_DIR-$1 )
420
+ tar zxf downloads/Python-$(PYTHON_VERSION ) .tgz --strip-components 1 -C $$(PYTHON_DIR-$1 )
421
+ # Apply target Python patches
422
+ cd $$(PYTHON_DIR-$1 ) && patch -p1 < $(PROJECT_DIR ) /patch/Python/Python.patch
423
+ # A locally hosted Python requires a full Setup.local configuration
424
+ # because there's no PYTHON_HOST_PLATFORM to cause Setup.local to be
425
+ # generated
426
+ cat $(PROJECT_DIR ) /patch/Python/Setup.embedded $(PROJECT_DIR ) /patch/Python/Setup.macOS-x86_64 > $$(PYTHON_DIR-$1 ) /Modules/Setup.local
427
+ # Configure target Python
428
+ cd $$(PYTHON_DIR-$1 ) && MACOSX_DEPLOYMENT_TARGET=$$(MACOSX_DEPLOYMENT_TARGET ) ./configure \
429
+ --prefix=$(PROJECT_DIR ) /$$(PYTHON_DIR-$1 ) /dist \
430
+ --without-doc-strings --enable-ipv6 --without-ensurepip \
431
+ $$(PYTHON_CONFIGURE-$1 )
432
+
433
+ # Build Python
434
+ $$(PYTHON_DIR-$1 ) /dist/lib/libpython$(PYTHON_VER ) m.a : build/$1/Support/OpenSSL build/$1/Support/BZip2 build/$1/Support/XZ $$(PYTHON_DIR-$1 ) /Makefile
435
+ # Build target Python
436
+ cd $$(PYTHON_DIR-$1 ) && PATH=" $( PROJECT_DIR) /$( PYTHON_DIR-$1 ) /dist/bin:$( PATH) " make all install
437
+
438
+ else
439
+ # The Python targets are the same as they are for every other library
440
+ PYTHON_TARGETS-$1 =$$(TARGETS-$1 )
441
+
442
+ endif
443
+
414
444
$1: Python-$1
415
445
416
446
Python-$1: dist/Python-$(PYTHON_VER ) -$1-support.$(BUILD_NUMBER ) .tar.gz
417
447
418
448
# Build Python
419
- $$(PYTHON_FRAMEWORK-$1 ) : build/$1/libpython$(PYTHON_VER ) m.a $$(foreach target,$$(TARGETS -$1 ) ,build/$1/$$(pyconfig.h-$$(target ) ) )
449
+ $$(PYTHON_FRAMEWORK-$1 ) : build/$1/libpython$(PYTHON_VER ) m.a $$(foreach target,$$(PYTHON_TARGETS -$1 ) ,build/$1/$$(pyconfig.h-$$(target ) ) )
420
450
mkdir -p $$(PYTHON_RESOURCES-$1 ) /include/python$(PYTHON_VER ) m
421
451
422
452
# Copy the headers. The headers are the same for every platform, except for pyconfig.h
423
453
# We ship a master pyconfig.h for iOS, tvOS and watchOS that delegates to architecture
424
454
# specific versions; on macOS, we can use the original version as-is.
425
- cp -f -r $$(PYTHON_DIR-$$(firstword $$(TARGETS-$1 ) ) ) /dist/include/python$(PYTHON_VER ) m $$(PYTHON_FRAMEWORK-$1 ) /Headers
455
+ cp -f -r $$(PYTHON_DIR-$$(firstword $$(PYTHON_TARGETS-$1 ) ) ) /dist/include/python$(PYTHON_VER ) m $$(PYTHON_FRAMEWORK-$1 ) /Headers
456
+ ifneq ($1,macOS)
426
457
cp -f $$(filter %.h,$$^) $$(PYTHON_FRAMEWORK-$1)/Headers
427
- ifeq ($1,macOS)
428
- mv $$(PYTHON_FRAMEWORK-$1)/Headers/pyconfig-x86_64.h $$(PYTHON_FRAMEWORK-$1)/Headers/pyconfig.h
429
- else
430
458
cp -f $(PROJECT_DIR)/patch/Python/pyconfig-$1.h $$(PYTHON_FRAMEWORK-$1)/Headers/pyconfig.h
431
459
endif
432
460
# Copy Python.h and pyconfig.h into the resources include directory
433
461
cp -f -r $$(PYTHON_FRAMEWORK-$1 ) /Headers/pyconfig*.h $$(PYTHON_RESOURCES-$1 ) /include/python$(PYTHON_VER ) m
434
462
cp -f -r $$(PYTHON_FRAMEWORK-$1 ) /Headers/Python.h $$(PYTHON_RESOURCES-$1 ) /include/python$(PYTHON_VER ) m
435
463
436
464
# Copy the standard library from the simulator build
437
- cp -f -r $$(PYTHON_DIR-$$(firstword $$(TARGETS -$1 ) ) ) /dist/lib $$(PYTHON_RESOURCES-$1 )
465
+ cp -f -r $$(PYTHON_DIR-$$(firstword $$(PYTHON_TARGETS -$1 ) ) ) /dist/lib $$(PYTHON_RESOURCES-$1 )
438
466
439
467
# Copy fat library
440
468
cp -f $$(filter % .a,$$^ ) $$(PYTHON_FRAMEWORK-$1 ) /libPython.a
441
469
442
470
443
471
# Build libpython fat library
444
- build/$1/libpython$(PYTHON_VER ) m.a: $$(foreach target,$$(TARGETS -$1 ) ,$$(PYTHON_DIR-$$(target ) ) /dist/lib/libpython$(PYTHON_VER ) m.a)
472
+ build/$1/libpython$(PYTHON_VER ) m.a: $$(foreach target,$$(PYTHON_TARGETS -$1 ) ,$$(PYTHON_DIR-$$(target ) ) /dist/lib/libpython$(PYTHON_VER ) m.a)
445
473
# Create a fat binary for the libPython library
446
474
mkdir -p build/$1
447
475
xcrun lipo -create -output $$@ $$^
448
476
449
477
vars-$1: $$(foreach target,$$(TARGETS-$1 ) ,vars-$$(target ) )
478
+ @echo "OPENSSL_FRAMEWORK-$1: $$(OPENSSL_FRAMEWORK-$1 ) "
479
+ @echo "BZIP2_FRAMEWORK-$1: $$(BZIP2_FRAMEWORK-$1 ) "
480
+ @echo "XZ_FRAMEWORK-$1: $$(XZ_FRAMEWORK-$1 ) "
481
+ @echo "PYTHON_FRAMEWORK-$1: $$(PYTHON_FRAMEWORK-$1 ) "
482
+ @echo "PYTHON_RESOURCES-$1: $$(PYTHON_RESOURCES-$1 ) "
483
+ @echo "PYTHON_TARGETS-$1: $$(PYTHON_TARGETS-$1 ) "
450
484
451
485
endef
452
486
0 commit comments