Merge pull request #17481 from jefferyto/python-3.10.1
[feed/packages.git] / lang / python / python3 / Makefile
1 #
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
8 include $(TOPDIR)/rules.mk
9
10 # The file included below defines PYTHON3_VERSION
11 include ../python3-version.mk
12
13 PKG_NAME:=python3
14 PKG_RELEASE:=1
15 PKG_VERSION:=$(PYTHON3_VERSION).$(PYTHON3_VERSION_MICRO)
16
17 PKG_SOURCE:=Python-$(PKG_VERSION).tar.xz
18 PKG_SOURCE_URL:=https://www.python.org/ftp/python/$(PKG_VERSION)
19 # FIXME: if updating, get rid of [1] & [2] asap
20 PKG_HASH:=a7f1265b6e1a5de1ec5c3ec7019ab53413469934758311e9d240c46e5ae6e177
21
22 PKG_MAINTAINER:=Jeffery To <jeffery.to@gmail.com>
23 PKG_LICENSE:=PSF-2.0
24 PKG_LICENSE_FILES:=LICENSE Doc/copyright.rst Doc/license.rst Modules/_ctypes/darwin/LICENSE Modules/_ctypes/libffi_osx/LICENSE Modules/expat/COPYING
25 PKG_CPE_ID:=cpe:/a:python:python
26
27 # This file provides the necsessary host build variables
28 include ../python3-host.mk
29
30 # For Py3Package
31 PYTHON3_PKG_BUILD:=0
32 include ../python3-package.mk
33
34 PKG_FIXUP:=autoreconf
35 PKG_INSTALL:=1
36 PKG_BUILD_PARALLEL:=1
37 HOST_BUILD_PARALLEL:=1
38
39 PKG_BUILD_DIR:=$(BUILD_DIR)/Python-$(PKG_VERSION)
40 HOST_BUILD_DIR:=$(BUILD_DIR_HOST)/Python-$(PKG_VERSION)
41
42 PKG_CONFIG_DEPENDS:= \
43 CONFIG_PACKAGE_python3-pkg-resources \
44 CONFIG_PACKAGE_python3-setuptools CONFIG_PACKAGE_python3-pip
45
46 PKG_BUILD_DEPENDS:=bluez python3/host
47 HOST_BUILD_DEPENDS:=bzip2/host libffi/host
48
49 include $(INCLUDE_DIR)/host-build.mk
50 include $(INCLUDE_DIR)/package.mk
51
52 define Package/python3/Default
53 SUBMENU:=Python
54 SECTION:=lang
55 CATEGORY:=Languages
56 TITLE:=Python $(PYTHON3_VERSION) programming language
57 URL:=https://www.python.org/
58 endef
59
60 define Package/python3/Default/description
61 Python is a dynamic object-oriented programming language that can be used
62 for many kinds of software development. It offers strong support for
63 integration with other languages and tools, comes with extensive standard
64 libraries, and can be learned in a few days. Many Python programmers
65 report substantial productivity gains and feel the language encourages
66 the development of higher quality, more maintainable code.
67 endef
68
69 define Package/libpython3
70 $(call Package/python3/Default)
71 TITLE:=Python $(PYTHON3_VERSION) core library
72 DEPENDS:=+libpthread +zlib
73 ABI_VERSION:=$(PYTHON3_VERSION)
74 endef
75
76 define Package/libpython3/description
77 This package contains only core Python library.
78 endef
79
80 define Package/python3-base
81 $(call Package/python3/Default)
82 TITLE:=Python $(PYTHON3_VERSION) interpreter
83 DEPENDS:=+libpthread +zlib +libpython3
84 endef
85
86 define Package/python3-base/description
87 This package contains only the interpreter and the bare minimum
88 for the interpreter to start.
89 endef
90
91 define Package/python3-light
92 $(call Package/python3/Default)
93 TITLE:=Python $(PYTHON3_VERSION) light installation
94 DEPENDS:=+python3-base +libffi +libbz2
95 endef
96
97 define Package/python3-light/config
98 source "$(SOURCE)/Config-python3-light.in"
99 endef
100
101 define Package/python3-light/description
102 This package is essentially the python3-base package plus
103 a few of the rarely used (and big) libraries stripped out
104 into separate packages.
105 endef
106
107 PYTHON3_LIB_FILES_DEL:=
108 PYTHON3_PACKAGES:=
109 PYTHON3_SO_SUFFIX:=cpython-$(PYTHON3_VERSION_MAJOR)$(PYTHON3_VERSION_MINOR).so
110 PYTHON3_PACKAGES_DEPENDS:=
111 define Py3BasePackage
112 PYTHON3_PACKAGES+=$(1)
113 ifeq ($(3),)
114 PYTHON3_PACKAGES_DEPENDS+=$(1)
115 endif
116 PYTHON3_LIB_FILES_DEL+=$(2)
117 define Py3Package/$(1)/filespec
118 ifneq ($(2),)
119 $(subst $(space),$(newline),$(foreach lib_file,$(2),+|$(lib_file)))
120 -|/usr/lib/python$(PYTHON3_VERSION)/*/test
121 -|/usr/lib/python$(PYTHON3_VERSION)/*/tests
122 endif
123 endef
124 Py3Package/$(1)/install?=:
125 endef
126
127 include ./files/python3-package-*.mk
128
129 define Package/python3
130 $(call Package/python3/Default)
131 DEPENDS:=+python3-light $(foreach package,$(PYTHON3_PACKAGES_DEPENDS),+$(package))
132 endef
133
134 define Package/python3/description
135 This package contains the (almost) full Python install.
136 It's python3-light + all other packages.
137 endef
138
139 EXTRA_LDFLAGS+= \
140 -L$(PKG_BUILD_DIR) \
141 -L$(STAGING_DIR)/usr/lib -L$(STAGING_DIR)/lib
142
143 # Workaround for hardfloat mips
144 # https://bugs.python.org/issue46265
145 ifneq ($(findstring mips,$(CONFIG_ARCH)),)
146 ifeq ($(CONFIG_HAS_FPU),y)
147 CONFIGURE_VARS += \
148 ax_cv_check_cflags___fno_semantic_interposition=no
149 endif
150 endif
151
152 MAKE_VARS += \
153 PYTHONSTRICTEXTENSIONBUILD=1
154
155 CONFIGURE_ARGS+= \
156 --enable-optimizations \
157 --enable-shared \
158 --with-system-ffi \
159 --without-cxx-main \
160 --without-ensurepip \
161 --without-pymalloc \
162 --disable-test-modules \
163 $(if $(CONFIG_IPV6),--enable-ipv6) \
164 $(if $(findstring mips,$(CONFIG_ARCH)),,--with-lto) \
165 CONFIG_SITE="$(PKG_BUILD_DIR)/config.site" \
166 OPT="$(TARGET_CFLAGS)"
167
168 define Build/Prepare
169 $(call Build/Prepare/Default)
170 $(CP) ./files/config.site $(PKG_BUILD_DIR)/config.site
171 endef
172
173 ifdef CONFIG_PACKAGE_python3-setuptools
174 PYTHON3_SETUPTOOLS_BUILD:=1
175 endif
176
177 ifdef CONFIG_PACKAGE_python3-pkg-resources
178 PYTHON3_SETUPTOOLS_BUILD:=1
179 endif
180
181 ifeq ($(PYTHON3_SETUPTOOLS_BUILD),1)
182 define Build/Compile/python3-setuptools
183 $(HOST_PYTHON3_PIP) \
184 --disable-pip-version-check \
185 --cache-dir "$(DL_DIR)/pip-cache" \
186 install \
187 --ignore-installed \
188 --root=$(PKG_BUILD_DIR)/install-setuptools \
189 --prefix=/usr \
190 $(PKG_BUILD_DIR)/Lib/ensurepip/_bundled/setuptools-$(PYTHON3_SETUPTOOLS_VERSION)-py3-none-any.whl
191 $(call PatchDir,$(PKG_BUILD_DIR)/install-setuptools/usr/lib/python$(PYTHON3_VERSION)/site-packages,./patches-setuptools,)
192 endef
193 else
194 define Build/Compile/python3-setuptools
195 ls $(PKG_BUILD_DIR)/Lib/ensurepip/_bundled/setuptools-$(PYTHON3_SETUPTOOLS_VERSION)-py3-none-any.whl
196 endef
197 endif # CONFIG_PACKAGE_python3-setuptools
198
199 ifdef CONFIG_PACKAGE_python3-pip
200 define Build/Compile/python3-pip
201 $(HOST_PYTHON3_PIP) \
202 --disable-pip-version-check \
203 --cache-dir "$(DL_DIR)/pip-cache" \
204 install \
205 --ignore-installed \
206 --root=$(PKG_BUILD_DIR)/install-pip \
207 --prefix=/usr \
208 $(PKG_BUILD_DIR)/Lib/ensurepip/_bundled/pip-$(PYTHON3_PIP_VERSION)-py3-none-any.whl
209 # FIXME: [1] get rid of this asap; 'patch' doesn't like Windows endings, and this file is full of them...
210 # I actually tried this in a number of ways and the only way to fix this is to implement
211 # a poor-man's dos2unix using sed.
212 # The issue is with the pip package; it seems that it throws in some Windows line-endings
213 # and 'patch' won't handle them. So, we do a "dos2unix" and then patch.
214 # We can get rid of this once this is solved upstream and in pip:
215 # https://github.com/pypa/pep517/pull/130
216 sed 's/\r//' -i $(PKG_BUILD_DIR)/install-pip/usr/lib/python$(PYTHON3_VERSION)/site-packages/pip/_vendor/pep517/in_process/__init__.py
217 $(call PatchDir,$(PKG_BUILD_DIR)/install-pip/usr/lib/python$(PYTHON3_VERSION)/site-packages,./patches-pip,)
218 endef
219 else
220 define Build/Compile/python3-pip
221 ls $(PKG_BUILD_DIR)/Lib/ensurepip/_bundled/pip-$(PYTHON3_PIP_VERSION)-py3-none-any.whl
222 endef
223 endif # CONFIG_PACKAGE_python3-pip
224
225 define Build/Compile
226 $(call Build/Compile/Default)
227 # Use host pip to install python-setuptools
228 $(call Build/Compile/python3-setuptools)
229 $(call Build/Compile/python3-pip)
230 endef
231
232 define Build/InstallDev
233 $(INSTALL_DIR) $(1)/usr/include $(1)/usr/lib $(1)/usr/lib/pkgconfig
234 $(INSTALL_DIR) $(2)/bin
235 $(CP) \
236 $(PKG_INSTALL_DIR)/usr/include/python$(PYTHON3_VERSION) \
237 $(1)/usr/include/
238 $(CP) \
239 $(PKG_INSTALL_DIR)/usr/lib/python$(PYTHON3_VERSION) \
240 $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON3_VERSION).so* \
241 $(1)/usr/lib/
242 grep \
243 '^_PYTHON_HOST_PLATFORM=' \
244 $(PKG_INSTALL_DIR)/usr/lib/python$(PYTHON3_VERSION)/config-$(PYTHON3_VERSION)/Makefile > \
245 $(1)/usr/lib/python$(PYTHON3_VERSION)/config-$(PYTHON3_VERSION)/Makefile-vars
246 $(CP) \
247 $(PKG_INSTALL_DIR)/usr/lib/pkgconfig/python*.pc \
248 $(1)/usr/lib/pkgconfig
249 $(INSTALL_BIN) \
250 $(PKG_INSTALL_DIR)/usr/bin/python$(PYTHON3_VERSION)-config \
251 $(2)/bin/
252 $(SED) \
253 's|^prefix_real=.*$$$$|prefix_real="$(PYTHON3_DIR)"|' \
254 $(2)/bin/python$(PYTHON3_VERSION)-config
255 endef
256
257 PYTHON3_BASE_LIB_FILES:= \
258 /usr/lib/python$(PYTHON3_VERSION)/encodings \
259 /usr/lib/python$(PYTHON3_VERSION)/_collections_abc.py \
260 /usr/lib/python$(PYTHON3_VERSION)/_sitebuiltins.py \
261 /usr/lib/python$(PYTHON3_VERSION)/_sysconfigdata.py \
262 /usr/lib/python$(PYTHON3_VERSION)/_weakrefset.py \
263 /usr/lib/python$(PYTHON3_VERSION)/abc.py \
264 /usr/lib/python$(PYTHON3_VERSION)/codecs.py \
265 /usr/lib/python$(PYTHON3_VERSION)/genericpath.py \
266 /usr/lib/python$(PYTHON3_VERSION)/io.py \
267 /usr/lib/python$(PYTHON3_VERSION)/os.py \
268 /usr/lib/python$(PYTHON3_VERSION)/posixpath.py \
269 /usr/lib/python$(PYTHON3_VERSION)/site.py \
270 /usr/lib/python$(PYTHON3_VERSION)/sysconfig.py \
271 /usr/lib/python$(PYTHON3_VERSION)/stat.py
272
273 PYTHON3_LIB_FILES_DEL+=$(PYTHON3_BASE_LIB_FILES)
274
275 define Py3Package/python3-base/filespec
276 +|/usr/bin/python$(PYTHON3_VERSION)
277 $(subst $(space),$(newline),$(foreach lib_file,$(PYTHON3_BASE_LIB_FILES),+|$(lib_file)))
278 endef
279
280 define Py3Package/python3-light/filespec
281 +|/usr/lib/python$(PYTHON3_VERSION)
282 -|/usr/lib/python$(PYTHON3_VERSION)/distutils/cygwinccompiler.py
283 -|/usr/lib/python$(PYTHON3_VERSION)/distutils/command/wininst*
284 -|/usr/lib/python$(PYTHON3_VERSION)/ensurepip
285 -|/usr/lib/python$(PYTHON3_VERSION)/idlelib
286 -|/usr/lib/python$(PYTHON3_VERSION)/tkinter
287 -|/usr/lib/python$(PYTHON3_VERSION)/turtledemo
288 -|/usr/lib/python$(PYTHON3_VERSION)/lib-dynload/_test*.so
289 -|/usr/lib/python$(PYTHON3_VERSION)/pdb.doc
290 -|/usr/lib/python$(PYTHON3_VERSION)/test
291 -|/usr/lib/python$(PYTHON3_VERSION)/webbrowser.py
292 -|/usr/lib/python$(PYTHON3_VERSION)/*/test
293 -|/usr/lib/python$(PYTHON3_VERSION)/*/tests
294 -|/usr/lib/python$(PYTHON3_VERSION)/_osx_support.py
295 $(subst $(space),$(newline),$(foreach lib_file,$(PYTHON3_LIB_FILES_DEL),-|$(lib_file)))
296 endef
297
298 define Package/libpython3/install
299 # Adding the lib-dynload folder (even just empty) suppresses 2 warnings when starting Python
300 $(INSTALL_DIR) $(1)/usr/lib/python$(PYTHON3_VERSION)/lib-dynload/
301 $(CP) $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON3_VERSION).so* $(1)/usr/lib/
302 endef
303
304 define Py3Package/python3-base/install
305 $(INSTALL_DIR) $(1)/usr/bin
306 $(LN) python$(PYTHON3_VERSION) $(1)/usr/bin/python3
307 $(LN) python$(PYTHON3_VERSION) $(1)/usr/bin/python
308 # This depends on being called before filespec is processed
309 $(SED) 's|$(TARGET_AR)|ar|g;s|$(TARGET_CROSS)readelf|readelf|g;s|$(TARGET_CC)|gcc|g;s|$(TARGET_CXX)|g++|g' \
310 $(PKG_INSTALL_DIR)/usr/lib/python$(PYTHON3_VERSION)/_sysconfigdata.py
311 endef
312
313 Py3Package/python3-light/install:=:
314 Py3Package/python3/install:=:
315
316 define Py3Package/python3/filespec
317 -|$(PYTHON3_PKG_DIR)
318 endef
319
320 HOST_LDFLAGS += \
321 -Wl$(comma)-rpath$(comma)$(STAGING_DIR_HOSTPKG)/lib
322
323 ifeq ($(HOST_OS),Linux)
324 HOST_LDFLAGS += \
325 -Wl,--no-as-needed -lrt
326 endif
327
328 # Would be nice to be able to do this, but hosts are very fiddly
329 # HOST_MAKE_VARS += \
330 # PYTHONSTRICTEXTENSIONBUILD=1
331
332 ifeq ($(HOST_OS),Darwin)
333 HOST_CONFIGURE_VARS += \
334 ac_cv_header_libintl_h=no
335 HOST_MAKE_VARS += \
336 USE_PYTHON_CONFIG_PY=1
337 endif
338
339 # FIXME: remove when removing patch '028-host-python-support-ssl-with-libressl.patch'
340 HOST_CFLAGS += \
341 -DOPENWRT_HOST_BUILD
342
343 HOST_CONFIGURE_ARGS+= \
344 --enable-optimizations \
345 --with-ensurepip=upgrade \
346 --with-system-expat=$(STAGING_DIR_HOSTPKG) \
347 --with-ssl-default-suites=openssl \
348 --without-cxx-main \
349 --without-pymalloc \
350 --disable-test-modules \
351 CONFIG_SITE=
352
353 define Host/Configure
354 $(SED) 's/^ENABLE_USER_SITE = None$$$$/ENABLE_USER_SITE = False/' $(HOST_BUILD_DIR)/Lib/site.py
355 $(call Host/Configure/Default)
356 endef
357
358 define Host/Compile
359 $(call Host/Compile/Default,python)
360 $(call Host/Compile/Default,sharedmods)
361 endef
362
363 define Host/Install
364 $(if $(wildcard $(HOST_PYTHON3_PKG_DIR)/.setuptools_installed_$(PYTHON3_SETUPTOOLS_VERSION)-$(PYTHON3_SETUPTOOLS_PKG_RELEASE)),,
365 rm -rf \
366 $(HOST_PYTHON3_PKG_DIR)/pkg_resources \
367 $(HOST_PYTHON3_PKG_DIR)/setuptools \
368 $(HOST_PYTHON3_PKG_DIR)/setuptools-* \
369 $(HOST_PYTHON3_PKG_DIR)/.setuptools-patched* \
370 $(HOST_PYTHON3_PKG_DIR)/.setuptools_installed_*
371 )
372 $(if $(wildcard $(HOST_PYTHON3_PKG_DIR)/.pip_installed_$(PYTHON3_PIP_VERSION)-$(PYTHON3_PIP_PKG_RELEASE)),,
373 rm -rf \
374 $(HOST_PYTHON3_PKG_DIR)/pip \
375 $(HOST_PYTHON3_PKG_DIR)/pip-* \
376 $(HOST_PYTHON3_PKG_DIR)/.pip-patched* \
377 $(HOST_PYTHON3_PKG_DIR)/.pip_installed_*
378 )
379 $(call Host/Install/Default)
380 $(if $(wildcard $(HOST_PYTHON3_PKG_DIR)/.setuptools_installed_$(PYTHON3_SETUPTOOLS_VERSION)-$(PYTHON3_SETUPTOOLS_PKG_RELEASE)),,
381 $(call HostPatchDir,$(HOST_PYTHON3_PKG_DIR),./patches-setuptools,)
382 touch $(HOST_PYTHON3_PKG_DIR)/.setuptools_installed_$(PYTHON3_SETUPTOOLS_VERSION)-$(PYTHON3_SETUPTOOLS_PKG_RELEASE)
383 )
384 $(if $(wildcard $(HOST_PYTHON3_PKG_DIR)/.pip_installed_$(PYTHON3_PIP_VERSION)-$(PYTHON3_PIP_PKG_RELEASE)),,
385 # FIXME: [2] get rid of this asap; same as [1]
386 sed 's/\r//' -i $(HOST_PYTHON3_PKG_DIR)/pip/_vendor/pep517/in_process/__init__.py
387 $(call HostPatchDir,$(HOST_PYTHON3_PKG_DIR),./patches-pip,)
388 touch $(HOST_PYTHON3_PKG_DIR)/.pip_installed_$(PYTHON3_PIP_VERSION)-$(PYTHON3_PIP_PKG_RELEASE)
389 )
390 endef
391
392 $(eval $(call HostBuild))
393
394 $(foreach package, $(PYTHON3_PACKAGES), \
395 $(eval $(call Py3Package,$(package))) \
396 $(eval $(call BuildPackage,$(package))) \
397 $(eval $(call BuildPackage,$(package)-src)) \
398 )
399
400 $(eval $(call BuildPackage,libpython3))
401
402 $(eval $(call Py3Package,python3-base))
403 $(eval $(call Py3Package,python3-light))
404 $(eval $(call Py3Package,python3))
405
406 $(eval $(call BuildPackage,python3-base))
407 $(eval $(call BuildPackage,python3-light))
408 $(eval $(call BuildPackage,python3))
409
410 $(eval $(call BuildPackage,python3-base-src))
411 $(eval $(call BuildPackage,python3-light-src))