Skip to content

Commit 8f43e44

Browse files
committed
[3.10] pythongh-114099: Add configure and Makefile targets to support iOS compilation. (pythonGH-115390)
1 parent 913d4b8 commit 8f43e44

20 files changed

+843
-112
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ Lib/test/data/*
6161
!Lib/test/data/README
6262
/Makefile
6363
/Makefile.pre
64+
iOS/Resources/Info.plist
6465
Mac/Makefile
6566
Mac/PythonLauncher/Info.plist
6667
Mac/PythonLauncher/Makefile

Makefile.pre.in

+54-3
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,21 @@ $(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK): \
697697
$(LN) -fsn Versions/Current/$(PYTHONFRAMEWORK) $(PYTHONFRAMEWORKDIR)/$(PYTHONFRAMEWORK)
698698
$(LN) -fsn Versions/Current/Resources $(PYTHONFRAMEWORKDIR)/Resources
699699

700+
# This rule is for iOS, which requires an annoyingly just slighly different
701+
# format for frameworks to macOS. It *doesn't* use a versioned framework, and
702+
# the Info.plist must be in the root of the framework.
703+
$(PYTHONFRAMEWORKDIR)/$(PYTHONFRAMEWORK): \
704+
$(LIBRARY) \
705+
$(RESSRCDIR)/Info.plist
706+
$(INSTALL) -d -m $(DIRMODE) $(PYTHONFRAMEWORKDIR)
707+
$(CC) -o $(LDLIBRARY) $(PY_CORE_LDFLAGS) -dynamiclib \
708+
-all_load $(LIBRARY) \
709+
-install_name $(PYTHONFRAMEWORKINSTALLNAMEPREFIX)/$(PYTHONFRAMEWORK) \
710+
-compatibility_version $(VERSION) \
711+
-current_version $(VERSION) \
712+
-framework CoreFoundation $(LIBS);
713+
$(INSTALL_DATA) $(RESSRCDIR)/Info.plist $(PYTHONFRAMEWORKDIR)/Info.plist
714+
700715
# This rule builds the Cygwin Python DLL and import library if configured
701716
# for a shared core library; otherwise, this rule is a noop.
702717
$(DLLLIBRARY) libpython$(LDVERSION).dll.a: $(LIBRARY_OBJS)
@@ -1778,9 +1793,11 @@ frameworkinstall: install
17781793
# automatically set prefix to the location deep down in the framework, so we
17791794
# only have to cater for the structural bits of the framework.
17801795

1781-
frameworkinstallframework: frameworkinstallstructure install frameworkinstallmaclib
1796+
frameworkinstallframework: @FRAMEWORKINSTALLFIRST@ install frameworkinstallmaclib
17821797

1783-
frameworkinstallstructure: $(LDLIBRARY)
1798+
# macOS uses a versioned frameworks structure that includes a full install
1799+
.PHONY: frameworkinstallversionedstructure
1800+
frameworkinstallversionedstructure: $(LDLIBRARY)
17841801
@if test "$(PYTHONFRAMEWORKDIR)" = no-framework; then \
17851802
echo Not configured with --enable-framework; \
17861803
exit 1; \
@@ -1801,6 +1818,27 @@ frameworkinstallstructure: $(LDLIBRARY)
18011818
$(LN) -fsn Versions/Current/Resources $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Resources
18021819
$(INSTALL_SHARED) $(LDLIBRARY) $(DESTDIR)$(PYTHONFRAMEWORKPREFIX)/$(LDLIBRARY)
18031820

1821+
# iOS/tvOS/watchOS uses a non-versioned framework with Info.plist in the
1822+
# framework root, no .lproj data, and only stub compilation assistance binaries
1823+
.PHONY: frameworkinstallunversionedstructure
1824+
frameworkinstallunversionedstructure: $(LDLIBRARY)
1825+
@if test "$(PYTHONFRAMEWORKDIR)" = no-framework; then \
1826+
echo Not configured with --enable-framework; \
1827+
exit 1; \
1828+
else true; \
1829+
fi
1830+
if test -d $(DESTDIR)$(PYTHONFRAMEWORKPREFIX)/include; then \
1831+
echo "Clearing stale header symlink directory"; \
1832+
rm -rf $(DESTDIR)$(PYTHONFRAMEWORKPREFIX)/include; \
1833+
fi
1834+
$(INSTALL) -d -m $(DIRMODE) $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)
1835+
sed 's/%VERSION%/'"`$(RUNSHARED) $(PYTHON_FOR_BUILD) -c 'import platform; print(platform.python_version())'`"'/g' < $(RESSRCDIR)/Info.plist > $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Info.plist
1836+
$(INSTALL_SHARED) $(LDLIBRARY) $(DESTDIR)$(PYTHONFRAMEWORKPREFIX)/$(LDLIBRARY)
1837+
$(INSTALL) -d -m $(DIRMODE) $(DESTDIR)$(BINDIR)
1838+
for file in $(srcdir)/$(RESSRCDIR)/bin/* ; do \
1839+
$(INSTALL) -m $(EXEMODE) $$file $(DESTDIR)$(BINDIR); \
1840+
done
1841+
18041842
# This installs Mac/Lib into the framework
18051843
# Install a number of symlinks to keep software that expects a normal unix
18061844
# install (which includes python-config) happy.
@@ -1835,6 +1873,19 @@ frameworkaltinstallunixtools:
18351873
frameworkinstallextras:
18361874
cd Mac && $(MAKE) installextras DESTDIR="$(DESTDIR)"
18371875

1876+
# On iOS, bin/lib can't live inside the framework; include needs to be called
1877+
# "Headers", but *must* be in the framework, and *not* include the `python3.X`
1878+
# subdirectory. The install has put these folders in the same folder as
1879+
# Python.framework; Move the headers to their final framework-compatible home.
1880+
.PHONY: frameworkinstallmobileheaders
1881+
frameworkinstallmobileheaders:
1882+
if test -d $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Headers; then \
1883+
echo "Removing old framework headers"; \
1884+
rm -rf $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Headers; \
1885+
fi
1886+
mv "$(DESTDIR)$(PYTHONFRAMEWORKPREFIX)/include/python$(VERSION)" "$(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Headers"
1887+
$(LN) -fs "../$(PYTHONFRAMEWORKDIR)/Headers" "$(DESTDIR)$(PYTHONFRAMEWORKPREFIX)/include/python$(VERSION)"
1888+
18381889
# Build the toplevel Makefile
18391890
Makefile.pre: $(srcdir)/Makefile.pre.in config.status
18401891
CONFIG_FILES=Makefile.pre CONFIG_HEADERS= $(SHELL) config.status
@@ -2035,7 +2086,7 @@ Python/thread.o: @THREADHEADERS@ $(srcdir)/Python/condvar.h
20352086
.PHONY: all build_all sharedmods check-clean-src oldsharedmods test quicktest
20362087
.PHONY: install altinstall oldsharedinstall bininstall altbininstall
20372088
.PHONY: maninstall libinstall inclinstall libainstall sharedinstall
2038-
.PHONY: frameworkinstall frameworkinstallframework frameworkinstallstructure
2089+
.PHONY: frameworkinstall frameworkinstallframework
20392090
.PHONY: frameworkinstallmaclib frameworkinstallapps frameworkinstallunixtools
20402091
.PHONY: frameworkaltinstallunixtools recheck clean clobber distclean
20412092
.PHONY: smelly funny patchcheck touch altmaninstall commoninstall
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Makefile targets were added to support compiling an iOS-compatible framework
2+
build.

config.sub

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
# shellcheck disable=SC2006,SC2268 # see below for rationale
66

7+
# Patched 2024-02-03 to include support for arm64_32 and iOS/tvOS/watchOS simulators
78
timestamp='2024-01-01'
89

910
# This file is free software; you can redistribute it and/or modify it
@@ -1127,7 +1128,7 @@ case $cpu-$vendor in
11271128
xscale-* | xscalee[bl]-*)
11281129
cpu=`echo "$cpu" | sed 's/^xscale/arm/'`
11291130
;;
1130-
arm64-* | aarch64le-*)
1131+
arm64-* | aarch64le-* | arm64_32-*)
11311132
cpu=aarch64
11321133
;;
11331134

@@ -1866,6 +1867,8 @@ case $kernel-$os-$obj in
18661867
;;
18671868
*-eabi*- | *-gnueabi*-)
18681869
;;
1870+
ios*-simulator- | tvos*-simulator- | watchos*-simulator- )
1871+
;;
18691872
none--*)
18701873
# None (no kernel, i.e. freestanding / bare metal),
18711874
# can be paired with an machine code file format

0 commit comments

Comments
 (0)