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