Merge pull request #4853 from StevenHessing/noddos
[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 PYTHON_VERSION
11 include ./files/python3-version.mk
12
13 PYTHON_VERSION:=$(PYTHON3_VERSION)
14 PYTHON_VERSION_MICRO:=$(PYTHON3_VERSION_MICRO)
15
16 PKG_NAME:=python3
17 # XXX: reset PKG_RELEASE to 1 only if Python's pip & setuptools versions have also bumped;
18 # otherwise, keep bumping PKG_RELEASE
19 PKG_RELEASE:=6
20 PKG_VERSION:=$(PYTHON_VERSION).$(PYTHON_VERSION_MICRO)
21
22 PKG_SOURCE:=Python-$(PKG_VERSION).tar.xz
23 PKG_SOURCE_URL:=https://www.python.org/ftp/python/$(PKG_VERSION)
24 PKG_HASH:=9229773be41ed144370f47f0f626a1579931f5a390f1e8e3853174d52edd64a9
25
26 PKG_LICENSE:=PSF
27 PKG_LICENSE_FILES:=LICENSE Modules/_ctypes/libffi_msvc/LICENSE Modules/_ctypes/darwin/LICENSE Modules/_ctypes/libffi/LICENSE Modules/_ctypes/libffi_osx/LICENSE Tools/pybench/LICENSE
28
29 # This file provides the necsessary host build variables
30 include ./files/python3-host.mk
31
32 # For Py3Package
33 include ./files/python3-package.mk
34
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:=CONFIG_PACKAGE_python3-setuptools CONFIG_PACKAGE_python3-pip
43
44 PKG_BUILD_DEPENDS:=python3/host
45 HOST_BUILD_DEPENDS:=bzip2/host expat/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 $(PYTHON_VERSION) programming language
55 URL:=https://www.python.org/
56 MAINTAINER:=Alexandru Ardelean <ardeleanalex@gmail.com>
57 endef
58
59 define Package/python3/Default/description
60 Python is a dynamic object-oriented programming language that can be used
61 for many kinds of software development. It offers strong support for
62 integration with other languages and tools, comes with extensive standard
63 libraries, and can be learned in a few days. Many Python programmers
64 report substantial productivity gains and feel the language encourages
65 the development of higher quality, more maintainable code.
66 endef
67
68 define Package/python3-base
69 $(call Package/python3/Default)
70 TITLE:=Python $(PYTHON_VERSION) interpreter
71 DEPENDS:=+libpthread +zlib
72 endef
73
74 define Package/python3-base/description
75 This package contains only the interpreter and the bare minimum
76 for the interpreter to start.
77 endef
78
79 define Package/python3-light
80 $(call Package/python3/Default)
81 TITLE:=Python $(PYTHON_VERSION) light installation
82 DEPENDS:=+python3-base +libffi +libbz2
83 endef
84
85 define Package/python3-light/description
86 This package is essentially the python3-base package plus
87 a few of the rarely used (and big) libraries stripped out
88 into separate packages.
89 endef
90
91 PYTHON3_LIB_FILES_DEL:=
92 PYTHON3_PACKAGES:=
93 PYTHON3_SO_SUFFIX:=cpython-$(PYTHON3_VERSION_MAJOR)$(PYTHON3_VERSION_MINOR).so
94 PYTHON3_PACKAGES_DEPENDS:=
95 define Py3BasePackage
96 PYTHON3_PACKAGES+=$(1)
97 ifeq ($(3),)
98 PYTHON3_PACKAGES_DEPENDS+=$(1)
99 endif
100 PYTHON3_LIB_FILES_DEL+=$(2)
101 define Py3Package/$(1)/filespec
102 ifneq ($(2),)
103 $(subst $(space),$(newline),$(foreach lib_file,$(2),+|$(lib_file)))
104 -|/usr/lib/python$(PYTHON_VERSION)/*/test
105 -|/usr/lib/python$(PYTHON_VERSION)/*/tests
106 endif
107 endef
108 endef
109
110 include ./files/python3-package-*.mk
111
112 define Package/python3
113 $(call Package/python3/Default)
114 DEPENDS:=+python3-light $(foreach package,$(PYTHON3_PACKAGES_DEPENDS),+$(package))
115 endef
116
117 define Package/python3/description
118 This package contains the (almost) full Python install.
119 It's python3-light + all other packages.
120 endef
121
122 MAKE_FLAGS+=\
123 CROSS_COMPILE=yes \
124 LD="$(TARGET_CC)" \
125 PGEN=pgen3
126
127 EXTRA_CFLAGS+= \
128 -DNDEBUG -fno-inline
129 EXTRA_LDFLAGS+= \
130 -L$(PKG_BUILD_DIR)
131
132 ENABLE_IPV6:=
133 ifeq ($(CONFIG_IPV6),y)
134 ENABLE_IPV6 += --enable-ipv6
135 endif
136
137 PYTHON_FOR_BUILD:= \
138 _PYTHON_PROJECT_BASE=$(PKG_BUILD_DIR) \
139 _PYTHON_HOST_PLATFORM=linux2 \
140 PYTHONPATH="$(PKG_BUILD_DIR)/Lib:$(PKG_BUILD_DIR)/build/lib.linux2-$(PYTHON_VERSION)" \
141 _PYTHON_SYSCONFIGDATA_NAME=_sysconfigdata \
142 $(HOST_PYTHON3_BIN)
143
144 CONFIGURE_ARGS+= \
145 --sysconfdir=/etc \
146 --enable-shared \
147 --without-cxx-main \
148 --with-threads \
149 --with-system-ffi \
150 --with-ensurepip=no \
151 --without-pymalloc \
152 PYTHON_FOR_BUILD="$(PYTHON_FOR_BUILD)" \
153 $(ENABLE_IPV6) \
154 CONFIG_SITE="$(PKG_BUILD_DIR)/config.site" \
155 OPT="$(TARGET_CFLAGS)"
156
157 define Build/Prepare
158 $(call Build/Prepare/Default)
159 $(CP) ./files/config.site $(PKG_BUILD_DIR)/config.site
160 endef
161
162 ifdef CONFIG_PACKAGE_python3-setuptools
163 define Build/Compile/python3-setuptools
164 $(STAGING_DIR_HOSTPKG)/bin/pip3 install \
165 --ignore-installed \
166 --root=$(PKG_BUILD_DIR)/install-setuptools --prefix=. \
167 $(PKG_BUILD_DIR)/Lib/ensurepip/_bundled/setuptools-*.whl
168 endef
169 endif # CONFIG_PACKAGE_python3-setuptools
170
171 ifdef CONFIG_PACKAGE_python3-pip
172 define Build/Compile/python3-pip
173 $(STAGING_DIR_HOSTPKG)/bin/pip3 install \
174 --ignore-installed \
175 --root=$(PKG_BUILD_DIR)/install-pip --prefix=. \
176 $(PKG_BUILD_DIR)/Lib/ensurepip/_bundled/pip-*.whl
177 endef
178 endif # CONFIG_PACKAGE_python3-pip
179
180 define Build/Compile
181 $(call Build/Compile/Default)
182 # Use host pip to install python-setuptools
183 $(call Build/Compile/python3-setuptools)
184 $(call Build/Compile/python3-pip)
185 endef
186
187 define Build/InstallMkFiles
188 $(INSTALL_DIR) $(STAGING_DIR)/mk/
189 $(INSTALL_DATA) \
190 ./files/python3-package.mk \
191 ./files/python3-host.mk \
192 ./files/python3-version.mk \
193 ./files/python3-package-install.sh \
194 $(STAGING_DIR)/mk/
195 endef
196
197 define Build/InstallDev
198 $(INSTALL_DIR) $(1)/usr/include/ $(1)/usr/lib/
199 $(INSTALL_DIR) $(1)/usr/lib/python$(PYTHON_VERSION)/
200 $(CP) \
201 $(PKG_INSTALL_DIR)/usr/include/python$(PYTHON_VERSION) \
202 $(1)/usr/include/
203 $(CP) \
204 $(HOST_PYTHON3_LIB_DIR) \
205 $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON_VERSION).so* \
206 $(1)/usr/lib/
207 $(CP) \
208 $(PKG_INSTALL_DIR)/usr/lib/python$(PYTHON_VERSION)/config-$(PYTHON_VERSION) \
209 $(1)/usr/lib/python$(PYTHON_VERSION)/
210 $(call Build/InstallMkFiles)
211 endef
212
213 PYTHON3_BASE_LIB_FILES:= \
214 /usr/lib/python$(PYTHON_VERSION)/encodings \
215 /usr/lib/python$(PYTHON_VERSION)/_collections_abc.py \
216 /usr/lib/python$(PYTHON_VERSION)/_sitebuiltins.py \
217 /usr/lib/python$(PYTHON_VERSION)/_sysconfigdata.py \
218 /usr/lib/python$(PYTHON_VERSION)/_weakrefset.py \
219 /usr/lib/python$(PYTHON_VERSION)/abc.py \
220 /usr/lib/python$(PYTHON_VERSION)/codecs.py \
221 /usr/lib/python$(PYTHON_VERSION)/genericpath.py \
222 /usr/lib/python$(PYTHON_VERSION)/io.py \
223 /usr/lib/python$(PYTHON_VERSION)/os.py \
224 /usr/lib/python$(PYTHON_VERSION)/posixpath.py \
225 /usr/lib/python$(PYTHON_VERSION)/site.py \
226 /usr/lib/python$(PYTHON_VERSION)/sysconfig.py \
227 /usr/lib/python$(PYTHON_VERSION)/stat.py
228
229 PYTHON3_LIB_FILES_DEL+=$(PYTHON3_BASE_LIB_FILES)
230
231 define Py3Package/python3-base/filespec
232 +|/usr/bin/python$(PYTHON_VERSION)
233 $(subst $(space),$(newline),$(foreach lib_file,$(PYTHON3_BASE_LIB_FILES),+|$(lib_file)))
234 endef
235
236 define Py3Package/python3-light/filespec
237 +|/usr/lib/python$(PYTHON_VERSION)
238 -|/usr/lib/python$(PYTHON_VERSION)/distutils/cygwinccompiler.py
239 -|/usr/lib/python$(PYTHON_VERSION)/distutils/command/wininst*
240 -|/usr/lib/python$(PYTHON_VERSION)/ensurepip
241 -|/usr/lib/python$(PYTHON_VERSION)/idlelib
242 -|/usr/lib/python$(PYTHON_VERSION)/tkinter
243 -|/usr/lib/python$(PYTHON_VERSION)/turtledemo
244 -|/usr/lib/python$(PYTHON_VERSION)/lib-dynload/_test*.so
245 -|/usr/lib/python$(PYTHON_VERSION)/lib-dynload/readline*.so
246 -|/usr/lib/python$(PYTHON_VERSION)/pdb.doc
247 -|/usr/lib/python$(PYTHON_VERSION)/test
248 -|/usr/lib/python$(PYTHON_VERSION)/webbrowser.py
249 -|/usr/lib/python$(PYTHON_VERSION)/*/test
250 -|/usr/lib/python$(PYTHON_VERSION)/*/tests
251 -|/usr/lib/python$(PYTHON_VERSION)/_osx_support.py
252 $(subst $(space),$(newline),$(foreach lib_file,$(PYTHON3_LIB_FILES_DEL),-|$(lib_file)))
253 endef
254
255 define Py3Package/python3-base/install
256 # Adding the lib-dynload folder (even just empty) suppresses 2 warnings when starting Python
257 $(INSTALL_DIR) $(1)/usr/lib/python$(PYTHON_VERSION)/lib-dynload/
258 $(INSTALL_DIR) $(1)/usr/bin
259 $(LN) python$(PYTHON_VERSION) $(1)/usr/bin/python3
260 $(CP) $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON_VERSION).so* $(1)/usr/lib/
261 endef
262
263 define Py3Package/python3/filespec
264 -|$(PYTHON3_PKG_DIR)
265 endef
266
267 HOST_LDFLAGS += \
268 -Wl,--no-as-needed -lrt \
269 $$$$(pkg-config --static --libs libcrypto libssl)
270
271 HOST_CONFIGURE_ARGS+= \
272 --without-cxx-main \
273 --without-pymalloc \
274 --with-threads \
275 --prefix=$(HOST_PYTHON3_DIR) \
276 --exec-prefix=$(HOST_PYTHON3_DIR) \
277 --with-system-expat=$(STAGING_DIR_HOSTPKG) \
278 --with-system-ffi=no \
279 --with-ensurepip=install \
280 CONFIG_SITE=
281
282 define Host/Compile
283 +$(HOST_MAKE_VARS) $(MAKE) $(HOST_JOBS) -C $(HOST_BUILD_DIR) python Parser/pgen
284 +$(HOST_MAKE_VARS) $(MAKE) $(HOST_JOBS) -C $(HOST_BUILD_DIR) sharedmods
285 endef
286
287 define Host/Install
288 $(call Build/InstallMkFiles)
289 $(MAKE) -C $(HOST_BUILD_DIR) install
290 $(INSTALL_DIR) $(HOST_PYTHON3_DIR)/bin/
291 $(INSTALL_BIN) $(HOST_BUILD_DIR)/Parser/pgen $(HOST_PYTHON3_DIR)/bin/pgen3
292 endef
293
294 $(eval $(call HostBuild))
295
296 $(foreach package, $(PYTHON3_PACKAGES), \
297 $(eval $(call Py3Package,$(package))) \
298 $(eval $(call BuildPackage,$(package))) \
299 $(eval $(call BuildPackage,$(package)-src)) \
300 )
301
302 $(eval $(call Py3Package,python3-base))
303 $(eval $(call Py3Package,python3-light))
304 $(eval $(call Py3Package,python3))
305
306 $(eval $(call BuildPackage,python3-base))
307 $(eval $(call BuildPackage,python3-light))
308 $(eval $(call BuildPackage,python3))
309
310 $(eval $(call BuildPackage,python3-base-src))
311 $(eval $(call BuildPackage,python3-light-src))
312 $(eval $(call BuildPackage,python3-src))