@@ -47,6 +47,9 @@ CFLAGS-watchOS= -mwatchos-version-min=2.0
47
47
CFLAGS-watchos.armv7k = -fembed-bitcode
48
48
PYTHON_CONFIGURE-watchOS=ac_cv_func_sigaltstack =no
49
49
50
+ # override machine for arm64
51
+ MACHINE-arm64 = aarch64
52
+
50
53
all : $(foreach os,$(OS ) ,all-$(os ) )
51
54
52
55
# Clean all builds
@@ -93,7 +96,7 @@ PYTHON_DIR-host= build/Python-$(PYTHON_VERSION)-host
93
96
Python-host : $(PYTHON_DIR-host ) /dist/bin/python$(PYTHON_VER )
94
97
95
98
# Unpack host Python
96
- $(PYTHON_DIR-host ) /configure : downloads/Python-$(PYTHON_VERSION ) .tgz
99
+ $(PYTHON_DIR-host ) /Makefile : downloads/Python-$(PYTHON_VERSION ) .tgz
97
100
# Unpack host Python
98
101
mkdir -p $(PYTHON_DIR-host )
99
102
tar zxf downloads/Python-$(PYTHON_VERSION ) .tgz --strip-components 1 -C $(PYTHON_DIR-host )
@@ -113,6 +116,11 @@ $(PYTHON_DIR-host)/dist/bin/python$(PYTHON_VER): $(PYTHON_DIR-host)/Makefile
113
116
# - $2 - OS
114
117
define build-target
115
118
ARCH-$1= $$(subst .,,$$(suffix $1) )
119
+ ifdef MACHINE-$$(ARCH-$1)
120
+ MACHINE-$1 = $$(MACHINE-$$(ARCH-$1 ) )
121
+ else
122
+ MACHINE-$1 = $$(ARCH-$1 )
123
+ endif
116
124
SDK-$1= $$(basename $1)
117
125
118
126
SDK_ROOT-$1= $$(shell xcrun --sdk $$(SDK-$1 ) --show-sdk-path)
@@ -121,6 +129,7 @@ CC-$1= xcrun --sdk $$(SDK-$1) clang\
121
129
122
130
OPENSSL_DIR-$1= build/$2/openssl-$(OPENSSL_VERSION ) -$1
123
131
PYTHON_DIR-$1= build/$2/Python-$(PYTHON_VERSION ) -$1
132
+ pyconfig.h-$1= pyconfig-$$(ARCH-$1 ) .h
124
133
125
134
# Unpack OpenSSL
126
135
$$(OPENSSL_DIR-$1 ) /Makefile: downloads/openssl-$(OPENSSL_VERSION ) .tgz
@@ -167,7 +176,7 @@ endif
167
176
# Configure target Python
168
177
cd $$(PYTHON_DIR-$1 ) && PATH=$(PROJECT_DIR ) /$(PYTHON_DIR-host ) /dist/bin:$(PATH ) ./configure \
169
178
CC="$$(CC-$1 ) " LD="$$(CC-$1 ) " \
170
- --host=$$(ARCH -$1 ) -apple-ios --build=x86_64-apple-darwin$(shell uname -r) \
179
+ --host=$$(MACHINE -$1 ) -apple-ios --build=x86_64-apple-darwin$(shell uname -r) \
171
180
--prefix=$(PROJECT_DIR ) /$$(PYTHON_DIR-$1 ) /dist \
172
181
--without-pymalloc --without-doc-strings --disable-ipv6 --without-ensurepip \
173
182
ac_cv_file__dev_ptmx=no ac_cv_file__dev_ptc=no \
@@ -178,49 +187,63 @@ $$(PYTHON_DIR-$1)/dist/lib/libpython$(PYTHON_VER).a: $$(PYTHON_DIR-$1)/Makefile
178
187
# Build target Python
179
188
cd $$(PYTHON_DIR-$1 ) && PATH=$(PROJECT_DIR ) /$(PYTHON_DIR-host ) /dist/bin:$(PATH ) make all install
180
189
190
+ build/$2/$$(pyconfig.h-$1 ) : $$(PYTHON_DIR-$1 ) /dist/include/python$(PYTHON_VER ) /pyconfig.h
191
+ cp $$^ $$@
192
+
181
193
# Dump vars (for test)
182
194
vars-$1:
183
195
@echo "ARCH-$1: $$(ARCH-$1 ) "
196
+ @echo "MACHINE-$1: $$(MACHINE-$1 ) "
184
197
@echo "SDK-$1: $$(SDK-$1 ) "
185
198
@echo "SDK_ROOT-$1: $$(SDK_ROOT-$1 ) "
186
199
@echo "CC-$1: $$(CC-$1 ) "
187
200
endef
188
201
202
+ #
203
+ # Install target pyconfig.h
204
+ # Parameters:
205
+ # - $1 - target
206
+ # - $2 - framework directory
207
+ define install-target-pyconfig
208
+ endef
209
+
189
210
#
190
211
# Build for specified OS (from $(OS))
191
212
# Parameters:
192
213
# - $1 - OS
193
214
define build
194
215
$$(foreach target,$$(TARGETS-$1 ) ,$$(eval $$(call build-target,$$(target ) ,$1) ) )
195
216
217
+ OPENSSL_FRAMEWORK-$1= build/$1/OpenSSL.framework
218
+ PYTHON_FRAMEWORK-$1= build/$1/Python.framework
219
+ PYTHON_RESOURCES-$1= $$(PYTHON_FRAMEWORK-$1 ) /Versions/$(PYTHON_VER ) /Resources
220
+
196
221
all-$1: Python-$(PYTHON_VERSION ) -$1-support.b$(BUILD_NUMBER ) .tar.gz
197
222
198
223
clean-$1:
199
224
rm -rf build/$1
200
225
201
- Python-$(PYTHON_VERSION ) -$1-support.b$(BUILD_NUMBER ) .tar.gz: build/$1/OpenSSL.framework build/$1/Python.framework
202
- tar zcvf $$@ -C build/$1 Python.framework OpenSSL.framework
226
+ Python-$(PYTHON_VERSION ) -$1-support.b$(BUILD_NUMBER ) .tar.gz: $$( OPENSSL_FRAMEWORK-$1 ) $$( PYTHON_FRAMEWORK-$1 )
227
+ tar zcvf $$@ -C build/$1 $$( notdir $$^ )
203
228
204
- OpenSSL.framework-$1: build/$1/OpenSSL.framework
229
+ OpenSSL.framework-$1: $$( OPENSSL_FRAMEWORK-$1 )
205
230
206
231
# Build OpenSSL.framework
207
- build/$1/OpenSSL.framework : build/$1/libssl.a build/$1/libcrypto.a
232
+ $$( OPENSSL_FRAMEWORK-$1 ) : build/$1/libssl.a build/$1/libcrypto.a
208
233
# Create framework directory structure
209
- mkdir -p build/$1/OpenSSL.framework/Versions/$(OPENSSL_VERSION )
210
- ln -fs $(OPENSSL_VERSION ) build/$1/OpenSSL.framework/Versions/Current
234
+ mkdir -p $$(OPENSSL_FRAMEWORK-$1 ) /Versions/$(OPENSSL_VERSION )
211
235
212
236
# Copy the headers (use the version from the simulator because reasons)
213
- cp -r $$(OPENSSL_DIR-$$(firstword $$(TARGETS-$1 ) ) ) /include build/$1/OpenSSL.framework/Versions/Current/Headers
214
-
215
- # Link the current Headers to the top level
216
- ln -fs Versions/Current/Headers build/$1/OpenSSL.framework
237
+ cp -r $$(OPENSSL_DIR-$$(firstword $$(TARGETS-$1 ) ) ) /include $$(OPENSSL_FRAMEWORK-$1 ) /Versions/$(OPENSSL_VERSION ) /Headers
217
238
218
239
# Create the fat library
219
240
xcrun libtool -no_warning_for_no_symbols -static \
220
- -o build/$1/OpenSSL.framework/ Versions/Current /OpenSSL $$^
241
+ -o $$( OPENSSL_FRAMEWORK-$1 ) / Versions/$( OPENSSL_VERSION ) /OpenSSL $$^
221
242
222
- # Link the fat Library to the top level
223
- ln -fs Versions/Current/OpenSSL build/$1/OpenSSL.framework
243
+ # Create symlinks
244
+ ln -fs $(OPENSSL_VERSION ) $$(OPENSSL_FRAMEWORK-$1 ) /Versions/Current
245
+ ln -fs Versions/Current/Headers $$(OPENSSL_FRAMEWORK-$1 )
246
+ ln -fs Versions/Current/OpenSSL $$(OPENSSL_FRAMEWORK-$1 )
224
247
225
248
build/$1/libssl.a: $$(foreach target,$$(TARGETS-$1 ) ,$$(OPENSSL_DIR-$$(target ) ) /libssl.a)
226
249
mkdir -p build/$1
@@ -230,73 +253,47 @@ build/$1/libcrypto.a: $$(foreach target,$$(TARGETS-$1),$$(OPENSSL_DIR-$$(target)
230
253
mkdir -p build/$1
231
254
xcrun lipo -create -output $$@ $$^
232
255
233
- Python.framework-$1: build/$1/Python.framework
256
+ Python.framework-$1: $$( PYTHON_FRAMEWORK-$1 )
234
257
235
258
# Build Python.framework
236
- build/$1/Python.framework: build/$1/libpython$(PYTHON_VER ) .a
259
+ $$(PYTHON_FRAMEWORK-$1 ) : build/$1/libpython$(PYTHON_VER ) .a $$(foreach target,$$(TARGETS-$1 ) ,build/$1/$$(pyconfig.h-$$(target ) ) )
260
+ mkdir -p $$(PYTHON_RESOURCES-$1 ) /include/python$(PYTHON_VER )
237
261
238
- # Build libpython fat library
239
- build/$1/libpython$(PYTHON_VER ) .a: $$(foreach target,$$(TARGETS-$1 ) ,$$(PYTHON_DIR-$$(target ) ) /dist/lib/libpython$(PYTHON_VER ) .a)
240
- mkdir -p build/$1
241
- xcrun lipo -create -output $$@ $$^
242
-
243
- endef
244
-
245
- $(foreach os,$(OS),$(eval $(call build,$(os))))
246
-
247
- _framework :
248
- # Create the framework directory and set it as the current version
249
- mkdir -p $(FRAMEWORK_DIR ) /Versions/$(PYTHON_VERSION ) /
250
- cd $(FRAMEWORK_DIR ) /Versions && ln -fs $(PYTHON_VERSION ) Current
251
-
252
- # Copy the headers. The headers are the same for every platform, except for pyconfig.h;
253
- # use the x86_64 simulator build because reasons.
254
- cp -r build/ios-simulator-x86_64/include/python$(PYTHON_VERSION) $(FRAMEWORK_DIR)/Versions/$(PYTHON_VERSION)/Headers
255
-
256
- # The only headers that change between versions is pyconfig.h; copy each supported version...
257
- cp build/ios-simulator-i386/include/python$(PYTHON_VERSION)/pyconfig.h $(FRAMEWORK_DIR)/Versions/$(PYTHON_VERSION)/Headers/pyconfig-i386.h
258
- cp build/ios-simulator-x86_64/include/python$(PYTHON_VERSION)/pyconfig.h $(FRAMEWORK_DIR)/Versions/$(PYTHON_VERSION)/Headers/pyconfig-x86_64.h
259
- # ARMv7 and ARMv7S headers are the same; don't copy this one.
260
- # cp build/ios-armv7s/include/python$(PYTHON_VERSION)/pyconfig.h $(FRAMEWORK_DIR)/Versions/$(PYTHON_VERSION)/Headers/pyconfig-armv7s.h
261
- cp build/ios-armv7/include/python$(PYTHON_VERSION)/pyconfig.h $(FRAMEWORK_DIR)/Versions/$(PYTHON_VERSION)/Headers/pyconfig-armv7.h
262
- cp build/ios-arm64/include/python$(PYTHON_VERSION)/pyconfig.h $(FRAMEWORK_DIR)/Versions/$(PYTHON_VERSION)/Headers/pyconfig-arm64.h
263
- # ... and then copy in a master pyconfig.h to unify them all.
264
- cp include/pyconfig.h $(FRAMEWORK_DIR)/Versions/$(PYTHON_VERSION)/Headers/pyconfig.h
265
-
266
- # Link the current Headers to the top level
267
- cd $(FRAMEWORK_DIR) && ln -fs Versions/Current/Headers
268
-
269
- # Copy the standard library from the simulator build. Again, the
270
- # pure Python standard library is the same on every platform;
271
- # use the simulator version because reasons.
272
- mkdir -p $(FRAMEWORK_DIR)/Versions/$(PYTHON_VERSION)/Resources
273
- cp -r build/ios-simulator-x86_64/lib $(FRAMEWORK_DIR)/Versions/$(PYTHON_VERSION)/Resources
262
+ # Copy the headers. The headers are the same for every platform, except for pyconfig.h
263
+ cp -r $$(PYTHON_DIR-$$(firstword $$(TARGETS-$1 ) ) ) /dist/include/python$(PYTHON_VER ) $$(PYTHON_FRAMEWORK-$1 ) /Versions/$(PYTHON_VER ) /Headers
264
+ cp $$(filter % .h,$$^ ) $$(PYTHON_FRAMEWORK-$1 ) /Versions/$(PYTHON_VER ) /Headers
265
+ cp $$(PYTHON_DIR-$$(firstword $$(TARGETS-$1 ) ) ) /iOS/include/pyconfig.h $$(PYTHON_FRAMEWORK-$1 ) /Versions/$(PYTHON_VER ) /Headers
274
266
275
267
# Copy Python.h and pyconfig.h into the resources include directory
276
- mkdir -p $(FRAMEWORK_DIR)/Versions/$(PYTHON_VERSION)/Resources/include/python$(PYTHON_VERSION)
277
- cp -r $(FRAMEWORK_DIR)/Versions/$(PYTHON_VERSION)/Headers/pyconfig*.h $(FRAMEWORK_DIR)/Versions/$(PYTHON_VERSION)/Resources/include/python$(PYTHON_VERSION)
278
- cp -r $(FRAMEWORK_DIR)/Versions/$(PYTHON_VERSION)/Headers/Python.h $(FRAMEWORK_DIR)/Versions/$(PYTHON_VERSION)/Resources/include/python$(PYTHON_VERSION)
279
-
280
- # Remove the pieces of the resources directory that aren't needed:
281
- # libpython.a isn't needed in the lib directory
282
- rm -f $(FRAMEWORK_DIR)/Versions/$(PYTHON_VERSION)/Resources/lib/libpython$(PYTHON_VERSION).a
283
- # pkgconfig isn't needed on the device
284
- rm -rf $(FRAMEWORK_DIR)/Versions/$(PYTHON_VERSION)/Resources/lib/pkgconfig
268
+ cp -r $$(PYTHON_FRAMEWORK-$1 ) /Versions/$(PYTHON_VER ) /Headers/pyconfig*.h $$(PYTHON_RESOURCES-$1 ) /include/python$(PYTHON_VER )
269
+ cp -r $$(PYTHON_FRAMEWORK-$1 ) /Versions/$(PYTHON_VER ) /Headers/Python.h $$(PYTHON_RESOURCES-$1 ) /include/python$(PYTHON_VER )
285
270
271
+ # Copy the standard library from the simulator build
286
272
ifneq ($(TEST ) ,)
287
- # Do the pruning and compression.
288
- cd $(FRAMEWORK_DIR)/Versions/$(PYTHON_VERSION)/Resources/lib/python$(PYTHON_VERSION);
289
- rm -rf *test* lib* bsddb curses ensurepip hotshot idlelib tkinter turtledemo wsgiref \
290
- config-$(PYTHON_VERSION) ctypes/test distutils/tests site-packages sqlite3/test; \
291
- find . -name "*.pyc" -exec rm -rf {} \;
292
- zip -r ../python$(subst .,,$(PYTHON_VER)).zip *;
273
+ cp -r $$(PYTHON_DIR-$$(firstword $$(TARGETS-$1)))/dist/lib $$(PYTHON_RESOURCES-$1)
274
+ # Remove the pieces of the resources directory that aren't needed:
275
+ rm -f $$(PYTHON_RESOURCES-$1)/lib/libpython$(PYTHON_VER).a
276
+ rm -rf $$(PYTHON_RESOURCES-$1)/lib/pkgconfig
277
+ else
278
+ mkdir -p $$(PYTHON_RESOURCES-$1)/lib
279
+ cd $$(PYTHON_DIR-$$(firstword $$(TARGETS-$1)))/dist/lib/python$(PYTHON_VER) && \
280
+ zip -x@$(PROJECT_DIR)/python-lib-exclude.lst -r $(PROJECT_DIR)/$$(PYTHON_RESOURCES-$1)/lib/python$(subst .,,$(PYTHON_VER)) *
293
281
endif
294
282
295
- # Link the current Resources to the top level
296
- cd $(FRAMEWORK_DIR) && ln -fs Versions/Current/Resources
283
+ # Copy fat library
284
+ cp $$( filter % .a, $$^ ) $$( PYTHON_FRAMEWORK-$1 ) / Versions/$( PYTHON_VER ) /Python
297
285
286
+ # Create symlinks
287
+ ln -fs $(PYTHON_VER ) $$(PYTHON_FRAMEWORK-$1 ) /Versions/Current
288
+ ln -fs Versions/Current/Headers $$(PYTHON_FRAMEWORK-$1 )
289
+ ln -fs Versions/Current/Resources $$(PYTHON_FRAMEWORK-$1 )
290
+ ln -fs Versions/Current/Python $$(PYTHON_FRAMEWORK-$1 )
291
+
292
+ # Build libpython fat library
293
+ build/$1/libpython$(PYTHON_VER ) .a: $$(foreach target,$$(TARGETS-$1 ) ,$$(PYTHON_DIR-$$(target ) ) /dist/lib/libpython$(PYTHON_VER ) .a)
298
294
# Create a fat binary for the libPython library
299
- cp libpython.a $(FRAMEWORK_DIR)/Versions/$(PYTHON_VERSION)/Python
295
+ mkdir -p build/$1
296
+ xcrun lipo -create -output $$@ $$^
297
+ endef
300
298
301
- # Link the current Python library to the top level
302
- cd $(FRAMEWORK_DIR) && ln -fs Versions/Current/Python
299
+ $(foreach os,$(OS),$(eval $(call build,$(os))))
0 commit comments