eb2c4c8b26d0091df716881a8b9b70fcc231e0ea
[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:=7
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 # Set READELF here so that the exact same readelf program name can be
142 # replaced in _sysconfigdata.py (in Py3Package/python3-base/install)
143 TARGET_CONFIGURE_OPTS+= \
144 READELF="$(TARGET_CROSS)readelf"
145
146 EXTRA_LDFLAGS+= \
147 -L$(PKG_BUILD_DIR) \
148 -L$(STAGING_DIR)/usr/lib -L$(STAGING_DIR)/lib
149
150 # Workaround for hardfloat mips
151 # https://bugs.python.org/issue46265
152 ifneq ($(findstring mips,$(CONFIG_ARCH)),)
153 ifeq ($(CONFIG_HAS_FPU),y)
154 CONFIGURE_VARS += \
155 ax_cv_check_cflags___fno_semantic_interposition=no
156 endif
157 endif
158
159 MAKE_VARS += \
160 PYTHONSTRICTEXTENSIONBUILD=1
161
162 CONFIGURE_ARGS+= \
163 --enable-optimizations \
164 --enable-shared \
165 --with-system-ffi \
166 --without-cxx-main \
167 --without-ensurepip \
168 --disable-test-modules \
169 $(if $(CONFIG_IPV6),--enable-ipv6) \
170 $(if $(findstring mips,$(CONFIG_ARCH)),,--with-lto) \
171 CONFIG_SITE="$(PKG_BUILD_DIR)/config.site" \
172 OPT="$(TARGET_CFLAGS)"
173
174 define Build/Prepare
175 $(call Build/Prepare/Default)
176 $(CP) ./files/config.site $(PKG_BUILD_DIR)/config.site
177 endef
178
179 ifdef CONFIG_PACKAGE_python3-setuptools
180 PYTHON3_SETUPTOOLS_BUILD:=1
181 endif
182
183 ifdef CONFIG_PACKAGE_python3-pkg-resources
184 PYTHON3_SETUPTOOLS_BUILD:=1
185 endif
186
187 ifeq ($(PYTHON3_SETUPTOOLS_BUILD),1)
188 define Build/Compile/python3-setuptools
189 $(HOST_PYTHON3_PIP_VARS) \
190 $(HOST_PYTHON3_PIP) \
191 install \
192 --ignore-installed \
193 --progress-bar off \
194 --root=$(PKG_BUILD_DIR)/install-setuptools \
195 --prefix=/usr \
196 $(PKG_BUILD_DIR)/Lib/ensurepip/_bundled/setuptools-$(PYTHON3_SETUPTOOLS_VERSION)-py3-none-any.whl
197 $(call PatchDir,$(PKG_BUILD_DIR)/install-setuptools/usr/lib/python$(PYTHON3_VERSION)/site-packages,./patches-setuptools,)
198 endef
199 else
200 define Build/Compile/python3-setuptools
201 ls $(PKG_BUILD_DIR)/Lib/ensurepip/_bundled/setuptools-$(PYTHON3_SETUPTOOLS_VERSION)-py3-none-any.whl
202 endef
203 endif # CONFIG_PACKAGE_python3-setuptools
204
205 ifdef CONFIG_PACKAGE_python3-pip
206 define Build/Compile/python3-pip
207 $(HOST_PYTHON3_PIP_VARS) \
208 $(HOST_PYTHON3_PIP) \
209 install \
210 --ignore-installed \
211 --progress-bar off \
212 --root=$(PKG_BUILD_DIR)/install-pip \
213 --prefix=/usr \
214 $(PKG_BUILD_DIR)/Lib/ensurepip/_bundled/pip-$(PYTHON3_PIP_VERSION)-py3-none-any.whl
215 $(call PatchDir,$(PKG_BUILD_DIR)/install-pip/usr/lib/python$(PYTHON3_VERSION)/site-packages,./patches-pip,)
216 endef
217 else
218 define Build/Compile/python3-pip
219 ls $(PKG_BUILD_DIR)/Lib/ensurepip/_bundled/pip-$(PYTHON3_PIP_VERSION)-py3-none-any.whl
220 endef
221 endif # CONFIG_PACKAGE_python3-pip
222
223 define Build/Compile
224 $(call Build/Compile/Default)
225 # Use host pip to install python-setuptools
226 $(call Build/Compile/python3-setuptools)
227 $(call Build/Compile/python3-pip)
228 endef
229
230 define Build/InstallDev
231 $(INSTALL_DIR) $(1)/usr/include $(1)/usr/lib $(1)/usr/lib/pkgconfig
232 $(INSTALL_DIR) $(2)/bin
233 $(CP) \
234 $(PKG_INSTALL_DIR)/usr/include/python$(PYTHON3_VERSION) \
235 $(1)/usr/include/
236 $(CP) \
237 $(PKG_INSTALL_DIR)/usr/lib/python$(PYTHON3_VERSION) \
238 $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON3_VERSION).so* \
239 $(1)/usr/lib/
240 grep \
241 '^_PYTHON_HOST_PLATFORM=' \
242 $(PKG_INSTALL_DIR)/usr/lib/python$(PYTHON3_VERSION)/config-$(PYTHON3_VERSION)/Makefile > \
243 $(1)/usr/lib/python$(PYTHON3_VERSION)/config-$(PYTHON3_VERSION)/Makefile-vars
244 $(CP) \
245 $(PKG_INSTALL_DIR)/usr/lib/pkgconfig/python*.pc \
246 $(1)/usr/lib/pkgconfig
247 $(INSTALL_BIN) \
248 $(PKG_INSTALL_DIR)/usr/bin/python$(PYTHON3_VERSION)-config \
249 $(2)/bin/
250 $(SED) \
251 's|^prefix_real=.*$$$$|prefix_real="$(PYTHON3_DIR)"|' \
252 $(2)/bin/python$(PYTHON3_VERSION)-config
253 endef
254
255 PYTHON3_BASE_LIB_FILES:= \
256 /usr/lib/python$(PYTHON3_VERSION)/encodings \
257 /usr/lib/python$(PYTHON3_VERSION)/_collections_abc.py \
258 /usr/lib/python$(PYTHON3_VERSION)/_sitebuiltins.py \
259 /usr/lib/python$(PYTHON3_VERSION)/_sysconfigdata.py \
260 /usr/lib/python$(PYTHON3_VERSION)/_weakrefset.py \
261 /usr/lib/python$(PYTHON3_VERSION)/abc.py \
262 /usr/lib/python$(PYTHON3_VERSION)/codecs.py \
263 /usr/lib/python$(PYTHON3_VERSION)/genericpath.py \
264 /usr/lib/python$(PYTHON3_VERSION)/io.py \
265 /usr/lib/python$(PYTHON3_VERSION)/os.py \
266 /usr/lib/python$(PYTHON3_VERSION)/posixpath.py \
267 /usr/lib/python$(PYTHON3_VERSION)/site.py \
268 /usr/lib/python$(PYTHON3_VERSION)/sysconfig.py \
269 /usr/lib/python$(PYTHON3_VERSION)/stat.py
270
271 PYTHON3_LIB_FILES_DEL+=$(PYTHON3_BASE_LIB_FILES)
272
273 define Py3Package/python3-base/filespec
274 +|/usr/bin/python$(PYTHON3_VERSION)
275 $(subst $(space),$(newline),$(foreach lib_file,$(PYTHON3_BASE_LIB_FILES),+|$(lib_file)))
276 endef
277
278 define Py3Package/python3-light/filespec
279 +|/usr/lib/python$(PYTHON3_VERSION)
280 -|/usr/lib/python$(PYTHON3_VERSION)/distutils/cygwinccompiler.py
281 -|/usr/lib/python$(PYTHON3_VERSION)/distutils/command/wininst*
282 -|/usr/lib/python$(PYTHON3_VERSION)/idlelib
283 -|/usr/lib/python$(PYTHON3_VERSION)/tkinter
284 -|/usr/lib/python$(PYTHON3_VERSION)/turtledemo
285 -|/usr/lib/python$(PYTHON3_VERSION)/lib-dynload/_test*.so
286 -|/usr/lib/python$(PYTHON3_VERSION)/pdb.doc
287 -|/usr/lib/python$(PYTHON3_VERSION)/test
288 -|/usr/lib/python$(PYTHON3_VERSION)/webbrowser.py
289 -|/usr/lib/python$(PYTHON3_VERSION)/*/test
290 -|/usr/lib/python$(PYTHON3_VERSION)/*/tests
291 -|/usr/lib/python$(PYTHON3_VERSION)/_osx_support.py
292 $(subst $(space),$(newline),$(foreach lib_file,$(PYTHON3_LIB_FILES_DEL),-|$(lib_file)))
293 endef
294
295 define Package/libpython3/install
296 # Adding the lib-dynload folder (even just empty) suppresses 2 warnings when starting Python
297 $(INSTALL_DIR) $(1)/usr/lib/python$(PYTHON3_VERSION)/lib-dynload/
298 $(CP) $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON3_VERSION).so* $(1)/usr/lib/
299 endef
300
301 define Py3Package/python3-base/install
302 $(INSTALL_DIR) $(1)/usr/bin
303 $(LN) python$(PYTHON3_VERSION) $(1)/usr/bin/python3
304 $(LN) python$(PYTHON3_VERSION) $(1)/usr/bin/python
305 # This depends on being called before filespec is processed
306 $(SED) 's|$(TARGET_AR)|ar|g;s|$(TARGET_CROSS)readelf|readelf|g;s|$(TARGET_CC)|gcc|g;s|$(TARGET_CXX)|g++|g' \
307 $(PKG_INSTALL_DIR)/usr/lib/python$(PYTHON3_VERSION)/_sysconfigdata.py
308 endef
309
310 Py3Package/python3-light/install:=:
311 Py3Package/python3/install:=:
312
313 define Py3Package/python3/filespec
314 -|$(PYTHON3_PKG_DIR)
315 endef
316
317 HOST_LDFLAGS += \
318 -Wl$(comma)-rpath$(comma)$(STAGING_DIR_HOSTPKG)/lib
319
320 ifeq ($(HOST_OS),Linux)
321 HOST_LDFLAGS += \
322 -Wl,--no-as-needed -lrt
323 endif
324
325 # Would be nice to be able to do this, but hosts are very fiddly
326 # HOST_MAKE_VARS += \
327 # PYTHONSTRICTEXTENSIONBUILD=1
328
329 ifeq ($(HOST_OS),Darwin)
330 HOST_CONFIGURE_VARS += \
331 ac_cv_header_libintl_h=no
332 HOST_MAKE_VARS += \
333 USE_PYTHON_CONFIG_PY=1
334 endif
335
336 HOST_CONFIGURE_ARGS+= \
337 --enable-optimizations \
338 --with-ensurepip=upgrade \
339 --with-system-expat=$(STAGING_DIR_HOST) \
340 --with-ssl-default-suites=openssl \
341 --without-cxx-main \
342 --disable-test-modules \
343 CONFIG_SITE=
344
345 define Host/Configure
346 $(SED) 's/^ENABLE_USER_SITE = None$$$$/ENABLE_USER_SITE = False/' $(HOST_BUILD_DIR)/Lib/site.py
347 $(call Host/Configure/Default)
348 endef
349
350 define Host/Compile
351 $(call Host/Compile/Default,python)
352 $(call Host/Compile/Default,sharedmods)
353 endef
354
355 define Host/Install
356 $(if $(wildcard $(HOST_PYTHON3_PKG_DIR)/.setuptools_installed_$(PYTHON3_SETUPTOOLS_VERSION)-$(PYTHON3_SETUPTOOLS_PKG_RELEASE)),,
357 rm -rf \
358 $(HOST_PYTHON3_PKG_DIR)/pkg_resources \
359 $(HOST_PYTHON3_PKG_DIR)/setuptools \
360 $(HOST_PYTHON3_PKG_DIR)/setuptools-* \
361 $(HOST_PYTHON3_PKG_DIR)/.setuptools-patched* \
362 $(HOST_PYTHON3_PKG_DIR)/.setuptools_installed_*
363 )
364 $(if $(wildcard $(HOST_PYTHON3_PKG_DIR)/.pip_installed_$(PYTHON3_PIP_VERSION)-$(PYTHON3_PIP_PKG_RELEASE)),,
365 rm -rf \
366 $(HOST_PYTHON3_PKG_DIR)/pip \
367 $(HOST_PYTHON3_PKG_DIR)/pip-* \
368 $(HOST_PYTHON3_PKG_DIR)/.pip-patched* \
369 $(HOST_PYTHON3_PKG_DIR)/.pip_installed_*
370 )
371 $(call Host/Install/Default)
372 $(if $(wildcard $(HOST_PYTHON3_PKG_DIR)/.setuptools_installed_$(PYTHON3_SETUPTOOLS_VERSION)-$(PYTHON3_SETUPTOOLS_PKG_RELEASE)),,
373 $(call HostPatchDir,$(HOST_PYTHON3_PKG_DIR),./patches-setuptools,)
374 touch $(HOST_PYTHON3_PKG_DIR)/.setuptools_installed_$(PYTHON3_SETUPTOOLS_VERSION)-$(PYTHON3_SETUPTOOLS_PKG_RELEASE)
375 )
376 $(if $(wildcard $(HOST_PYTHON3_PKG_DIR)/.pip_installed_$(PYTHON3_PIP_VERSION)-$(PYTHON3_PIP_PKG_RELEASE)),,
377 $(call HostPatchDir,$(HOST_PYTHON3_PKG_DIR),./patches-pip,)
378 touch $(HOST_PYTHON3_PKG_DIR)/.pip_installed_$(PYTHON3_PIP_VERSION)-$(PYTHON3_PIP_PKG_RELEASE)
379 )
380 endef
381
382 $(eval $(call HostBuild))
383
384 $(foreach package, $(PYTHON3_PACKAGES), \
385 $(eval $(call Py3Package,$(package))) \
386 $(eval $(call BuildPackage,$(package))) \
387 $(eval $(call BuildPackage,$(package)-src)) \
388 )
389
390 $(eval $(call BuildPackage,libpython3))
391
392 $(eval $(call Py3Package,python3-base))
393 $(eval $(call Py3Package,python3-light))
394 $(eval $(call Py3Package,python3))
395
396 $(eval $(call BuildPackage,python3-base))
397 $(eval $(call BuildPackage,python3-light))
398 $(eval $(call BuildPackage,python3))
399
400 $(eval $(call BuildPackage,python3-base-src))
401 $(eval $(call BuildPackage,python3-light-src))