03e6328e97c9170bf70928e5b80114724141a113
[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 ../python3-version.mk
12
13 PYTHON_VERSION:=$(PYTHON3_VERSION)
14 PYTHON_VERSION_MICRO:=$(PYTHON3_VERSION_MICRO)
15
16 PKG_NAME:=python3
17 PKG_RELEASE:=2
18 PKG_VERSION:=$(PYTHON_VERSION).$(PYTHON_VERSION_MICRO)
19
20 PKG_SOURCE:=Python-$(PKG_VERSION).tar.xz
21 PKG_SOURCE_URL:=https://www.python.org/ftp/python/$(PKG_VERSION)
22 PKG_HASH:=70953a9b5d6891d92e65d184c3512126a15814bee15e1eff2ddcce04334e9a99
23
24 PKG_LICENSE:=PSF
25 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
26
27 # This file provides the necsessary host build variables
28 include ../python3-host.mk
29
30 # For Py3Package
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-setuptools CONFIG_PACKAGE_python3-pip \
43 CONFIG_PYTHON3_BLUETOOTH_SUPPORT
44
45 PKG_BUILD_DEPENDS:=python3/host
46 HOST_BUILD_DEPENDS:=bzip2/host expat/host libffi/host
47
48 include $(INCLUDE_DIR)/host-build.mk
49 include $(INCLUDE_DIR)/package.mk
50
51 define Package/python3/Default
52 SUBMENU:=Python
53 SECTION:=lang
54 CATEGORY:=Languages
55 TITLE:=Python $(PYTHON_VERSION) programming language
56 URL:=https://www.python.org/
57 MAINTAINER:=Alexandru Ardelean <ardeleanalex@gmail.com>
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 $(PYTHON_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 $(PYTHON_VERSION) light installation
83 DEPENDS:=+python3-base +libffi +libbz2 +PYTHON3_BLUETOOTH_SUPPORT:bluez-libs
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$(PYTHON_VERSION)/*/test
110 -|/usr/lib/python$(PYTHON_VERSION)/*/tests
111 endif
112 endef
113 endef
114
115 include ./files/python3-package-*.mk
116
117 define Package/python3
118 $(call Package/python3/Default)
119 DEPENDS:=+python3-light $(foreach package,$(PYTHON3_PACKAGES_DEPENDS),+$(package))
120 endef
121
122 define Package/python3/description
123 This package contains the (almost) full Python install.
124 It's python3-light + all other packages.
125 endef
126
127 MAKE_FLAGS+=\
128 CROSS_COMPILE=yes \
129 LD="$(TARGET_CC)" \
130 PGEN=pgen3
131
132 EXTRA_CFLAGS+= \
133 -DNDEBUG -fno-inline
134 EXTRA_LDFLAGS+= \
135 -L$(PKG_BUILD_DIR)
136
137 ENABLE_IPV6:=
138 ifeq ($(CONFIG_IPV6),y)
139 ENABLE_IPV6 += --enable-ipv6
140 endif
141
142 PYTHON_FOR_BUILD:= \
143 _PYTHON_PROJECT_BASE=$(PKG_BUILD_DIR) \
144 _PYTHON_HOST_PLATFORM=linux2 \
145 PYTHONPATH="$(PKG_BUILD_DIR)/Lib:$(PKG_BUILD_DIR)/build/lib.linux2-$(PYTHON_VERSION)" \
146 _PYTHON_SYSCONFIGDATA_NAME=_sysconfigdata \
147 $(HOST_PYTHON3_BIN)
148
149 DISABLE_BLUETOOTH:= \
150 ac_cv_header_bluetooth_bluetooth_h=no \
151 ac_cv_header_bluetooth_h=no
152
153 CONFIGURE_ARGS+= \
154 --sysconfdir=/etc \
155 --enable-shared \
156 --without-cxx-main \
157 --with-threads \
158 --with-system-ffi \
159 --with-ensurepip=no \
160 --without-pymalloc \
161 $(if $(CONFIG_PYTHON3_BLUETOOTH_SUPPORT),,$(DISABLE_BLUETOOTH)) \
162 PYTHON_FOR_BUILD="$(PYTHON_FOR_BUILD)" \
163 $(ENABLE_IPV6) \
164 CONFIG_SITE="$(PKG_BUILD_DIR)/config.site" \
165 OPT="$(TARGET_CFLAGS)"
166
167 define Build/Prepare
168 $(call Build/Prepare/Default)
169 $(CP) ./files/config.site $(PKG_BUILD_DIR)/config.site
170 endef
171
172 ifdef CONFIG_PACKAGE_python3-setuptools
173 define Build/Compile/python3-setuptools
174 $(STAGING_DIR_HOSTPKG)/bin/pip3 install \
175 --ignore-installed \
176 --root=$(PKG_BUILD_DIR)/install-setuptools --prefix=. \
177 $(PKG_BUILD_DIR)/Lib/ensurepip/_bundled/setuptools-*.whl
178 endef
179 endif # CONFIG_PACKAGE_python3-setuptools
180
181 ifdef CONFIG_PACKAGE_python3-pip
182 define Build/Compile/python3-pip
183 $(STAGING_DIR_HOSTPKG)/bin/pip3 install \
184 --ignore-installed \
185 --root=$(PKG_BUILD_DIR)/install-pip --prefix=. \
186 $(PKG_BUILD_DIR)/Lib/ensurepip/_bundled/pip-*.whl
187 endef
188 endif # CONFIG_PACKAGE_python3-pip
189
190 define Build/Compile
191 $(call Build/Compile/Default)
192 # Use host pip to install python-setuptools
193 $(call Build/Compile/python3-setuptools)
194 $(call Build/Compile/python3-pip)
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 endef
211
212 PYTHON3_BASE_LIB_FILES:= \
213 /usr/lib/python$(PYTHON_VERSION)/encodings \
214 /usr/lib/python$(PYTHON_VERSION)/_collections_abc.py \
215 /usr/lib/python$(PYTHON_VERSION)/_sitebuiltins.py \
216 /usr/lib/python$(PYTHON_VERSION)/_sysconfigdata.py \
217 /usr/lib/python$(PYTHON_VERSION)/_weakrefset.py \
218 /usr/lib/python$(PYTHON_VERSION)/abc.py \
219 /usr/lib/python$(PYTHON_VERSION)/codecs.py \
220 /usr/lib/python$(PYTHON_VERSION)/genericpath.py \
221 /usr/lib/python$(PYTHON_VERSION)/io.py \
222 /usr/lib/python$(PYTHON_VERSION)/os.py \
223 /usr/lib/python$(PYTHON_VERSION)/posixpath.py \
224 /usr/lib/python$(PYTHON_VERSION)/site.py \
225 /usr/lib/python$(PYTHON_VERSION)/sysconfig.py \
226 /usr/lib/python$(PYTHON_VERSION)/stat.py
227
228 PYTHON3_LIB_FILES_DEL+=$(PYTHON3_BASE_LIB_FILES)
229
230 define Py3Package/python3-base/filespec
231 +|/usr/bin/python$(PYTHON_VERSION)
232 $(subst $(space),$(newline),$(foreach lib_file,$(PYTHON3_BASE_LIB_FILES),+|$(lib_file)))
233 endef
234
235 define Py3Package/python3-light/filespec
236 +|/usr/lib/python$(PYTHON_VERSION)
237 -|/usr/lib/python$(PYTHON_VERSION)/distutils/cygwinccompiler.py
238 -|/usr/lib/python$(PYTHON_VERSION)/distutils/command/wininst*
239 -|/usr/lib/python$(PYTHON_VERSION)/ensurepip
240 -|/usr/lib/python$(PYTHON_VERSION)/idlelib
241 -|/usr/lib/python$(PYTHON_VERSION)/tkinter
242 -|/usr/lib/python$(PYTHON_VERSION)/turtledemo
243 -|/usr/lib/python$(PYTHON_VERSION)/lib-dynload/_test*.so
244 -|/usr/lib/python$(PYTHON_VERSION)/lib-dynload/readline*.so
245 -|/usr/lib/python$(PYTHON_VERSION)/pdb.doc
246 -|/usr/lib/python$(PYTHON_VERSION)/test
247 -|/usr/lib/python$(PYTHON_VERSION)/webbrowser.py
248 -|/usr/lib/python$(PYTHON_VERSION)/*/test
249 -|/usr/lib/python$(PYTHON_VERSION)/*/tests
250 -|/usr/lib/python$(PYTHON_VERSION)/_osx_support.py
251 $(subst $(space),$(newline),$(foreach lib_file,$(PYTHON3_LIB_FILES_DEL),-|$(lib_file)))
252 endef
253
254 define Py3Package/python3-base/install
255 # Adding the lib-dynload folder (even just empty) suppresses 2 warnings when starting Python
256 $(INSTALL_DIR) $(1)/usr/lib/python$(PYTHON_VERSION)/lib-dynload/
257 $(INSTALL_DIR) $(1)/usr/bin
258 $(LN) python$(PYTHON_VERSION) $(1)/usr/bin/python3
259 $(CP) $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON_VERSION).so* $(1)/usr/lib/
260 endef
261
262 define Py3Package/python3/filespec
263 -|$(PYTHON3_PKG_DIR)
264 endef
265
266 HOST_LDFLAGS += \
267 $$$$(pkg-config --static --libs libcrypto libssl) -Wl$(comma)-rpath=$(STAGING_DIR_HOSTPKG)/lib
268
269 ifeq ($(HOST_OS),Linux)
270 HOST_LDFLAGS += \
271 -Wl,--no-as-needed -lrt
272 endif
273
274 HOST_CONFIGURE_ARGS+= \
275 --without-cxx-main \
276 --without-pymalloc \
277 --with-threads \
278 --prefix=$(HOST_PYTHON3_DIR) \
279 --exec-prefix=$(HOST_PYTHON3_DIR) \
280 --with-system-expat=$(STAGING_DIR_HOSTPKG) \
281 --with-ensurepip=install \
282 CONFIG_SITE=
283
284 define Host/Compile
285 +$(HOST_MAKE_VARS) $(MAKE) $(HOST_JOBS) -C $(HOST_BUILD_DIR) python Parser/pgen
286 +$(HOST_MAKE_VARS) $(MAKE) $(HOST_JOBS) -C $(HOST_BUILD_DIR) sharedmods
287 endef
288
289 define Host/Install
290 $(MAKE) -C $(HOST_BUILD_DIR) install
291 $(INSTALL_DIR) $(HOST_PYTHON3_DIR)/bin/
292 $(INSTALL_BIN) $(HOST_BUILD_DIR)/Parser/pgen $(HOST_PYTHON3_DIR)/bin/pgen3
293 endef
294
295 $(eval $(call HostBuild))
296
297 $(foreach package, $(PYTHON3_PACKAGES), \
298 $(eval $(call Py3Package,$(package))) \
299 $(eval $(call BuildPackage,$(package))) \
300 $(eval $(call BuildPackage,$(package)-src)) \
301 )
302
303 $(eval $(call Py3Package,python3-base))
304 $(eval $(call Py3Package,python3-light))
305 $(eval $(call Py3Package,python3))
306
307 $(eval $(call BuildPackage,python3-base))
308 $(eval $(call BuildPackage,python3-light))
309 $(eval $(call BuildPackage,python3))
310
311 $(eval $(call BuildPackage,python3-base-src))
312 $(eval $(call BuildPackage,python3-light-src))