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
17
17
# - XZ-iOS - build XZ for iOS
18
18
# - XZ-tvOS - build XZ for tvOS
19
19
# - XZ-watchOS - build XZ for watchOS
20
+ # - libFFI-iOS - build libFFI for iOS
21
+ # - libFFI-tvOS - build libFFI for tvOS
22
+ # - libFFI-watchOS - build libFFI for watchOS
20
23
# - Python-macOS - build Python for macOS
21
24
# - Python-iOS - build Python for iOS
22
25
# - Python-tvOS - build Python for tvOS
@@ -41,6 +44,8 @@ BZIP2_VERSION=1.0.8
41
44
42
45
XZ_VERSION =5.2.5
43
46
47
+ LIBFFI_VERSION =3.3
48
+
44
49
# Supported OS
45
50
OS =macOS iOS tvOS watchOS
46
51
82
87
distclean : clean
83
88
rm -rf downloads
84
89
85
- downloads : downloads/openssl-$(OPENSSL_VERSION ) .tgz downloads/bzip2-$(BZIP2_VERSION ) .tgz downloads/xz-$(XZ_VERSION ) .tgz downloads/Python-$(PYTHON_VERSION ) .tgz
90
+ downloads : downloads/openssl-$(OPENSSL_VERSION ) .tgz downloads/bzip2-$(BZIP2_VERSION ) .tgz downloads/xz-$(XZ_VERSION ) .tgz downloads/libffi- $( LIBFFI_VERSION ) .tgz downloads/ Python-$(PYTHON_VERSION ) .tgz
86
91
87
92
update-patch :
88
93
# Generate a diff from the clone of the python/cpython Github repository
@@ -99,8 +104,9 @@ update-patch:
99
104
# Clean the OpenSSL project
100
105
clean-OpenSSL :
101
106
rm -rf build/* /openssl-$(OPENSSL_VERSION ) -* \
107
+ build/* /openssl \
102
108
build/* /libssl.a build/* /libcrypto.a \
103
- build/* /OpenSSL
109
+ build/* /Support/ OpenSSL
104
110
105
111
# Download original OpenSSL source code archive.
106
112
downloads/openssl-$(OPENSSL_VERSION ) .tgz :
@@ -114,9 +120,10 @@ downloads/openssl-$(OPENSSL_VERSION).tgz:
114
120
# ##########################################################################
115
121
116
122
# Clean the bzip2 project
117
- clean-bzip2 :
123
+ clean-BZip2 :
118
124
rm -rf build/* /bzip2-$(BZIP2_VERSION ) -* \
119
- build/* /bzip2
125
+ build/* /bzip2 \
126
+ build/* /Support/BZip2
120
127
121
128
# Download original BZip2 source code archive.
122
129
downloads/bzip2-$(BZIP2_VERSION ) .tgz :
@@ -128,15 +135,30 @@ downloads/bzip2-$(BZIP2_VERSION).tgz:
128
135
# ##########################################################################
129
136
130
137
# Clean the XZ project
131
- clean-xz :
138
+ clean-XZ :
132
139
rm -rf build/* /xz-$(XZ_VERSION ) -* \
133
- build/* /xz
140
+ build/* /xz \
141
+ build/* /Support/XZ
134
142
135
143
# Download original XZ source code archive.
136
144
downloads/xz-$(XZ_VERSION ) .tgz :
137
145
mkdir -p downloads
138
146
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
139
147
148
+ # ##########################################################################
149
+ # LIBFFI
150
+ # ##########################################################################
151
+
152
+ # Clean the LibFFI project
153
+ clean-libFFI :
154
+ rm -rf build/* /libffi-$(LIBFFI_VERSION ) \
155
+ build/* /Support/libFFI
156
+
157
+ # Download original XZ source code archive.
158
+ downloads/libffi-$(LIBFFI_VERSION ) .tgz :
159
+ mkdir -p downloads
160
+ if [ ! -e downloads/libffi-$( LIBFFI_VERSION) .tgz ]; then curl --fail -L http://github.com/libffi/libffi/releases/download/v$( LIBFFI_VERSION) /libffi-$( LIBFFI_VERSION) .tar.gz -o downloads/libffi-$( LIBFFI_VERSION) .tgz; fi
161
+
140
162
# ##########################################################################
141
163
# Python
142
164
# ##########################################################################
@@ -147,7 +169,7 @@ clean-Python:
147
169
build/* /Python-$(PYTHON_VERSION ) -* \
148
170
build/* /libpython$(PYTHON_VER ) .a \
149
171
build/* /pyconfig-* .h \
150
- build/* /Python
172
+ build/* /Support/ Python
151
173
152
174
# Download original Python source code archive.
153
175
downloads/Python-$(PYTHON_VERSION ) .tgz :
@@ -186,6 +208,7 @@ LDFLAGS-$1=-arch $$(ARCH-$1) -isysroot=$$(SDK_ROOT-$1)
186
208
OPENSSL_DIR-$1=build/$2/openssl-$(OPENSSL_VERSION ) -$1
187
209
BZIP2_DIR-$1=build/$2/bzip2-$(BZIP2_VERSION ) -$1
188
210
XZ_DIR-$1=build/$2/xz-$(XZ_VERSION ) -$1
211
+ LIBFFI_DIR-$1=build/$2/libffi-$(LIBFFI_VERSION )
189
212
PYTHON_DIR-$1=build/$2/Python-$(PYTHON_VERSION ) -$1
190
213
pyconfig.h-$1=pyconfig-$$(ARCH-$1 ) .h
191
214
@@ -265,29 +288,52 @@ $$(XZ_DIR-$1)/Makefile: downloads/xz-$(XZ_VERSION).tgz
265
288
$$(XZ_DIR-$1 ) /src/liblzma/.libs/liblzma.a: $$(XZ_DIR-$1 ) /Makefile
266
289
cd $$(XZ_DIR-$1 ) && make && make install
267
290
291
+ # No need to build libFFI on macOS
292
+ ifneq ($2,macOS)
293
+
294
+ # libFFI has it's own internal build directories for each Apple platform
295
+ ifeq ($$(ARCH-$1 ) ,x86_64)
296
+ LIBFFI_BUILD_DIR-$1 =build_iphonesimulator-x86_64
297
+ else ifeq ($$(ARCH-$1),i386)
298
+ LIBFFI_BUILD_DIR-$1 =build_iphonesimulator-i386
299
+ else ifeq ($$(ARCH-$1),arm64)
300
+ LIBFFI_BUILD_DIR-$1 =build_iphoneos-arm64
301
+ else ifeq ($$(ARCH-$1),armv7)
302
+ LIBFFI_BUILD_DIR-$1 =build_iphoneos-armv7
303
+ else ifeq ($$(ARCH-$1),armv7k)
304
+ LIBFFI_BUILD_DIR-$1 =build_iphoneos-armv7
305
+ else
306
+ # This is a canary - it should never occur, so if you see it,
307
+ # you've got a problem.
308
+ LIBFFI_BUILD_DIR-$1 =build_other
309
+ endif
310
+
311
+ # Build LibFFI
312
+ $$(LIBFFI_DIR-$1 ) /libffi.$1.a : $$(LIBFFI_DIR-$1 ) /darwin_common
313
+ cd $$(LIBFFI_DIR-$1 ) /$$(LIBFFI_BUILD_DIR-$1 ) && make
314
+
315
+ # Copy in the lib to a non-BUILD_DIR dependent location;
316
+ # include the target in the final filename for disambiguation
317
+ cp $$(LIBFFI_DIR-$1)/$$(LIBFFI_BUILD_DIR-$1)/.libs/libffi.a $$(LIBFFI_DIR-$1)/libffi.$1.a
318
+
319
+ endif
320
+
268
321
# Unpack Python
269
322
$$(PYTHON_DIR-$1 ) /Makefile: downloads/Python-$(PYTHON_VERSION ) .tgz $$(PYTHON_HOST-$1 )
270
323
# Unpack target Python
271
324
mkdir -p $$(PYTHON_DIR-$1 )
272
325
tar zxf downloads/Python-$(PYTHON_VERSION ) .tgz --strip-components 1 -C $$(PYTHON_DIR-$1 )
273
326
# Apply target Python patches
274
327
cd $$(PYTHON_DIR-$1 ) && patch -p1 < $(PROJECT_DIR ) /patch/Python/Python.patch
328
+ # Copy in the embedded module configuration
329
+ cat $(PROJECT_DIR ) /patch/Python/Setup.embedded $(PROJECT_DIR ) /patch/Python/Setup.$2 > $$(PYTHON_DIR-$1 ) /Modules/Setup.local
275
330
# Configure target Python
276
331
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
332
cd $$(PYTHON_DIR-$1) && MACOSX_DEPLOYMENT_TARGET=$$(MACOSX_DEPLOYMENT_TARGET) ./configure \
283
333
--prefix=$(PROJECT_DIR)/$$(PYTHON_DIR-$1)/dist \
284
334
--without-doc-strings --enable-ipv6 --without-ensurepip \
285
335
$$(PYTHON_CONFIGURE-$2)
286
336
else
287
- # Copy in the embedded and platform/arch configuration
288
- cp -f $(PROJECT_DIR)/patch/Python/Setup.embedded $$(PYTHON_DIR-$1)/Modules/Setup.embedded
289
- if [ -e "$(PROJECT_DIR)/patch/Python/Setup.$2-$$(ARCH-$1)" ]; then \
290
- cp -f $(PROJECT_DIR)/patch/Python/Setup.$2-$$(ARCH-$1) $$(PYTHON_DIR-$1)/Modules/Setup.$2-$$(ARCH-$1); fi
291
337
cd $$(PYTHON_DIR-$1) && PATH=$(PROJECT_DIR)/$(PYTHON_DIR-macOS)/dist/bin:$(PATH) ./configure \
292
338
CC="$$(CC-$1)" LD="$$(CC-$1)" \
293
339
--host=$$(MACHINE_DETAILED-$1)-apple-$(shell echo $2 | tr '[:upper:]' '[:lower:]') \
299
345
endif
300
346
301
347
# Build Python
302
- $$(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
348
+ $$(PYTHON_DIR-$1 ) /dist/lib/libpython$(PYTHON_VER ) .a: build/$2/Support/OpenSSL build/$2/Support/BZip2 build/$2/Support/XZ build/$2/Support/libFFI $$(PYTHON_DIR-$1 ) /Makefile
303
349
# Build target Python
304
350
cd $$(PYTHON_DIR-$1 ) && PATH="$(PROJECT_DIR ) /$(PYTHON_DIR-macOS ) /dist/bin:$(PATH ) " make all install
305
351
@@ -313,6 +359,14 @@ vars-$1:
313
359
@echo "SDK-$1: $$(SDK-$1 ) "
314
360
@echo "SDK_ROOT-$1: $$(SDK_ROOT-$1 ) "
315
361
@echo "CC-$1: $$(CC-$1 ) "
362
+ @echo "LIBFFI_BUILD_DIR-$1: $$(LIBFFI_BUILD_DIR-$1 ) "
363
+ @echo "OPENSSL_DIR-$1: $$(OPENSSL_DIR-$1 ) "
364
+ @echo "BZIP2_DIR-$1: $$(BZIP2_DIR-$1 ) "
365
+ @echo "XZ_DIR-$1: $$(XZ_DIR-$1 ) "
366
+ @echo "LIBFFI_DIR-$1: $$(LIBFFI_DIR-$1 ) "
367
+ @echo "PYTHON_DIR-$1: $$(PYTHON_DIR-$1 ) "
368
+ @echo "pyconfig.h-$1: $$(pyconfig.h-$1 ) "
369
+
316
370
endef
317
371
318
372
#
@@ -325,6 +379,7 @@ $$(foreach target,$$(TARGETS-$1),$$(eval $$(call build-target,$$(target),$1)))
325
379
OPENSSL_FRAMEWORK-$1=build/$1/Support/OpenSSL
326
380
BZIP2_FRAMEWORK-$1=build/$1/Support/BZip2
327
381
XZ_FRAMEWORK-$1=build/$1/Support/XZ
382
+ LIBFFI_FRAMEWORK-$1=build/$1/Support/libFFI
328
383
PYTHON_FRAMEWORK-$1=build/$1/Support/Python
329
384
PYTHON_RESOURCES-$1=$$(PYTHON_FRAMEWORK-$1 ) /Resources
330
385
@@ -333,11 +388,16 @@ $1: dist/Python-$(PYTHON_VER)-$1-support.$(BUILD_NUMBER).tar.gz
333
388
clean-$1:
334
389
rm -rf build/$1
335
390
336
- dist/Python-$(PYTHON_VER ) -$1-support.$(BUILD_NUMBER ) .tar.gz: $$(BZIP2_FRAMEWORK-$1 ) $$(XZ_FRAMEWORK-$1 ) $$(OPENSSL_FRAMEWORK-$1 ) $$(PYTHON_FRAMEWORK-$1 )
391
+ dist/Python-$(PYTHON_VER ) -$1-support.$(BUILD_NUMBER ) .tar.gz: $$(BZIP2_FRAMEWORK-$1 ) $$(XZ_FRAMEWORK-$1 ) $$(OPENSSL_FRAMEWORK-$1 ) $$(LIBFFI_FRAMEWORK-$1 ) $$( PYTHON_FRAMEWORK-$1 )
337
392
mkdir -p dist
338
393
echo "Python version: $(PYTHON_VERSION ) " > build/$1/Support/VERSIONS
339
394
echo "Build: $(BUILD_NUMBER ) " >> build/$1/Support/VERSIONS
340
395
echo "---------------------" >> build/$1/Support/VERSIONS
396
+ ifeq ($1,macOS)
397
+ echo "libFFI: macOS native" >> build/$1/Support/VERSIONS
398
+ else
399
+ echo "libFFI: $(LIBFFI_VERSION)" >> build/$1/Support/VERSIONS
400
+ endif
341
401
echo "BZip2: $(BZIP2_VERSION ) " >> build/$1/Support/VERSIONS
342
402
echo "OpenSSL: $(OPENSSL_VERSION ) " >> build/$1/Support/VERSIONS
343
403
echo "XZ: $(XZ_VERSION ) " >> build/$1/Support/VERSIONS
@@ -412,6 +472,45 @@ build/$1/xz/lib/liblzma.a: $$(foreach target,$$(TARGETS-$1),$$(XZ_DIR-$$(target)
412
472
mkdir -p build/$1
413
473
xcrun lipo -create -o $$@ $$^
414
474
475
+ # Build libFFI
476
+ libFFI-$1: $$(LIBFFI_FRAMEWORK-$1 )
477
+
478
+ ifeq ($1,macOS)
479
+ $$(LIBFFI_FRAMEWORK-$1 ) : # noop
480
+ else
481
+
482
+ LIBFFI_DIR-$1 =build/$1/libffi-$(LIBFFI_VERSION )
483
+
484
+ # Unpack LibFFI and generate source & headers
485
+ $$(LIBFFI_DIR-$1 ) /darwin_common : downloads/libffi-$(LIBFFI_VERSION ) .tgz
486
+ # Unpack sources
487
+ mkdir -p $$(LIBFFI_DIR-$1 )
488
+ tar zxf downloads/libffi-$(LIBFFI_VERSION ) .tgz --strip-components 1 -C $$(LIBFFI_DIR-$1 )
489
+ # Apply libffi patches. Apple builds of libffi use a utility script; that
490
+ # script doesn't work with Python3 using the out-of-the-box version in
491
+ # libffi 3.3. This patch matches what is in trunk as of Feb 2021 (and will
492
+ # presumably be in libffi 3.4 or whatever comes next)
493
+ cd $$(LIBFFI_DIR-$1 ) && patch -p1 < $(PROJECT_DIR ) /patch/libffi/libffi.patch
494
+ # Configure the build
495
+ cd $$(LIBFFI_DIR-$1 ) && python generate-darwin-source-and-headers.py --only-ios
496
+
497
+ $$(LIBFFI_FRAMEWORK-$1 ) : $$(LIBFFI_DIR-$1 ) /libffi.a
498
+ # Create framework directory structure
499
+ mkdir -p $$(LIBFFI_FRAMEWORK-$1 )
500
+
501
+ # Copy the headers.
502
+ cp -f -r $$(LIBFFI_DIR-$1)/darwin_common/include $$(LIBFFI_FRAMEWORK-$1)/Headers
503
+ cp -f -r $$(LIBFFI_DIR-$1)/darwin_ios/include/* $$(LIBFFI_FRAMEWORK-$1)/Headers
504
+
505
+ # Create the fat library
506
+ xcrun libtool -no_warning_for_no_symbols -static \
507
+ -o $$(LIBFFI_FRAMEWORK-$1)/libFFI.a $$^
508
+
509
+ $$(LIBFFI_DIR-$1 ) /libffi.a : $$(foreach target,$$(TARGETS-$1 ) ,$$(LIBFFI_DIR-$1 ) /libffi.$$(target ) .a)
510
+ xcrun lipo -create -o $$@ $$^
511
+
512
+ endif
513
+
415
514
$1: Python-$1
416
515
417
516
Python-$1: dist/Python-$(PYTHON_VER ) -$1-support.$(BUILD_NUMBER ) .tar.gz
@@ -448,6 +547,13 @@ build/$1/libpython$(PYTHON_VER).a: $$(foreach target,$$(TARGETS-$1),$$(PYTHON_DI
448
547
xcrun lipo -create -output $$@ $$^
449
548
450
549
vars-$1: $$(foreach target,$$(TARGETS-$1 ) ,vars-$$(target ) )
550
+ @echo "OPENSSL_FRAMEWORK-$1: $$(OPENSSL_FRAMEWORK-$1 ) "
551
+ @echo "BZIP2_FRAMEWORK-$1: $$(BZIP2_FRAMEWORK-$1 ) "
552
+ @echo "XZ_FRAMEWORK-$1: $$(XZ_FRAMEWORK-$1 ) "
553
+ @echo "LIBFFI_FRAMEWORK-$1: $$(LIBFFI_FRAMEWORK-$1 ) "
554
+ @echo "PYTHON_FRAMEWORK-$1: $$(PYTHON_FRAMEWORK-$1 ) "
555
+ @echo "LIBFFI_DIR-$1: $$(LIBFFI_DIR-$1 ) "
556
+ @echo "PYTHON_RESOURCES-$1: $$(PYTHON_RESOURCES-$1 ) "
451
557
452
558
endef
453
559
0 commit comments