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