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