python3: sync makefiles with python package
[feed/packages.git] / lang / 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 PKG_RELEASE:=1
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_MD5SUM:=82b143ebbf4514d7e05876bed7a6b1f5
23 PKG_HASH:=b0c5f904f685e32d9232f7bdcbece9819a892929063b6e385414ad2dd6a23622
24
25 PKG_LICENSE:=PSF
26 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
27
28 # This file provides the necsessary host build variables
29 include ./files/python3-host.mk
30
31 # For Py3Package
32 include ./files/python3-package.mk
33
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_BUILD_DEPENDS:=python3/host
42 HOST_BUILD_DEPENDS:=bzip2/host expat/host libffi/host
43
44 include $(INCLUDE_DIR)/host-build.mk
45 include $(INCLUDE_DIR)/package.mk
46
47 define Package/python3/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/python3/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/python3-base
66 $(call Package/python3/Default)
67 TITLE:=Python $(PYTHON_VERSION) interpreter
68 DEPENDS:=+libpthread +zlib
69 endef
70
71 define Package/python3-base/description
72 This package contains only the interpreter and the bare minimum
73 for the interpreter to start.
74 endef
75
76 define Package/python3-light
77 $(call Package/python3/Default)
78 TITLE:=Python $(PYTHON_VERSION) light installation
79 DEPENDS:=+python3-base +libffi +libbz2
80 endef
81
82 define Package/python3-light/description
83 This package is essentially the python3-base package plus
84 a few of the rarely used (and big) libraries stripped out
85 into separate packages.
86 endef
87
88 PYTHON3_LIB_FILES_DEL:=
89 PYTHON3_PACKAGES:=
90 PYTHON3_SO_SUFFIX:=cpython-$(PYTHON3_VERSION_MAJOR)$(PYTHON3_VERSION_MINOR).so
91 PYTHON3_PACKAGES_DEPENDS:=
92 define Py3BasePackage
93 PYTHON3_PACKAGES+=$(1)
94 ifeq ($(3),)
95 PYTHON3_PACKAGES_DEPENDS+=$(1)
96 endif
97 PYTHON3_LIB_FILES_DEL+=$(2)
98 define Py3Package/$(1)/filespec
99 $(subst $(space),$(newline),$(foreach lib_file,$(2),+|$(lib_file)))
100 endef
101 endef
102
103 include ./files/python3-package-*.mk
104
105 define Package/python3
106 $(call Package/python3/Default)
107 DEPENDS:=+python3-light $(foreach package,$(PYTHON3_PACKAGES_DEPENDS),+$(package))
108 endef
109
110 define Package/python3/description
111 This package contains the (almost) full Python install.
112 It's python3-light + all other packages.
113 endef
114
115 MAKE_FLAGS+=\
116 CROSS_COMPILE=yes \
117 LD="$(TARGET_CC)" \
118 PGEN=pgen3
119
120 ifeq ($(ARCH),i386)
121 MAKE_FLAGS+=PYTHON_DECIMAL_WITH_MACHINE=ansi32
122 endif
123
124 EXTRA_CFLAGS+= \
125 -DNDEBUG -fno-inline
126 EXTRA_LDFLAGS+= \
127 -L$(PKG_BUILD_DIR)
128
129 ENABLE_IPV6:=
130 ifeq ($(CONFIG_IPV6),y)
131 ENABLE_IPV6 += --enable-ipv6
132 endif
133
134 PYTHON_FOR_BUILD:= \
135 _PYTHON_PROJECT_BASE=$(PKG_BUILD_DIR) \
136 _PYTHON_HOST_PLATFORM=linux2 \
137 PYTHONPATH="$(PKG_BUILD_DIR)/Lib:$(PKG_BUILD_DIR)/build/lib.linux2-$(PYTHON_VERSION)" \
138 _PYTHON_SYSCONFIGDATA_NAME=_sysconfigdata \
139 $(HOST_PYTHON3_BIN)
140
141 CONFIGURE_ARGS+= \
142 --sysconfdir=/etc \
143 --enable-shared \
144 --without-cxx-main \
145 --with-threads \
146 --with-system-ffi \
147 --without-pymalloc \
148 --with-ensurepip=no \
149 PYTHON_FOR_BUILD="$(PYTHON_FOR_BUILD)" \
150 $(ENABLE_IPV6) \
151 CONFIG_SITE="$(PKG_BUILD_DIR)/config.site" \
152 OPT="$(TARGET_CFLAGS)"
153
154 define Build/Prepare
155 $(call Build/Prepare/Default)
156 $(CP) ./files/config.site $(PKG_BUILD_DIR)/config.site
157 endef
158
159 define Build/InstallDev
160 $(INSTALL_DIR) $(STAGING_DIR)/mk/
161 $(INSTALL_DIR) $(1)/usr/include/ $(1)/usr/lib/
162 $(INSTALL_DIR) $(1)/usr/lib/python$(PYTHON_VERSION)/
163 $(INSTALL_DATA) \
164 ./files/python3-package.mk \
165 ./files/python3-host.mk \
166 ./files/python3-version.mk \
167 $(STAGING_DIR)/mk/
168 $(CP) \
169 $(PKG_INSTALL_DIR)/usr/include/python$(PYTHON_VERSION) \
170 $(1)/usr/include/
171 $(CP) \
172 $(HOST_PYTHON3_LIB_DIR) \
173 $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON_VERSION).so* \
174 $(1)/usr/lib/
175 $(CP) \
176 $(PKG_INSTALL_DIR)/usr/lib/python$(PYTHON_VERSION)/config-$(PYTHON_VERSION) \
177 $(1)/usr/lib/python$(PYTHON_VERSION)/
178 endef
179
180 PYTHON3_BASE_LIB_FILES:= \
181 /usr/lib/python$(PYTHON_VERSION)/encodings \
182 /usr/lib/python$(PYTHON_VERSION)/_collections_abc.py \
183 /usr/lib/python$(PYTHON_VERSION)/_sitebuiltins.py \
184 /usr/lib/python$(PYTHON_VERSION)/_sysconfigdata.py \
185 /usr/lib/python$(PYTHON_VERSION)/_weakrefset.py \
186 /usr/lib/python$(PYTHON_VERSION)/abc.py \
187 /usr/lib/python$(PYTHON_VERSION)/codecs.py \
188 /usr/lib/python$(PYTHON_VERSION)/genericpath.py \
189 /usr/lib/python$(PYTHON_VERSION)/io.py \
190 /usr/lib/python$(PYTHON_VERSION)/os.py \
191 /usr/lib/python$(PYTHON_VERSION)/posixpath.py \
192 /usr/lib/python$(PYTHON_VERSION)/site.py \
193 /usr/lib/python$(PYTHON_VERSION)/sysconfig.py \
194 /usr/lib/python$(PYTHON_VERSION)/stat.py
195
196 PYTHON3_LIB_FILES_DEL+=$(PYTHON3_BASE_LIB_FILES)
197
198 define Py3Package/python3-base/filespec
199 +|/usr/bin/python$(PYTHON_VERSION)
200 $(subst $(space),$(newline),$(foreach lib_file,$(PYTHON3_BASE_LIB_FILES),+|$(lib_file)))
201 endef
202
203 define Py3Package/python3-light/filespec
204 +|/usr/lib/python$(PYTHON_VERSION)
205 -|/usr/lib/python$(PYTHON_VERSION)/distutils/cygwinccompiler.py
206 -|/usr/lib/python$(PYTHON_VERSION)/distutils/command/wininst*
207 -|/usr/lib/python$(PYTHON_VERSION)/ensurepip
208 -|/usr/lib/python$(PYTHON_VERSION)/idlelib
209 -|/usr/lib/python$(PYTHON_VERSION)/tkinter
210 -|/usr/lib/python$(PYTHON_VERSION)/turtledemo
211 -|/usr/lib/python$(PYTHON_VERSION)/lib-dynload/_test*.so
212 -|/usr/lib/python$(PYTHON_VERSION)/lib-dynload/readline*.so
213 -|/usr/lib/python$(PYTHON_VERSION)/pdb.doc
214 -|/usr/lib/python$(PYTHON_VERSION)/test
215 -|/usr/lib/python$(PYTHON_VERSION)/webbrowser.py
216 -|/usr/lib/python$(PYTHON_VERSION)/*/test
217 -|/usr/lib/python$(PYTHON_VERSION)/*/tests
218 -|/usr/lib/python$(PYTHON_VERSION)/_osx_support.py
219 $(subst $(space),$(newline),$(foreach lib_file,$(PYTHON3_LIB_FILES_DEL),-|$(lib_file)))
220 endef
221
222 define Py3Package/python3-base/install
223 # Adding the lib-dynload folder (even just empty) suppresses 2 warnings when starting Python
224 $(INSTALL_DIR) $(1)/usr/lib/python$(PYTHON_VERSION)/lib-dynload/
225 $(INSTALL_DIR) $(1)/usr/bin
226 $(LN) python$(PYTHON_VERSION) $(1)/usr/bin/python3
227 $(CP) $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON_VERSION).so* $(1)/usr/lib/
228 endef
229
230 define Py3Package/python3/filespec
231 -|$(PYTHON3_PKG_DIR)
232 endef
233
234 HOST_CONFIGURE_ARGS+= \
235 --without-cxx-main \
236 --without-pymalloc \
237 --with-threads \
238 --prefix=$(HOST_PYTHON3_DIR) \
239 --exec-prefix=$(HOST_PYTHON3_DIR) \
240 --with-system-expat=$(STAGING_DIR_HOSTPKG) \
241 --with-system-ffi \
242 --with-ensurepip=no \
243 CONFIG_SITE= \
244 CFLAGS="$(HOST_CFLAGS)"
245
246 define Host/Compile
247 +$(MAKE) $(HOST_JOBS) -C $(HOST_BUILD_DIR) python Parser/pgen
248 +$(MAKE) $(HOST_JOBS) -C $(HOST_BUILD_DIR) sharedmods
249 endef
250
251 define Host/Install
252 $(MAKE) -C $(HOST_BUILD_DIR) install
253
254 $(INSTALL_DIR) $(HOST_PYTHON3_DIR)/bin/
255 $(INSTALL_BIN) $(HOST_BUILD_DIR)/Parser/pgen $(HOST_PYTHON3_DIR)/bin/pgen3
256 $(INSTALL_BIN) $(HOST_BUILD_DIR)/Programs/_freeze_importlib $(HOST_PYTHON3_DIR)/bin/_freeze_importlib
257 endef
258
259 $(eval $(call HostBuild))
260
261 $(foreach package, $(PYTHON3_PACKAGES), \
262 $(eval $(call Py3Package,$(package))) \
263 $(eval $(call BuildPackage,$(package))) \
264 )
265
266 $(eval $(call Py3Package,python3-base))
267 $(eval $(call Py3Package,python3-light))
268 $(eval $(call Py3Package,python3))
269
270 $(eval $(call BuildPackage,python3-base))
271 $(eval $(call BuildPackage,python3-light))
272 $(eval $(call BuildPackage,python3))