blob: 9a9e2ce82b773f737442eef11ce69cc18011e4a6 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001#
2# Copyright (C) 2006-2016 OpenWrt.org
3#
4# This is free software, licensed under the GNU General Public License v2.
5# See /LICENSE for more information.
6#
7
8include $(TOPDIR)/rules.mk
9
10# The file included below defines PYTHON3_VERSION
11include ../python3-version.mk
12
13PKG_NAME:=python3
14PKG_RELEASE:=2
15PKG_VERSION:=$(PYTHON3_VERSION).$(PYTHON3_VERSION_MICRO)
16
17PKG_SOURCE:=Python-$(PKG_VERSION).tar.xz
18PKG_SOURCE_URL:=https://www.python.org/ftp/python/$(PKG_VERSION)
19PKG_HASH:=18e1aa7e66ff3a58423d59ed22815a6954e53342122c45df20c96877c062b9b7
20
21PKG_MAINTAINER:=Jeffery To <jeffery.to@gmail.com>
22PKG_LICENSE:=Python-2.0.1 0BSD
23PKG_LICENSE_FILES:=LICENSE Doc/copyright.rst Doc/license.rst Modules/_ctypes/darwin/LICENSE Modules/_ctypes/libffi_osx/LICENSE Modules/expat/COPYING
24PKG_CPE_ID:=cpe:/a:python:python
25
26# This file provides the necsessary host build variables
27include ../python3-host.mk
28
29# For Py3Package
30PYTHON3_PKG_BUILD:=0
31include ../python3-package.mk
32
33PKG_FIXUP:=autoreconf
34PKG_BUILD_PARALLEL:=1
35HOST_BUILD_PARALLEL:=1
36# LTO is handled here individually, see --with-lto below
37# "no-lto" prevents CONFIG_USE_LTO to add additional and interfering flags
38PKG_BUILD_FLAGS:=no-lto
39
40PKG_BUILD_DIR:=$(BUILD_DIR)/Python-$(PKG_VERSION)
41HOST_BUILD_DIR:=$(BUILD_DIR_HOST)/Python-$(PKG_VERSION)
42
43PKG_BUILD_DEPENDS:=bluez python3/host python-build/host python-installer/host python-wheel/host
44HOST_BUILD_DEPENDS:=bzip2/host libffi/host readline/host
45
46include $(INCLUDE_DIR)/host-build.mk
47include $(INCLUDE_DIR)/package.mk
48
49define Package/python3/Default
50 SUBMENU:=Python
51 SECTION:=lang
52 CATEGORY:=Languages
53 TITLE:=Python $(PYTHON3_VERSION)
54 URL:=https://www.python.org/
55endef
56
57define Package/python3/Default/description
58Python is an interpreted, interactive, object-oriented programming
59language. It incorporates modules, exceptions, dynamic typing, very high
60level dynamic data types, and classes. It supports multiple programming
61paradigms beyond object-oriented programming, such as procedural and
62functional programming. Python combines remarkable power with very clear
63syntax. It has interfaces to many system calls and libraries, as well as
64to various window systems, and is extensible in C or C++. It is also
65usable as an extension language for applications that need a
66programmable interface. Finally, Python is portable: it runs on many
67Unix variants including Linux and macOS, and on Windows.
68endef
69
70define Package/libpython3
71$(call Package/python3/Default)
72 TITLE+= core library
73 DEPENDS:=+libpthread
74 ABI_VERSION:=$(PYTHON3_VERSION)
75endef
76
77define Package/libpython3/description
78$(call Package/python3/Default/description)
79
80This package contains only core Python library.
81endef
82
83define Package/python3-base
84$(call Package/python3/Default)
85 TITLE+= base interpreter
86 DEPENDS:=+libpython3
87endef
88
89define Package/python3-base/description
90$(call Package/python3/Default/description)
91
92This package contains only the interpreter and the bare minimum for the
93interpreter to start.
94endef
95
96define Package/python3-light
97$(call Package/python3/Default)
98 TITLE+= light installation
99 DEPENDS:=+python3-base +libbz2 +zlib
100endef
101
102define Package/python3-light/config
103 source "$(SOURCE)/Config-python3-light.in"
104endef
105
106define Package/python3-light/description
107$(call Package/python3/Default/description)
108
109This package installs the base interpreter package and contains the most
110commonly used parts of the standard library.
111endef
112
113PYTHON3_LIB_FILES_DEL:=
114PYTHON3_PACKAGES:=
115PYTHON3_SO_SUFFIX:=cpython-$(PYTHON3_VERSION_MAJOR)$(PYTHON3_VERSION_MINOR)-*.so
116PYTHON3_PACKAGES_DEPENDS:=
117define Py3BasePackage
118 PYTHON3_PACKAGES+=$(1)
119 ifeq ($(3),)
120 PYTHON3_PACKAGES_DEPENDS+=$(1)
121 endif
122 PYTHON3_LIB_FILES_DEL+=$(2)
123 ifeq ($(2),)
124 Py3Package/$(1)/filespec=
125 else
126 define Py3Package/$(1)/filespec
127 $(foreach lib_file,$(2),
128 +|$(lib_file)
129 )
130 endef
131 endif
132 Py3Package/$(1)/install?=:
133endef
134
135include ./files/python3-package-*.mk
136
137define Package/python3
138$(call Package/python3/Default)
139 TITLE+= programming language
140 DEPENDS:=+python3-light $(foreach package,$(PYTHON3_PACKAGES_DEPENDS),+$(package))
141endef
142
143define Package/python3/description
144$(call Package/python3/Default/description)
145
146This package installs almost all parts of the standard Python
147installation.
148endef
149
150# Set READELF here so that the exact same readelf program name can be
151# replaced in _sysconfigdata_*.py (in Build/Install)
152TARGET_CONFIGURE_OPTS+= \
153 READELF="$(TARGET_CROSS)readelf"
154
155EXTRA_LDFLAGS+= \
156 -L$(PKG_BUILD_DIR) \
157 -L$(STAGING_DIR)/usr/lib -L$(STAGING_DIR)/lib
158
159# Bypass configure tests for cross compilation
160CONFIGURE_VARS += \
161 ac_cv_buggy_getaddrinfo=no \
162 ac_cv_file__dev_ptc=no \
163 ac_cv_file__dev_ptmx=yes
164
165# Disable stdlib modules
166# Check for a better way in the future: https://github.com/python/cpython/issues/98558
167CONFIGURE_VARS += \
168 py_cv_module__tkinter=n/a \
169 py_cv_module_nis=n/a
170
171# Workaround for hardfloat mips
172# https://bugs.python.org/issue46265
173ifneq ($(findstring mips,$(CONFIG_ARCH)),)
174ifeq ($(CONFIG_HAS_FPU),y)
175CONFIGURE_VARS += \
176 ax_cv_check_cflags___fno_semantic_interposition=no
177endif
178endif
179
180MAKE_VARS += \
181 PYTHONSTRICTEXTENSIONBUILD=1
182
183CONFIGURE_ARGS += \
184 --enable-optimizations \
185 --enable-shared \
186 --disable-test-modules \
187 --with-build-python \
188 --with-system-ffi \
189 --without-cxx-main \
190 --without-ensurepip \
191 $(if $(CONFIG_IPV6),--enable-ipv6) \
192 $(if $(findstring mips,$(CONFIG_ARCH)),,--with-lto)
193
194define Build/Install
195 $(call Build/Install/Default,)
196
197 $(SED) 's|$(TARGET_AR)|ar|g;s|$(TARGET_CROSS)readelf|readelf|g;s|$(TARGET_CC)|gcc|g;s|$(TARGET_CXX)|g++|g' \
198 $(PKG_INSTALL_DIR)/usr/lib/python$(PYTHON3_VERSION)/_sysconfigdata_*.py \
199 $(PKG_INSTALL_DIR)/usr/lib/python$(PYTHON3_VERSION)/config-$(PYTHON3_VERSION)-*/Makefile
200endef
201
202define Build/InstallDev
203 $(INSTALL_DIR) $(1)/usr/include
204 $(CP) \
205 $(PKG_INSTALL_DIR)/usr/include/python$(PYTHON3_VERSION) \
206 $(1)/usr/include/
207
208 $(INSTALL_DIR) $(1)/usr/lib
209 $(CP) \
210 $(PKG_INSTALL_DIR)/usr/lib/python$(PYTHON3_VERSION) \
211 $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON3_VERSION).so* \
212 $(1)/usr/lib/
213
214 $(INSTALL_DIR) $(1)/usr/lib/python$(PYTHON3_VERSION)/openwrt
215 grep -E \
216 '^(_PYTHON_HOST_PLATFORM|ABIFLAGS|MACHDEP|MULTIARCH)=' \
217 $(PKG_INSTALL_DIR)/usr/lib/python$(PYTHON3_VERSION)/config-$(PYTHON3_VERSION)-*/Makefile > \
218 $(1)/usr/lib/python$(PYTHON3_VERSION)/openwrt/Makefile-vars
219
220 $(INSTALL_DIR) $(1)/usr/lib/pkgconfig
221 $(CP) \
222 $(PKG_INSTALL_DIR)/usr/lib/pkgconfig/python*.pc \
223 $(1)/usr/lib/pkgconfig
224
225 $(INSTALL_DIR) $(2)/bin
226 $(INSTALL_BIN) \
227 $(PKG_INSTALL_DIR)/usr/bin/python$(PYTHON3_VERSION)-config \
228 $(2)/bin/
229 $(SED) \
230 's|^prefix_real=.*$$$$|prefix_real="$(PYTHON3_DIR)"|' \
231 $(2)/bin/python$(PYTHON3_VERSION)-config
232endef
233
234PYTHON3_BASE_LIB_FILES:= \
235 /usr/lib/python$(PYTHON3_VERSION)/encodings \
236 /usr/lib/python$(PYTHON3_VERSION)/_collections_abc.py \
237 /usr/lib/python$(PYTHON3_VERSION)/_sitebuiltins.py \
238 /usr/lib/python$(PYTHON3_VERSION)/_sysconfigdata_*.py \
239 /usr/lib/python$(PYTHON3_VERSION)/_weakrefset.py \
240 /usr/lib/python$(PYTHON3_VERSION)/abc.py \
241 /usr/lib/python$(PYTHON3_VERSION)/codecs.py \
242 /usr/lib/python$(PYTHON3_VERSION)/genericpath.py \
243 /usr/lib/python$(PYTHON3_VERSION)/io.py \
244 /usr/lib/python$(PYTHON3_VERSION)/os.py \
245 /usr/lib/python$(PYTHON3_VERSION)/posixpath.py \
246 /usr/lib/python$(PYTHON3_VERSION)/site.py \
247 /usr/lib/python$(PYTHON3_VERSION)/sysconfig.py \
248 /usr/lib/python$(PYTHON3_VERSION)/stat.py
249
250PYTHON3_LIB_FILES_DEL+=$(PYTHON3_BASE_LIB_FILES)
251
252define Py3Package/python3-base/filespec
253+|/usr/bin/python$(PYTHON3_VERSION)
254$(foreach lib_file,$(PYTHON3_BASE_LIB_FILES),
255 +|$(lib_file)
256)
257endef
258
259define Py3Package/python3-light/filespec
260+|/usr/lib/python$(PYTHON3_VERSION)
261-|/usr/lib/python$(PYTHON3_VERSION)/distutils/cygwinccompiler.py
262-|/usr/lib/python$(PYTHON3_VERSION)/idlelib
263-|/usr/lib/python$(PYTHON3_VERSION)/tkinter
264-|/usr/lib/python$(PYTHON3_VERSION)/turtledemo
265-|/usr/lib/python$(PYTHON3_VERSION)/webbrowser.py
266-|/usr/lib/python$(PYTHON3_VERSION)/_osx_support.py
267$(foreach lib_file,$(filter /usr/lib/python$(PYTHON3_VERSION)/%,$(PYTHON3_LIB_FILES_DEL)),
268 -|$(lib_file)
269)
270endef
271
272define Package/libpython3/install
273 # Adding the lib-dynload folder (even just empty) suppresses 2 warnings when starting Python
274 $(INSTALL_DIR) $(1)/usr/lib/python$(PYTHON3_VERSION)/lib-dynload/
275 $(CP) $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON3_VERSION).so* $(1)/usr/lib/
276endef
277
278define Py3Package/python3-base/install
279 $(INSTALL_DIR) $(1)/usr/bin
280 $(LN) python$(PYTHON3_VERSION) $(1)/usr/bin/python3
281 $(LN) python$(PYTHON3_VERSION) $(1)/usr/bin/python
282endef
283
284Py3Package/python3-light/install:=:
285Package/python3/install:=:
286
287ifeq ($(HOST_OS),Linux)
288HOST_LDFLAGS += \
289 -Wl,--no-as-needed -lrt
290endif
291
292# Would be nice to be able to do this, but hosts are very fiddly
293# HOST_MAKE_VARS += \
294# PYTHONSTRICTEXTENSIONBUILD=1
295
296# Bypass configure test
297HOST_CONFIGURE_VARS += \
298 ac_cv_working_openssl_hashlib=yes
299
300ifeq ($(HOST_OS),Darwin)
301HOST_CONFIGURE_VARS += \
302 ac_cv_header_libintl_h=no
303HOST_MAKE_VARS += \
304 USE_PYTHON_CONFIG_PY=1
305endif
306
307HOST_CONFIGURE_ARGS += \
308 --enable-optimizations \
309 --disable-test-modules \
310 --with-ensurepip=upgrade \
311 --with-ssl-default-suites=openssl \
312 --with-system-expat \
313 --without-cxx-main
314
315define Host/Configure
316 $(SED) 's/^ENABLE_USER_SITE = None$$$$/ENABLE_USER_SITE = False/' $(HOST_BUILD_DIR)/Lib/site.py
317 $(call Host/Configure/Default)
318 ls $(HOST_BUILD_DIR)/Lib/ensurepip/_bundled/setuptools-$(PYTHON3_SETUPTOOLS_VERSION)-py3-none-any.whl
319 ls $(HOST_BUILD_DIR)/Lib/ensurepip/_bundled/pip-$(PYTHON3_PIP_VERSION)-py3-none-any.whl
320endef
321
322define Host/Install
323 $(if $(wildcard $(HOST_PYTHON3_PKG_DIR)/.setuptools_installed_$(PYTHON3_SETUPTOOLS_VERSION)-$(PYTHON3_SETUPTOOLS_PKG_RELEASE)),,
324 rm -rf \
325 $(HOST_PYTHON3_PKG_DIR)/pkg_resources \
326 $(HOST_PYTHON3_PKG_DIR)/setuptools \
327 $(HOST_PYTHON3_PKG_DIR)/setuptools-* \
328 $(HOST_PYTHON3_PKG_DIR)/.setuptools-patched* \
329 $(HOST_PYTHON3_PKG_DIR)/.setuptools_installed_*
330 )
331 $(if $(wildcard $(HOST_PYTHON3_PKG_DIR)/.pip_installed_$(PYTHON3_PIP_VERSION)-$(PYTHON3_PIP_PKG_RELEASE)),,
332 rm -rf \
333 $(HOST_PYTHON3_PKG_DIR)/pip \
334 $(HOST_PYTHON3_PKG_DIR)/pip-* \
335 $(HOST_PYTHON3_PKG_DIR)/.pip-patched* \
336 $(HOST_PYTHON3_PKG_DIR)/.pip_installed_*
337 )
338 $(call Host/Install/Default)
339 $(if $(wildcard $(HOST_PYTHON3_PKG_DIR)/.setuptools_installed_$(PYTHON3_SETUPTOOLS_VERSION)-$(PYTHON3_SETUPTOOLS_PKG_RELEASE)),,
340 $(call HostPatchDir,$(HOST_PYTHON3_PKG_DIR),./patches-host-setuptools,)
341 touch $(HOST_PYTHON3_PKG_DIR)/.setuptools_installed_$(PYTHON3_SETUPTOOLS_VERSION)-$(PYTHON3_SETUPTOOLS_PKG_RELEASE)
342 )
343 $(if $(wildcard $(HOST_PYTHON3_PKG_DIR)/.pip_installed_$(PYTHON3_PIP_VERSION)-$(PYTHON3_PIP_PKG_RELEASE)),,
344 $(call HostPatchDir,$(HOST_PYTHON3_PKG_DIR),./patches-host-pip,)
345 touch $(HOST_PYTHON3_PKG_DIR)/.pip_installed_$(PYTHON3_PIP_VERSION)-$(PYTHON3_PIP_PKG_RELEASE)
346 )
347endef
348
349$(eval $(call HostBuild))
350
351$(eval $(call BuildPackage,libpython3))
352$(eval $(call BuildPackage,python3))
353
354$(eval $(call Py3Package,python3-base))
355$(eval $(call Py3Package,python3-light))
356
357$(eval $(call BuildPackage,python3-base))
358$(eval $(call BuildPackage,python3-light))
359
360$(eval $(call BuildPackage,python3-base-src))
361$(eval $(call BuildPackage,python3-light-src))
362
363$(foreach package, $(PYTHON3_PACKAGES), \
364 $(eval $(call Py3Package,$(package))) \
365 $(eval $(call BuildPackage,$(package))) \
366 $(eval $(call BuildPackage,$(package)-src)) \
367)