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