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