Merge pull request #11353 from kvuorine/fwknop-fixes
[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:=e3003ed57db17e617acb382b0cade29a248c6026b1bd8aad1f976e9af66a83b0
20
21 PKG_MAINTAINER:=Alexandru Ardelean <ardeleanalex@gmail.com>, Jeffery To <jeffery.to@gmail.com>
22 PKG_LICENSE:=Python/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 CONFIG_PYTHON3_BLUETOOTH_SUPPORT
45
46 PKG_BUILD_DEPENDS:=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/python3-base
70 $(call Package/python3/Default)
71 TITLE:=Python $(PYTHON3_VERSION) interpreter
72 DEPENDS:=+libpthread +zlib
73 endef
74
75 define Package/python3-base/description
76 This package contains only the interpreter and the bare minimum
77 for the interpreter to start.
78 endef
79
80 define Package/python3-light
81 $(call Package/python3/Default)
82 TITLE:=Python $(PYTHON3_VERSION) light installation
83 DEPENDS:=+python3-base +libffi +libbz2 +PYTHON3_BLUETOOTH_SUPPORT:bluez-libs +libuuid
84 endef
85
86 define Package/python3-light/config
87 source "$(SOURCE)/Config-python3-light.in"
88 endef
89
90 define Package/python3-light/description
91 This package is essentially the python3-base package plus
92 a few of the rarely used (and big) libraries stripped out
93 into separate packages.
94 endef
95
96 PYTHON3_LIB_FILES_DEL:=
97 PYTHON3_PACKAGES:=
98 PYTHON3_SO_SUFFIX:=cpython-$(PYTHON3_VERSION_MAJOR)$(PYTHON3_VERSION_MINOR).so
99 PYTHON3_PACKAGES_DEPENDS:=
100 define Py3BasePackage
101 PYTHON3_PACKAGES+=$(1)
102 ifeq ($(3),)
103 PYTHON3_PACKAGES_DEPENDS+=$(1)
104 endif
105 PYTHON3_LIB_FILES_DEL+=$(2)
106 define Py3Package/$(1)/filespec
107 ifneq ($(2),)
108 $(subst $(space),$(newline),$(foreach lib_file,$(2),+|$(lib_file)))
109 -|/usr/lib/python$(PYTHON3_VERSION)/*/test
110 -|/usr/lib/python$(PYTHON3_VERSION)/*/tests
111 endif
112 endef
113 Py3Package/$(1)/install?=:
114 endef
115
116 include ./files/python3-package-*.mk
117
118 define Package/python3
119 $(call Package/python3/Default)
120 DEPENDS:=+python3-light $(foreach package,$(PYTHON3_PACKAGES_DEPENDS),+$(package))
121 endef
122
123 define Package/python3/description
124 This package contains the (almost) full Python install.
125 It's python3-light + all other packages.
126 endef
127
128 TARGET_CONFIGURE_OPTS+= \
129 READELF="$(TARGET_CROSS)readelf"
130
131 MAKE_FLAGS+=\
132 LD="$(TARGET_CC)"
133
134 EXTRA_CFLAGS+= \
135 -DNDEBUG -fno-inline
136 EXTRA_LDFLAGS+= \
137 -L$(PKG_BUILD_DIR)
138
139 DISABLE_BLUETOOTH:= \
140 ac_cv_header_bluetooth_bluetooth_h=no \
141 ac_cv_header_bluetooth_h=no
142
143 CONFIGURE_ARGS+= \
144 --enable-optimizations \
145 --enable-shared \
146 --with-system-ffi \
147 --without-cxx-main \
148 --without-ensurepip \
149 --without-pymalloc \
150 $(if $(CONFIG_IPV6),--enable-ipv6) \
151 $(if $(findstring mips,$(CONFIG_ARCH)),,--with-lto) \
152 CONFIG_SITE="$(PKG_BUILD_DIR)/config.site" \
153 OPT="$(TARGET_CFLAGS)" \
154 $(if $(CONFIG_PYTHON3_BLUETOOTH_SUPPORT),,$(DISABLE_BLUETOOTH))
155
156 define Build/Prepare
157 $(call Build/Prepare/Default)
158 $(CP) ./files/config.site $(PKG_BUILD_DIR)/config.site
159 endef
160
161 ifdef CONFIG_PACKAGE_python3-setuptools
162 PYTHON3_SETUPTOOLS_BUILD:=1
163 endif
164
165 ifdef CONFIG_PACKAGE_python3-pkg-resources
166 PYTHON3_SETUPTOOLS_BUILD:=1
167 endif
168
169 ifeq ($(PYTHON3_SETUPTOOLS_BUILD),1)
170 define Build/Compile/python3-setuptools
171 $(HOST_PYTHON3_PIP) \
172 --disable-pip-version-check \
173 --cache-dir "$(DL_DIR)/pip-cache" \
174 install \
175 --ignore-installed \
176 --root=$(PKG_BUILD_DIR)/install-setuptools \
177 --prefix=/usr \
178 $(PKG_BUILD_DIR)/Lib/ensurepip/_bundled/setuptools-$(PYTHON3_SETUPTOOLS_VERSION)-py3-none-any.whl
179 $(call PatchDir,$(PKG_BUILD_DIR)/install-setuptools/usr/lib/python$(PYTHON3_VERSION)/site-packages,./patches-setuptools,)
180 endef
181 endif # CONFIG_PACKAGE_python3-setuptools
182
183 ifdef CONFIG_PACKAGE_python3-pip
184 define Build/Compile/python3-pip
185 $(HOST_PYTHON3_PIP) \
186 --disable-pip-version-check \
187 --cache-dir "$(DL_DIR)/pip-cache" \
188 install \
189 --ignore-installed \
190 --root=$(PKG_BUILD_DIR)/install-pip \
191 --prefix=/usr \
192 $(PKG_BUILD_DIR)/Lib/ensurepip/_bundled/pip-$(PYTHON3_PIP_VERSION)-py2.py3-none-any.whl
193 $(call PatchDir,$(PKG_BUILD_DIR)/install-pip/usr/lib/python$(PYTHON3_VERSION)/site-packages,./patches-pip,)
194 endef
195 endif # CONFIG_PACKAGE_python3-pip
196
197 define Build/Compile
198 $(call Build/Compile/Default)
199 # Use host pip to install python-setuptools
200 $(call Build/Compile/python3-setuptools)
201 $(call Build/Compile/python3-pip)
202 endef
203
204 define Build/InstallDev
205 $(INSTALL_DIR) $(1)/usr/include $(1)/usr/lib $(1)/usr/lib/pkgconfig
206 $(INSTALL_DIR) $(2)/bin
207 $(CP) \
208 $(PKG_INSTALL_DIR)/usr/include/python$(PYTHON3_VERSION) \
209 $(1)/usr/include/
210 $(CP) \
211 $(PKG_INSTALL_DIR)/usr/lib/python$(PYTHON3_VERSION) \
212 $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON3_VERSION).so* \
213 $(1)/usr/lib/
214 grep \
215 '^_PYTHON_HOST_PLATFORM=' \
216 $(PKG_INSTALL_DIR)/usr/lib/python$(PYTHON3_VERSION)/config-$(PYTHON3_VERSION)/Makefile > \
217 $(1)/usr/lib/python$(PYTHON3_VERSION)/config-$(PYTHON3_VERSION)/Makefile-vars
218 $(CP) \
219 $(PKG_INSTALL_DIR)/usr/lib/pkgconfig/python*.pc \
220 $(1)/usr/lib/pkgconfig
221 $(INSTALL_BIN) \
222 $(PKG_INSTALL_DIR)/usr/bin/python$(PYTHON3_VERSION)-config \
223 $(2)/bin/
224 $(SED) \
225 's|^prefix_real=.*$$$$|prefix_real="$(PYTHON3_DIR)"|' \
226 $(2)/bin/python$(PYTHON3_VERSION)-config
227 endef
228
229 PYTHON3_BASE_LIB_FILES:= \
230 /usr/lib/python$(PYTHON3_VERSION)/encodings \
231 /usr/lib/python$(PYTHON3_VERSION)/_collections_abc.py \
232 /usr/lib/python$(PYTHON3_VERSION)/_sitebuiltins.py \
233 /usr/lib/python$(PYTHON3_VERSION)/_sysconfigdata.py \
234 /usr/lib/python$(PYTHON3_VERSION)/_weakrefset.py \
235 /usr/lib/python$(PYTHON3_VERSION)/abc.py \
236 /usr/lib/python$(PYTHON3_VERSION)/codecs.py \
237 /usr/lib/python$(PYTHON3_VERSION)/genericpath.py \
238 /usr/lib/python$(PYTHON3_VERSION)/io.py \
239 /usr/lib/python$(PYTHON3_VERSION)/os.py \
240 /usr/lib/python$(PYTHON3_VERSION)/posixpath.py \
241 /usr/lib/python$(PYTHON3_VERSION)/site.py \
242 /usr/lib/python$(PYTHON3_VERSION)/sysconfig.py \
243 /usr/lib/python$(PYTHON3_VERSION)/stat.py
244
245 PYTHON3_LIB_FILES_DEL+=$(PYTHON3_BASE_LIB_FILES)
246
247 define Py3Package/python3-base/filespec
248 +|/usr/bin/python$(PYTHON3_VERSION)
249 $(subst $(space),$(newline),$(foreach lib_file,$(PYTHON3_BASE_LIB_FILES),+|$(lib_file)))
250 endef
251
252 define Py3Package/python3-light/filespec
253 +|/usr/lib/python$(PYTHON3_VERSION)
254 -|/usr/lib/python$(PYTHON3_VERSION)/distutils/cygwinccompiler.py
255 -|/usr/lib/python$(PYTHON3_VERSION)/distutils/command/wininst*
256 -|/usr/lib/python$(PYTHON3_VERSION)/ensurepip
257 -|/usr/lib/python$(PYTHON3_VERSION)/idlelib
258 -|/usr/lib/python$(PYTHON3_VERSION)/tkinter
259 -|/usr/lib/python$(PYTHON3_VERSION)/turtledemo
260 -|/usr/lib/python$(PYTHON3_VERSION)/lib-dynload/_test*.so
261 -|/usr/lib/python$(PYTHON3_VERSION)/lib-dynload/readline*.so
262 -|/usr/lib/python$(PYTHON3_VERSION)/pdb.doc
263 -|/usr/lib/python$(PYTHON3_VERSION)/test
264 -|/usr/lib/python$(PYTHON3_VERSION)/webbrowser.py
265 -|/usr/lib/python$(PYTHON3_VERSION)/*/test
266 -|/usr/lib/python$(PYTHON3_VERSION)/*/tests
267 -|/usr/lib/python$(PYTHON3_VERSION)/_osx_support.py
268 $(subst $(space),$(newline),$(foreach lib_file,$(PYTHON3_LIB_FILES_DEL),-|$(lib_file)))
269 endef
270
271 define Py3Package/python3-base/install
272 # Adding the lib-dynload folder (even just empty) suppresses 2 warnings when starting Python
273 $(INSTALL_DIR) $(1)/usr/lib/python$(PYTHON3_VERSION)/lib-dynload/
274 $(INSTALL_DIR) $(1)/usr/bin
275 $(LN) python$(PYTHON3_VERSION) $(1)/usr/bin/python3
276 $(LN) python$(PYTHON3_VERSION) $(1)/usr/bin/python
277 $(CP) $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON3_VERSION).so* $(1)/usr/lib/
278 # This depends on being called before filespec is processed
279 $(SED) 's|$(TARGET_AR)|ar|g;s|$(TARGET_CROSS)readelf|readelf|g;s|$(TARGET_CC)|gcc|g;s|$(TARGET_CXX)|g++|g' \
280 $(PKG_INSTALL_DIR)/usr/lib/python$(PYTHON3_VERSION)/_sysconfigdata.py
281 endef
282
283 Py3Package/python3-light/install:=:
284 Py3Package/python3/install:=:
285
286 define Py3Package/python3/filespec
287 -|$(PYTHON3_PKG_DIR)
288 endef
289
290 HOST_LDFLAGS += \
291 -Wl$(comma)-rpath$(comma)$(STAGING_DIR_HOSTPKG)/lib
292
293 ifeq ($(HOST_OS),Linux)
294 HOST_LDFLAGS += \
295 -Wl,--no-as-needed -lrt
296 endif
297
298 ifeq ($(HOST_OS),Darwin)
299 HOST_CONFIGURE_VARS += \
300 ac_cv_header_libintl_h=no
301 endif
302
303 HOST_CONFIGURE_ARGS+= \
304 --enable-optimizations \
305 --with-ensurepip=upgrade \
306 --with-system-expat=$(STAGING_DIR_HOSTPKG) \
307 --without-cxx-main \
308 --without-pymalloc \
309 CONFIG_SITE=
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 endef
315
316 define Host/Compile
317 +$(HOST_MAKE_VARS) $(MAKE) $(HOST_JOBS) -C $(HOST_BUILD_DIR) python
318 +$(HOST_MAKE_VARS) $(MAKE) $(HOST_JOBS) -C $(HOST_BUILD_DIR) sharedmods
319 endef
320
321 define Host/Install
322 $(if $(wildcard $(HOST_PYTHON3_PKG_DIR)/.setuptools_installed_$(PYTHON3_SETUPTOOLS_VERSION)-$(PYTHON3_SETUPTOOLS_PKG_RELEASE)),,
323 rm -rf \
324 $(HOST_PYTHON3_PKG_DIR)/easy_install.py \
325 $(HOST_PYTHON3_PKG_DIR)/pkg_resources \
326 $(HOST_PYTHON3_PKG_DIR)/setuptools \
327 $(HOST_PYTHON3_PKG_DIR)/setuptools-* \
328 $(HOST_PYTHON3_PKG_DIR)/.setuptools-patched* \
329 $(HOST_PYTHON3_PKG_DIR)/.setuptools_installed_*
330 )
331 $(if $(wildcard $(HOST_PYTHON3_PKG_DIR)/.pip_installed_$(PYTHON3_PIP_VERSION)-$(PYTHON3_PIP_PKG_RELEASE)),,
332 rm -rf \
333 $(HOST_PYTHON3_PKG_DIR)/pip \
334 $(HOST_PYTHON3_PKG_DIR)/pip-* \
335 $(HOST_PYTHON3_PKG_DIR)/.pip-patched* \
336 $(HOST_PYTHON3_PKG_DIR)/.pip_installed_*
337 )
338 $(MAKE) -C $(HOST_BUILD_DIR) install
339 $(if $(wildcard $(HOST_PYTHON3_PKG_DIR)/.setuptools_installed_$(PYTHON3_SETUPTOOLS_VERSION)-$(PYTHON3_SETUPTOOLS_PKG_RELEASE)),,
340 $(call HostPatchDir,$(HOST_PYTHON3_PKG_DIR),./patches-setuptools,)
341 touch $(HOST_PYTHON3_PKG_DIR)/.setuptools_installed_$(PYTHON3_SETUPTOOLS_VERSION)-$(PYTHON3_SETUPTOOLS_PKG_RELEASE)
342 )
343 $(if $(wildcard $(HOST_PYTHON3_PKG_DIR)/.pip_installed_$(PYTHON3_PIP_VERSION)-$(PYTHON3_PIP_PKG_RELEASE)),,
344 $(call HostPatchDir,$(HOST_PYTHON3_PKG_DIR),./patches-pip,)
345 touch $(HOST_PYTHON3_PKG_DIR)/.pip_installed_$(PYTHON3_PIP_VERSION)-$(PYTHON3_PIP_PKG_RELEASE)
346 )
347 endef
348
349 $(eval $(call HostBuild))
350
351 $(foreach package, $(PYTHON3_PACKAGES), \
352 $(eval $(call Py3Package,$(package))) \
353 $(eval $(call BuildPackage,$(package))) \
354 $(eval $(call BuildPackage,$(package)-src)) \
355 )
356
357 $(eval $(call Py3Package,python3-base))
358 $(eval $(call Py3Package,python3-light))
359 $(eval $(call Py3Package,python3))
360
361 $(eval $(call BuildPackage,python3-base))
362 $(eval $(call BuildPackage,python3-light))
363 $(eval $(call BuildPackage,python3))
364
365 $(eval $(call BuildPackage,python3-base-src))
366 $(eval $(call BuildPackage,python3-light-src))