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