Merge pull request #4465 from dibdot/adblock
[feed/packages.git] / lang / python / python / 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 # For PYTHON_VERSION
11 include ./files/python-version.mk
12
13 PKG_NAME:=python
14 PKG_VERSION:=$(PYTHON_VERSION).$(PYTHON_VERSION_MICRO)
15 PKG_RELEASE:=5
16
17 PKG_SOURCE:=Python-$(PKG_VERSION).tar.xz
18 PKG_SOURCE_URL:=https://www.python.org/ftp/python/$(PKG_VERSION)
19 PKG_MD5SUM:=53b43534153bb2a0363f08bae8b9d990
20 PKG_HASH:=35d543986882f78261f97787fd3e06274bfa6df29fac9b4a94f73930ff98f731
21
22 PKG_LICENSE:=PSF
23 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
24
25 # This file provides the necsessary host build variables
26 include ./files/python-host.mk
27
28 # For PyPackage
29 include ./files/python-package.mk
30
31 PKG_INSTALL:=1
32 PKG_BUILD_PARALLEL:=1
33 HOST_BUILD_PARALLEL:=1
34
35 PKG_BUILD_DIR:=$(BUILD_DIR)/Python-$(PKG_VERSION)
36 HOST_BUILD_DIR:=$(BUILD_DIR_HOST)/Python-$(PKG_VERSION)
37
38 PKG_BUILD_DEPENDS:=python/host
39 HOST_BUILD_DEPENDS:=bzip2/host expat/host
40
41 include $(INCLUDE_DIR)/host-build.mk
42 include $(INCLUDE_DIR)/package.mk
43
44 define Package/python/Default
45 SUBMENU:=Python
46 SECTION:=lang
47 CATEGORY:=Languages
48 TITLE:=Python $(PYTHON_VERSION) programming language
49 URL:=https://www.python.org/
50 MAINTAINER:=Alexandru Ardelean <ardeleanalex@gmail.com>
51 endef
52
53 define Package/python/Default/description
54 Python is a dynamic object-oriented programming language that can be used
55 for many kinds of software development. It offers strong support for
56 integration with other languages and tools, comes with extensive standard
57 libraries, and can be learned in a few days. Many Python programmers
58 report substantial productivity gains and feel the language encourages
59 the development of higher quality, more maintainable code.
60 endef
61
62 define Package/python-pip-conf
63 $(call Package/python/Default)
64 TITLE:=Configuration file for pip/pip3
65 URL:=https://pip.pypa.io
66 endef
67
68 define Package/python-pip-conf/description
69 Configuration file for pip/pip3
70 endef
71
72 define Package/python-base
73 $(call Package/python/Default)
74 TITLE:=Python $(PYTHON_VERSION) interpreter
75 DEPENDS:=+libpthread +zlib
76 endef
77
78 define Package/python-base/description
79 This package contains only the interpreter and the bare minimum
80 for the interpreter to start.
81 endef
82
83 define Package/python-light
84 $(call Package/python/Default)
85 TITLE:=Python $(PYTHON_VERSION) light installation
86 DEPENDS:=+python-base +libffi +libbz2
87 endef
88
89 define Package/python-light/description
90 This package is essentially the python-base package plus
91 a few of the rarely used (and big) libraries stripped out
92 into separate packages.
93 endef
94
95 PYTHON_LIB_FILES_DEL:=
96 PYTHON_PACKAGES:=
97 PYTHON_PACKAGES_DEPENDS:=
98 define PyBasePackage
99 PYTHON_PACKAGES+=$(1)
100 ifeq ($(3),)
101 PYTHON_PACKAGES_DEPENDS+=$(1)
102 endif
103 PYTHON_LIB_FILES_DEL+=$(2)
104 define PyPackage/$(1)/filespec
105 ifneq ($(2),)
106 $(subst $(space),$(newline),$(foreach lib_file,$(2),+|$(lib_file)))
107 -|/usr/lib/python$(PYTHON_VERSION)/*/test
108 -|/usr/lib/python$(PYTHON_VERSION)/*/tests
109 endif
110 endef
111 endef
112
113 include ./files/python-package-*.mk
114
115 define Package/python
116 $(call Package/python/Default)
117 DEPENDS:=+python-light $(foreach package,$(PYTHON_PACKAGES_DEPENDS),+$(package))
118 endef
119
120 define Package/python/description
121 This package contains the (almost) full Python install.
122 It's python-light + all other packages.
123 endef
124
125 MAKE_FLAGS+=\
126 CROSS_COMPILE=yes \
127 LD="$(TARGET_CC)" \
128 PGEN=pgen2
129
130 EXTRA_CFLAGS+= \
131 -DNDEBUG -fno-inline
132 EXTRA_LDFLAGS+= \
133 -L$(PKG_BUILD_DIR)
134
135 ENABLE_IPV6:=
136 ifeq ($(CONFIG_IPV6),y)
137 ENABLE_IPV6 += --enable-ipv6
138 endif
139
140 PYTHON_FOR_BUILD:= \
141 _PYTHON_PROJECT_BASE=$(PKG_BUILD_DIR) \
142 _PYTHON_HOST_PLATFORM=linux2 \
143 PYTHONPATH="$(PKG_BUILD_DIR)/Lib:$(PKG_BUILD_DIR)/build/lib.linux2-$(PYTHON_VERSION)" \
144 _PYTHON_SYSCONFIGDATA_NAME=_sysconfigdata \
145 $(HOST_PYTHON_BIN)
146
147 CONFIGURE_ARGS+= \
148 --sysconfdir=/etc \
149 --enable-shared \
150 --without-cxx-main \
151 --with-threads \
152 --with-system-ffi \
153 --with-ensurepip=no \
154 --without-pymalloc \
155 PYTHON_FOR_BUILD="$(PYTHON_FOR_BUILD)" \
156 $(ENABLE_IPV6) \
157 CONFIG_SITE="$(PKG_BUILD_DIR)/config.site" \
158 OPT="$(TARGET_CFLAGS)"
159
160 define Build/Prepare
161 $(call Build/Prepare/Default)
162 $(CP) ./files/config.site $(PKG_BUILD_DIR)/config.site
163 endef
164
165 ifdef CONFIG_PACKAGE_python-setuptools
166 define Build/Compile/python-setuptools
167 $(STAGING_DIR_HOSTPKG)/bin/pip install \
168 --ignore-installed \
169 --root=$(PKG_BUILD_DIR)/install-setuptools --prefix=. \
170 $(PKG_BUILD_DIR)/Lib/ensurepip/_bundled/setuptools-*.whl
171 endef
172 endif # CONFIG_PACKAGE_python-setuptools
173
174 ifdef CONFIG_PACKAGE_python-pip
175 define Build/Compile/python-pip
176 $(STAGING_DIR_HOSTPKG)/bin/pip install \
177 --ignore-installed \
178 --root=$(PKG_BUILD_DIR)/install-pip --prefix=. \
179 $(PKG_BUILD_DIR)/Lib/ensurepip/_bundled/pip-*.whl
180 endef
181 endif # CONFIG_PACKAGE_python-pip
182
183 define Build/Compile
184 $(call Build/Compile/Default)
185 # Use host pip to install python-setuptools
186 $(call Build/Compile/python-setuptools)
187 $(call Build/Compile/python-pip)
188 endef
189
190 define Build/InstallDev
191 $(INSTALL_DIR) $(STAGING_DIR)/mk/
192 $(INSTALL_DIR) $(1)/usr/include/ $(1)/usr/lib/ $(1)/usr/lib/pkgconfig
193 $(INSTALL_DIR) $(1)/usr/lib/python$(PYTHON_VERSION)/
194 $(INSTALL_DATA) \
195 ./files/python-package.mk \
196 ./files/python-host.mk \
197 ./files/python-version.mk \
198 ./files/python-package-install.sh \
199 $(STAGING_DIR)/mk/
200 $(CP) \
201 $(PKG_INSTALL_DIR)/usr/include/python$(PYTHON_VERSION) \
202 $(1)/usr/include/
203 $(CP) \
204 $(HOST_PYTHON_LIB_DIR) \
205 $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON_VERSION).so* \
206 $(1)/usr/lib/
207 $(CP) \
208 $(HOST_PYTHON_DIR)/lib/pkgconfig/python.pc \
209 $(HOST_PYTHON_DIR)/lib/pkgconfig/python2.pc \
210 $(HOST_PYTHON_DIR)/lib/pkgconfig/python-$(PYTHON_VERSION).pc \
211 $(1)/usr/lib/pkgconfig
212 $(CP) \
213 $(PKG_INSTALL_DIR)/usr/lib/python$(PYTHON_VERSION)/config \
214 $(1)/usr/lib/python$(PYTHON_VERSION)/
215 endef
216
217 PYTHON_BASE_LIB_FILES:= \
218 /usr/lib/python$(PYTHON_VERSION)/_abcoll.py \
219 /usr/lib/python$(PYTHON_VERSION)/_sysconfigdata.py \
220 /usr/lib/python$(PYTHON_VERSION)/_weakrefset.py \
221 /usr/lib/python$(PYTHON_VERSION)/abc.py \
222 /usr/lib/python$(PYTHON_VERSION)/copy_reg.py \
223 /usr/lib/python$(PYTHON_VERSION)/genericpath.py \
224 /usr/lib/python$(PYTHON_VERSION)/linecache.py \
225 /usr/lib/python$(PYTHON_VERSION)/posixpath.py \
226 /usr/lib/python$(PYTHON_VERSION)/os.py \
227 /usr/lib/python$(PYTHON_VERSION)/re.py \
228 /usr/lib/python$(PYTHON_VERSION)/site.py \
229 /usr/lib/python$(PYTHON_VERSION)/sre_compile.py \
230 /usr/lib/python$(PYTHON_VERSION)/sre_constants.py \
231 /usr/lib/python$(PYTHON_VERSION)/sre_parse.py \
232 /usr/lib/python$(PYTHON_VERSION)/sysconfig.py \
233 /usr/lib/python$(PYTHON_VERSION)/stat.py \
234 /usr/lib/python$(PYTHON_VERSION)/traceback.py \
235 /usr/lib/python$(PYTHON_VERSION)/types.py \
236 /usr/lib/python$(PYTHON_VERSION)/UserDict.py \
237 /usr/lib/python$(PYTHON_VERSION)/warnings.py
238
239 PYTHON_LIB_FILES_DEL+=$(PYTHON_BASE_LIB_FILES)
240
241 define PyPackage/python-base/filespec
242 +|/usr/bin/python$(PYTHON_VERSION)
243 $(subst $(space),$(newline),$(foreach lib_file,$(PYTHON_BASE_LIB_FILES),+|$(lib_file)))
244 endef
245
246 define PyPackage/python-light/filespec
247 +|/usr/lib/python$(PYTHON_VERSION)
248 -|/usr/lib/python$(PYTHON_VERSION)/distutils/cygwinccompiler.py
249 -|/usr/lib/python$(PYTHON_VERSION)/distutils/command/wininst*
250 -|/usr/lib/python$(PYTHON_VERSION)/ensurepip
251 -|/usr/lib/python$(PYTHON_VERSION)/idlelib
252 -|/usr/lib/python$(PYTHON_VERSION)/lib-tk
253 -|/usr/lib/python$(PYTHON_VERSION)/lib-dynload/_testcapi.so
254 -|/usr/lib/python$(PYTHON_VERSION)/pdb.doc
255 -|/usr/lib/python$(PYTHON_VERSION)/test
256 -|/usr/lib/python$(PYTHON_VERSION)/webbrowser.py
257 -|/usr/lib/python$(PYTHON_VERSION)/*/test
258 -|/usr/lib/python$(PYTHON_VERSION)/*/tests
259 -|/usr/lib/python$(PYTHON_VERSION)/lib-dynload/readline.so
260 $(subst $(space),$(newline),$(foreach lib_file,$(PYTHON_LIB_FILES_DEL),-|$(lib_file)))
261 endef
262
263 define PyPackage/python-base/install
264 $(INSTALL_DIR) $(1)/usr/bin $(1)/usr/lib
265 $(LN) python$(PYTHON_VERSION) $(1)/usr/bin/python
266 $(LN) python$(PYTHON_VERSION) $(1)/usr/bin/python2
267 $(CP) $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON_VERSION).so* $(1)/usr/lib/
268 endef
269
270 define PyPackage/python/filespec
271 -|$(PYTHON_PKG_DIR)
272 endef
273
274 define Package/python-pip-conf/install
275 $(INSTALL_DIR) $(1)/etc
276 $(CP) ./files/pip.conf $(1)/etc
277 endef
278
279 HOST_LDFLAGS += \
280 $$$$(pkg-config --static --libs libcrypto libssl)
281
282 HOST_CONFIGURE_ARGS+= \
283 --without-cxx-main \
284 --without-pymalloc \
285 --with-threads \
286 --prefix=$(HOST_PYTHON_DIR) \
287 --exec-prefix=$(HOST_PYTHON_DIR) \
288 --with-system-expat=$(STAGING_DIR_HOSTPKG) \
289 --with-system-ffi=no \
290 --with-ensurepip=install \
291 CONFIG_SITE=
292
293 define Host/Install
294 $(MAKE) -C $(HOST_BUILD_DIR) install
295 $(INSTALL_DIR) $(HOST_PYTHON_DIR)/bin/
296 $(INSTALL_BIN) $(HOST_BUILD_DIR)/Parser/pgen $(HOST_PYTHON_DIR)/bin/pgen2
297 endef
298
299 $(eval $(call HostBuild))
300
301 $(foreach package, $(PYTHON_PACKAGES), \
302 $(eval $(call PyPackage,$(package))) \
303 $(eval $(call BuildPackage,$(package))) \
304 $(eval $(call BuildPackage,$(package)-src)) \
305 )
306
307 $(eval $(call PyPackage,python-base))
308 $(eval $(call PyPackage,python-light))
309 $(eval $(call PyPackage,python))
310
311 $(eval $(call BuildPackage,python-pip-conf))
312
313 $(eval $(call BuildPackage,python-base))
314 $(eval $(call BuildPackage,python-light))
315 $(eval $(call BuildPackage,python))
316
317 $(eval $(call BuildPackage,python-base-src))
318 $(eval $(call BuildPackage,python-light-src))
319 $(eval $(call BuildPackage,python-src))