Skip to content

Commit fdf391f

Browse files
committed
[3.9] pythongh-114099: Add configure and Makefile targets to support iOS compilation. (pythonGH-115390)
1 parent 0935df2 commit fdf391f

20 files changed

+851
-100
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
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

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,21 @@ $(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK): \
700700
$(LN) -fsn Versions/Current/$(PYTHONFRAMEWORK) $(PYTHONFRAMEWORKDIR)/$(PYTHONFRAMEWORK)
701701
$(LN) -fsn Versions/Current/Resources $(PYTHONFRAMEWORKDIR)/Resources
702702

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

1728-
frameworkinstallframework: frameworkinstallstructure install frameworkinstallmaclib
1743+
frameworkinstallframework: @FRAMEWORKINSTALLFIRST@ install frameworkinstallmaclib
17291744

1730-
frameworkinstallstructure: $(LDLIBRARY)
1745+
# macOS uses a versioned frameworks structure that includes a full install
1746+
.PHONY: frameworkinstallversionedstructure
1747+
frameworkinstallversionedstructure: $(LDLIBRARY)
17311748
@if test "$(PYTHONFRAMEWORKDIR)" = no-framework; then \
17321749
echo Not configured with --enable-framework; \
17331750
exit 1; \
@@ -1748,6 +1765,27 @@ frameworkinstallstructure: $(LDLIBRARY)
17481765
$(LN) -fsn Versions/Current/Resources $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Resources
17491766
$(INSTALL_SHARED) $(LDLIBRARY) $(DESTDIR)$(PYTHONFRAMEWORKPREFIX)/$(LDLIBRARY)
17501767

1768+
# iOS/tvOS/watchOS uses a non-versioned framework with Info.plist in the
1769+
# framework root, no .lproj data, and only stub compilation assistance binaries
1770+
.PHONY: frameworkinstallunversionedstructure
1771+
frameworkinstallunversionedstructure: $(LDLIBRARY)
1772+
@if test "$(PYTHONFRAMEWORKDIR)" = no-framework; then \
1773+
echo Not configured with --enable-framework; \
1774+
exit 1; \
1775+
else true; \
1776+
fi
1777+
if test -d $(DESTDIR)$(PYTHONFRAMEWORKPREFIX)/include; then \
1778+
echo "Clearing stale header symlink directory"; \
1779+
rm -rf $(DESTDIR)$(PYTHONFRAMEWORKPREFIX)/include; \
1780+
fi
1781+
$(INSTALL) -d -m $(DIRMODE) $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)
1782+
sed 's/%VERSION%/'"`$(RUNSHARED) $(PYTHON_FOR_BUILD) -c 'import platform; print(platform.python_version())'`"'/g' < $(RESSRCDIR)/Info.plist > $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Info.plist
1783+
$(INSTALL_SHARED) $(LDLIBRARY) $(DESTDIR)$(PYTHONFRAMEWORKPREFIX)/$(LDLIBRARY)
1784+
$(INSTALL) -d -m $(DIRMODE) $(DESTDIR)$(BINDIR)
1785+
for file in $(srcdir)/$(RESSRCDIR)/bin/* ; do \
1786+
$(INSTALL) -m $(EXEMODE) $$file $(DESTDIR)$(BINDIR); \
1787+
done
1788+
17511789
# This installs Mac/Lib into the framework
17521790
# Install a number of symlinks to keep software that expects a normal unix
17531791
# install (which includes python-config) happy.
@@ -1782,6 +1820,19 @@ frameworkaltinstallunixtools:
17821820
frameworkinstallextras:
17831821
cd Mac && $(MAKE) installextras DESTDIR="$(DESTDIR)"
17841822

1823+
# On iOS, bin/lib can't live inside the framework; include needs to be called
1824+
# "Headers", but *must* be in the framework, and *not* include the `python3.X`
1825+
# subdirectory. The install has put these folders in the same folder as
1826+
# Python.framework; Move the headers to their final framework-compatible home.
1827+
.PHONY: frameworkinstallmobileheaders
1828+
frameworkinstallmobileheaders:
1829+
if test -d $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Headers; then \
1830+
echo "Removing old framework headers"; \
1831+
rm -rf $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Headers; \
1832+
fi
1833+
mv "$(DESTDIR)$(PYTHONFRAMEWORKPREFIX)/include/python$(VERSION)" "$(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Headers"
1834+
$(LN) -fs "../$(PYTHONFRAMEWORKDIR)/Headers" "$(DESTDIR)$(PYTHONFRAMEWORKPREFIX)/include/python$(VERSION)"
1835+
17851836
# Build the toplevel Makefile
17861837
Makefile.pre: $(srcdir)/Makefile.pre.in config.status
17871838
CONFIG_FILES=Makefile.pre CONFIG_HEADERS= $(SHELL) config.status
@@ -1980,7 +2031,7 @@ Python/thread.o: @THREADHEADERS@ $(srcdir)/Python/condvar.h
19802031
.PHONY: all build_all sharedmods check-clean-src oldsharedmods test quicktest
19812032
.PHONY: install altinstall oldsharedinstall bininstall altbininstall
19822033
.PHONY: maninstall libinstall inclinstall libainstall sharedinstall
1983-
.PHONY: frameworkinstall frameworkinstallframework frameworkinstallstructure
2034+
.PHONY: frameworkinstall frameworkinstallframework
19842035
.PHONY: frameworkinstallmaclib frameworkinstallapps frameworkinstallunixtools
19852036
.PHONY: frameworkaltinstallunixtools recheck clean clobber distclean
19862037
.PHONY: smelly funny patchcheck touch altmaninstall commoninstall
Lines changed: 2 additions & 0 deletions
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

Lines changed: 4 additions & 1 deletion
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)