Skip to content
This repository was archived by the owner on Mar 30, 2019. It is now read-only.

Commit bde5911

Browse files
committed
Python.framework can now be built.
1 parent a4809cc commit bde5911

File tree

2 files changed

+86
-73
lines changed

2 files changed

+86
-73
lines changed

Makefile

Lines changed: 70 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ CFLAGS-watchOS= -mwatchos-version-min=2.0
4747
CFLAGS-watchos.armv7k= -fembed-bitcode
4848
PYTHON_CONFIGURE-watchOS=ac_cv_func_sigaltstack=no
4949

50+
# override machine for arm64
51+
MACHINE-arm64= aarch64
52+
5053
all: $(foreach os,$(OS),all-$(os))
5154

5255
# Clean all builds
@@ -93,7 +96,7 @@ PYTHON_DIR-host= build/Python-$(PYTHON_VERSION)-host
9396
Python-host: $(PYTHON_DIR-host)/dist/bin/python$(PYTHON_VER)
9497

9598
# Unpack host Python
96-
$(PYTHON_DIR-host)/configure: downloads/Python-$(PYTHON_VERSION).tgz
99+
$(PYTHON_DIR-host)/Makefile: downloads/Python-$(PYTHON_VERSION).tgz
97100
# Unpack host Python
98101
mkdir -p $(PYTHON_DIR-host)
99102
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
113116
# - $2 - OS
114117
define build-target
115118
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
116124
SDK-$1= $$(basename $1)
117125

118126
SDK_ROOT-$1= $$(shell xcrun --sdk $$(SDK-$1) --show-sdk-path)
@@ -121,6 +129,7 @@ CC-$1= xcrun --sdk $$(SDK-$1) clang\
121129

122130
OPENSSL_DIR-$1= build/$2/openssl-$(OPENSSL_VERSION)-$1
123131
PYTHON_DIR-$1= build/$2/Python-$(PYTHON_VERSION)-$1
132+
pyconfig.h-$1= pyconfig-$$(ARCH-$1).h
124133

125134
# Unpack OpenSSL
126135
$$(OPENSSL_DIR-$1)/Makefile: downloads/openssl-$(OPENSSL_VERSION).tgz
@@ -167,7 +176,7 @@ endif
167176
# Configure target Python
168177
cd $$(PYTHON_DIR-$1) && PATH=$(PROJECT_DIR)/$(PYTHON_DIR-host)/dist/bin:$(PATH) ./configure \
169178
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) \
171180
--prefix=$(PROJECT_DIR)/$$(PYTHON_DIR-$1)/dist \
172181
--without-pymalloc --without-doc-strings --disable-ipv6 --without-ensurepip \
173182
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
178187
# Build target Python
179188
cd $$(PYTHON_DIR-$1) && PATH=$(PROJECT_DIR)/$(PYTHON_DIR-host)/dist/bin:$(PATH) make all install
180189

190+
build/$2/$$(pyconfig.h-$1): $$(PYTHON_DIR-$1)/dist/include/python$(PYTHON_VER)/pyconfig.h
191+
cp $$^ $$@
192+
181193
# Dump vars (for test)
182194
vars-$1:
183195
@echo "ARCH-$1: $$(ARCH-$1)"
196+
@echo "MACHINE-$1: $$(MACHINE-$1)"
184197
@echo "SDK-$1: $$(SDK-$1)"
185198
@echo "SDK_ROOT-$1: $$(SDK_ROOT-$1)"
186199
@echo "CC-$1: $$(CC-$1)"
187200
endef
188201

202+
#
203+
# Install target pyconfig.h
204+
# Parameters:
205+
# - $1 - target
206+
# - $2 - framework directory
207+
define install-target-pyconfig
208+
endef
209+
189210
#
190211
# Build for specified OS (from $(OS))
191212
# Parameters:
192213
# - $1 - OS
193214
define build
194215
$$(foreach target,$$(TARGETS-$1),$$(eval $$(call build-target,$$(target),$1)))
195216

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+
196221
all-$1: Python-$(PYTHON_VERSION)-$1-support.b$(BUILD_NUMBER).tar.gz
197222

198223
clean-$1:
199224
rm -rf build/$1
200225

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 $$^)
203228

204-
OpenSSL.framework-$1: build/$1/OpenSSL.framework
229+
OpenSSL.framework-$1: $$(OPENSSL_FRAMEWORK-$1)
205230

206231
# 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
208233
# 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)
211235

212236
# 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
217238

218239
# Create the fat library
219240
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 $$^
221242

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)
224247

225248
build/$1/libssl.a: $$(foreach target,$$(TARGETS-$1),$$(OPENSSL_DIR-$$(target))/libssl.a)
226249
mkdir -p build/$1
@@ -230,73 +253,47 @@ build/$1/libcrypto.a: $$(foreach target,$$(TARGETS-$1),$$(OPENSSL_DIR-$$(target)
230253
mkdir -p build/$1
231254
xcrun lipo -create -output $$@ $$^
232255

233-
Python.framework-$1: build/$1/Python.framework
256+
Python.framework-$1: $$(PYTHON_FRAMEWORK-$1)
234257

235258
# 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)
237261

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
274266

275267
# 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)
285270

271+
# Copy the standard library from the simulator build
286272
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)) *
293281
endif
294282

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
297285

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)
298294
# 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
300298

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))))

python-lib-exclude.lst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
bsddb/*
2+
config-*/*
3+
ctypes/test/*
4+
curses/*
5+
distutils/tests
6+
ensurepip/*
7+
hotshot/*
8+
idlelib/*
9+
lib*/*
10+
site-packages/*
11+
sqlite3/test
12+
*test*/*
13+
tkinter/*
14+
turtledemo/*
15+
wsgiref/*
16+
*.pyc

0 commit comments

Comments
 (0)