python3: Remove --without-pymalloc
[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:=5
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 --disable-test-modules \
164 $(if $(CONFIG_IPV6),--enable-ipv6) \
165 $(if $(findstring mips,$(CONFIG_ARCH)),,--with-lto) \
166 CONFIG_SITE="$(PKG_BUILD_DIR)/config.site" \
167 OPT="$(TARGET_CFLAGS)"
168
169 define Build/Prepare
170 $(call Build/Prepare/Default)
171 $(CP) ./files/config.site $(PKG_BUILD_DIR)/config.site
172 endef
173
174 ifdef CONFIG_PACKAGE_python3-setuptools
175 PYTHON3_SETUPTOOLS_BUILD:=1
176 endif
177
178 ifdef CONFIG_PACKAGE_python3-pkg-resources
179 PYTHON3_SETUPTOOLS_BUILD:=1
180 endif
181
182 ifeq ($(PYTHON3_SETUPTOOLS_BUILD),1)
183 define Build/Compile/python3-setuptools
184 $(HOST_PYTHON3_PIP_VARS) \
185 $(HOST_PYTHON3_PIP) \
186 install \
187 --ignore-installed \
188 --progress-bar off \
189 --root=$(PKG_BUILD_DIR)/install-setuptools \
190 --prefix=/usr \
191 $(PKG_BUILD_DIR)/Lib/ensurepip/_bundled/setuptools-$(PYTHON3_SETUPTOOLS_VERSION)-py3-none-any.whl
192 $(call PatchDir,$(PKG_BUILD_DIR)/install-setuptools/usr/lib/python$(PYTHON3_VERSION)/site-packages,./patches-setuptools,)
193 endef
194 else
195 define Build/Compile/python3-setuptools
196 ls $(PKG_BUILD_DIR)/Lib/ensurepip/_bundled/setuptools-$(PYTHON3_SETUPTOOLS_VERSION)-py3-none-any.whl
197 endef
198 endif # CONFIG_PACKAGE_python3-setuptools
199
200 ifdef CONFIG_PACKAGE_python3-pip
201 define Build/Compile/python3-pip
202 $(HOST_PYTHON3_PIP_VARS) \
203 $(HOST_PYTHON3_PIP) \
204 install \
205 --ignore-installed \
206 --progress-bar off \
207 --root=$(PKG_BUILD_DIR)/install-pip \
208 --prefix=/usr \
209 $(PKG_BUILD_DIR)/Lib/ensurepip/_bundled/pip-$(PYTHON3_PIP_VERSION)-py3-none-any.whl
210 $(call PatchDir,$(PKG_BUILD_DIR)/install-pip/usr/lib/python$(PYTHON3_VERSION)/site-packages,./patches-pip,)
211 endef
212 else
213 define Build/Compile/python3-pip
214 ls $(PKG_BUILD_DIR)/Lib/ensurepip/_bundled/pip-$(PYTHON3_PIP_VERSION)-py3-none-any.whl
215 endef
216 endif # CONFIG_PACKAGE_python3-pip
217
218 define Build/Compile
219 $(call Build/Compile/Default)
220 # Use host pip to install python-setuptools
221 $(call Build/Compile/python3-setuptools)
222 $(call Build/Compile/python3-pip)
223 endef
224
225 define Build/InstallDev
226 $(INSTALL_DIR) $(1)/usr/include $(1)/usr/lib $(1)/usr/lib/pkgconfig
227 $(INSTALL_DIR) $(2)/bin
228 $(CP) \
229 $(PKG_INSTALL_DIR)/usr/include/python$(PYTHON3_VERSION) \
230 $(1)/usr/include/
231 $(CP) \
232 $(PKG_INSTALL_DIR)/usr/lib/python$(PYTHON3_VERSION) \
233 $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON3_VERSION).so* \
234 $(1)/usr/lib/
235 grep \
236 '^_PYTHON_HOST_PLATFORM=' \
237 $(PKG_INSTALL_DIR)/usr/lib/python$(PYTHON3_VERSION)/config-$(PYTHON3_VERSION)/Makefile > \
238 $(1)/usr/lib/python$(PYTHON3_VERSION)/config-$(PYTHON3_VERSION)/Makefile-vars
239 $(CP) \
240 $(PKG_INSTALL_DIR)/usr/lib/pkgconfig/python*.pc \
241 $(1)/usr/lib/pkgconfig
242 $(INSTALL_BIN) \
243 $(PKG_INSTALL_DIR)/usr/bin/python$(PYTHON3_VERSION)-config \
244 $(2)/bin/
245 $(SED) \
246 's|^prefix_real=.*$$$$|prefix_real="$(PYTHON3_DIR)"|' \
247 $(2)/bin/python$(PYTHON3_VERSION)-config
248 endef
249
250 PYTHON3_BASE_LIB_FILES:= \
251 /usr/lib/python$(PYTHON3_VERSION)/encodings \
252 /usr/lib/python$(PYTHON3_VERSION)/_collections_abc.py \
253 /usr/lib/python$(PYTHON3_VERSION)/_sitebuiltins.py \
254 /usr/lib/python$(PYTHON3_VERSION)/_sysconfigdata.py \
255 /usr/lib/python$(PYTHON3_VERSION)/_weakrefset.py \
256 /usr/lib/python$(PYTHON3_VERSION)/abc.py \
257 /usr/lib/python$(PYTHON3_VERSION)/codecs.py \
258 /usr/lib/python$(PYTHON3_VERSION)/genericpath.py \
259 /usr/lib/python$(PYTHON3_VERSION)/io.py \
260 /usr/lib/python$(PYTHON3_VERSION)/os.py \
261 /usr/lib/python$(PYTHON3_VERSION)/posixpath.py \
262 /usr/lib/python$(PYTHON3_VERSION)/site.py \
263 /usr/lib/python$(PYTHON3_VERSION)/sysconfig.py \
264 /usr/lib/python$(PYTHON3_VERSION)/stat.py
265
266 PYTHON3_LIB_FILES_DEL+=$(PYTHON3_BASE_LIB_FILES)
267
268 define Py3Package/python3-base/filespec
269 +|/usr/bin/python$(PYTHON3_VERSION)
270 $(subst $(space),$(newline),$(foreach lib_file,$(PYTHON3_BASE_LIB_FILES),+|$(lib_file)))
271 endef
272
273 define Py3Package/python3-light/filespec
274 +|/usr/lib/python$(PYTHON3_VERSION)
275 -|/usr/lib/python$(PYTHON3_VERSION)/distutils/cygwinccompiler.py
276 -|/usr/lib/python$(PYTHON3_VERSION)/distutils/command/wininst*
277 -|/usr/lib/python$(PYTHON3_VERSION)/idlelib
278 -|/usr/lib/python$(PYTHON3_VERSION)/tkinter
279 -|/usr/lib/python$(PYTHON3_VERSION)/turtledemo
280 -|/usr/lib/python$(PYTHON3_VERSION)/lib-dynload/_test*.so
281 -|/usr/lib/python$(PYTHON3_VERSION)/pdb.doc
282 -|/usr/lib/python$(PYTHON3_VERSION)/test
283 -|/usr/lib/python$(PYTHON3_VERSION)/webbrowser.py
284 -|/usr/lib/python$(PYTHON3_VERSION)/*/test
285 -|/usr/lib/python$(PYTHON3_VERSION)/*/tests
286 -|/usr/lib/python$(PYTHON3_VERSION)/_osx_support.py
287 $(subst $(space),$(newline),$(foreach lib_file,$(PYTHON3_LIB_FILES_DEL),-|$(lib_file)))
288 endef
289
290 define Package/libpython3/install
291 # Adding the lib-dynload folder (even just empty) suppresses 2 warnings when starting Python
292 $(INSTALL_DIR) $(1)/usr/lib/python$(PYTHON3_VERSION)/lib-dynload/
293 $(CP) $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON3_VERSION).so* $(1)/usr/lib/
294 endef
295
296 define Py3Package/python3-base/install
297 $(INSTALL_DIR) $(1)/usr/bin
298 $(LN) python$(PYTHON3_VERSION) $(1)/usr/bin/python3
299 $(LN) python$(PYTHON3_VERSION) $(1)/usr/bin/python
300 # This depends on being called before filespec is processed
301 $(SED) 's|$(TARGET_AR)|ar|g;s|$(TARGET_CROSS)readelf|readelf|g;s|$(TARGET_CC)|gcc|g;s|$(TARGET_CXX)|g++|g' \
302 $(PKG_INSTALL_DIR)/usr/lib/python$(PYTHON3_VERSION)/_sysconfigdata.py
303 endef
304
305 Py3Package/python3-light/install:=:
306 Py3Package/python3/install:=:
307
308 define Py3Package/python3/filespec
309 -|$(PYTHON3_PKG_DIR)
310 endef
311
312 HOST_LDFLAGS += \
313 -Wl$(comma)-rpath$(comma)$(STAGING_DIR_HOSTPKG)/lib
314
315 ifeq ($(HOST_OS),Linux)
316 HOST_LDFLAGS += \
317 -Wl,--no-as-needed -lrt
318 endif
319
320 # Would be nice to be able to do this, but hosts are very fiddly
321 # HOST_MAKE_VARS += \
322 # PYTHONSTRICTEXTENSIONBUILD=1
323
324 ifeq ($(HOST_OS),Darwin)
325 HOST_CONFIGURE_VARS += \
326 ac_cv_header_libintl_h=no
327 HOST_MAKE_VARS += \
328 USE_PYTHON_CONFIG_PY=1
329 endif
330
331 HOST_CONFIGURE_ARGS+= \
332 --enable-optimizations \
333 --with-ensurepip=upgrade \
334 --with-system-expat=$(STAGING_DIR_HOST) \
335 --with-ssl-default-suites=openssl \
336 --without-cxx-main \
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))