Fresh pull from upstream (stable) package feed
[librecmc/package-feed.git] / lang / 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:=1f6db41ad91d9eb0a6f0c769b8613c5b
20 PKG_HASH:=71ffb26e09e78650e424929b2b457b9c912ac216576e6bd9e7d204ed03296a66
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-base
63 $(call Package/python/Default)
64   TITLE:=Python $(PYTHON_VERSION) interpreter
65   DEPENDS:=+libpthread +zlib
66 endef
67
68 define Package/python-base/description
69   This package contains only the interpreter and the bare minimum
70   for the interpreter to start.
71 endef
72
73 define Package/python-light
74 $(call Package/python/Default)
75   TITLE:=Python $(PYTHON_VERSION) light installation
76   DEPENDS:=+python-base +libffi +libbz2
77 endef
78
79 define Package/python-light/description
80   This package is essentially the python-base package plus
81   a few of the rarely used (and big) libraries stripped out
82   into separate packages.
83 endef
84
85 PYTHON_LIB_FILES_DEL:=
86 PYTHON_PACKAGES:=
87 PYTHON_PACKAGES_DEPENDS:=
88 define PyBasePackage
89   PYTHON_PACKAGES+=$(1)
90   ifeq ($(3),)
91     PYTHON_PACKAGES_DEPENDS+=$(1)
92   endif
93   PYTHON_LIB_FILES_DEL+=$(2)
94   define PyPackage/$(1)/filespec
95     $(subst $(space),$(newline),$(foreach lib_file,$(2),+|$(lib_file)))
96   endef
97 endef
98
99 include ./files/python-package-*.mk
100
101 define Package/python
102 $(call Package/python/Default)
103   DEPENDS:=+python-light $(foreach package,$(PYTHON_PACKAGES_DEPENDS),+$(package))
104 endef
105
106 define Package/python/description
107   This package contains the (almost) full Python install.
108   It's python-light + all other packages.
109 endef
110
111 MAKE_FLAGS+=\
112         CROSS_COMPILE=yes \
113         LD="$(TARGET_CC)" \
114         PGEN=pgen2
115
116 EXTRA_CFLAGS+= \
117         -DNDEBUG -fno-inline
118 EXTRA_LDFLAGS+= \
119         -L$(PKG_BUILD_DIR)
120
121 ENABLE_IPV6:=
122 ifeq ($(CONFIG_IPV6),y)
123         ENABLE_IPV6 += --enable-ipv6
124 endif
125
126 PYTHON_FOR_BUILD:= \
127         _PYTHON_PROJECT_BASE=$(PKG_BUILD_DIR) \
128         _PYTHON_HOST_PLATFORM=linux2 \
129         PYTHONPATH="$(PKG_BUILD_DIR)/Lib:$(PKG_BUILD_DIR)/build/lib.linux2-$(PYTHON_VERSION)" \
130         _PYTHON_SYSCONFIGDATA_NAME=_sysconfigdata \
131         $(HOST_PYTHON_BIN)
132
133 CONFIGURE_ARGS+= \
134         --sysconfdir=/etc \
135         --enable-shared \
136         --without-cxx-main \
137         --with-threads \
138         --with-system-ffi \
139         --without-pymalloc \
140         PYTHON_FOR_BUILD="$(PYTHON_FOR_BUILD)" \
141         $(ENABLE_IPV6) \
142         CONFIG_SITE="$(PKG_BUILD_DIR)/config.site" \
143         OPT="$(TARGET_CFLAGS)"
144
145 define Build/Prepare
146         $(call Build/Prepare/Default)
147         $(CP) ./files/config.site $(PKG_BUILD_DIR)/config.site
148 endef
149
150 define Build/InstallDev
151         $(INSTALL_DIR) $(STAGING_DIR)/mk/
152         $(INSTALL_DIR) $(1)/usr/include/ $(1)/usr/lib/ $(1)/usr/lib/pkgconfig
153         $(INSTALL_DIR) $(1)/usr/lib/python$(PYTHON_VERSION)/
154         $(INSTALL_DATA) \
155                 ./files/python-package.mk \
156                 ./files/python-host.mk \
157                 ./files/python-version.mk \
158                 $(STAGING_DIR)/mk/
159         $(CP) \
160                 $(PKG_INSTALL_DIR)/usr/include/python$(PYTHON_VERSION) \
161                 $(1)/usr/include/
162         $(CP) \
163                 $(HOST_PYTHON_LIB_DIR) \
164                 $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON_VERSION).so* \
165                 $(1)/usr/lib/
166         $(CP) \
167                 $(HOST_PYTHON_DIR)/lib/pkgconfig/python.pc \
168                 $(HOST_PYTHON_DIR)/lib/pkgconfig/python2.pc \
169                 $(HOST_PYTHON_DIR)/lib/pkgconfig/python-$(PYTHON_VERSION).pc \
170                 $(1)/usr/lib/pkgconfig
171         $(CP) \
172                 $(PKG_INSTALL_DIR)/usr/lib/python$(PYTHON_VERSION)/config \
173                 $(1)/usr/lib/python$(PYTHON_VERSION)/
174 endef
175
176 PYTHON_BASE_LIB_FILES:= \
177         /usr/lib/python$(PYTHON_VERSION)/_abcoll.py \
178         /usr/lib/python$(PYTHON_VERSION)/_sysconfigdata.py \
179         /usr/lib/python$(PYTHON_VERSION)/_weakrefset.py \
180         /usr/lib/python$(PYTHON_VERSION)/abc.py \
181         /usr/lib/python$(PYTHON_VERSION)/copy_reg.py \
182         /usr/lib/python$(PYTHON_VERSION)/genericpath.py \
183         /usr/lib/python$(PYTHON_VERSION)/linecache.py \
184         /usr/lib/python$(PYTHON_VERSION)/posixpath.py \
185         /usr/lib/python$(PYTHON_VERSION)/os.py \
186         /usr/lib/python$(PYTHON_VERSION)/re.py \
187         /usr/lib/python$(PYTHON_VERSION)/site.py \
188         /usr/lib/python$(PYTHON_VERSION)/sre_compile.py \
189         /usr/lib/python$(PYTHON_VERSION)/sre_constants.py \
190         /usr/lib/python$(PYTHON_VERSION)/sre_parse.py \
191         /usr/lib/python$(PYTHON_VERSION)/sysconfig.py \
192         /usr/lib/python$(PYTHON_VERSION)/stat.py \
193         /usr/lib/python$(PYTHON_VERSION)/traceback.py \
194         /usr/lib/python$(PYTHON_VERSION)/types.py \
195         /usr/lib/python$(PYTHON_VERSION)/UserDict.py \
196         /usr/lib/python$(PYTHON_VERSION)/warnings.py
197
198 PYTHON_LIB_FILES_DEL+=$(PYTHON_BASE_LIB_FILES)
199
200 define PyPackage/python-base/filespec
201 +|/usr/bin/python$(PYTHON_VERSION)
202 $(subst $(space),$(newline),$(foreach lib_file,$(PYTHON_BASE_LIB_FILES),+|$(lib_file)))
203 endef
204
205 define PyPackage/python-light/filespec
206 +|/usr/lib/python$(PYTHON_VERSION)
207 -|/usr/lib/python$(PYTHON_VERSION)/distutils/cygwinccompiler.py
208 -|/usr/lib/python$(PYTHON_VERSION)/distutils/command/wininst*
209 -|/usr/lib/python$(PYTHON_VERSION)/ensurepip
210 -|/usr/lib/python$(PYTHON_VERSION)/idlelib
211 -|/usr/lib/python$(PYTHON_VERSION)/lib-tk
212 -|/usr/lib/python$(PYTHON_VERSION)/lib-dynload/_testcapi.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)/lib-dynload/readline.so
219 $(subst $(space),$(newline),$(foreach lib_file,$(PYTHON_LIB_FILES_DEL),-|$(lib_file)))
220 endef
221
222 define PyPackage/python-base/install
223         $(LN) python$(PYTHON_VERSION) $(1)/usr/bin/python
224         $(LN) python$(PYTHON_VERSION) $(1)/usr/bin/python2
225         $(CP) $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON_VERSION).so* $(1)/usr/lib/
226 endef
227
228 define PyPackage/python/filespec
229 -|$(PYTHON_PKG_DIR)
230 endef
231
232 HOST_LDFLAGS += \
233         $$$$(pkg-config --static --libs libcrypto libssl)
234
235 HOST_CONFIGURE_ARGS+= \
236         --without-cxx-main \
237         --without-pymalloc \
238         --with-threads \
239         --prefix=$(HOST_PYTHON_DIR) \
240         --exec-prefix=$(HOST_PYTHON_DIR) \
241         --with-system-expat=$(STAGING_DIR_HOSTPKG) \
242         --with-system-ffi=no \
243         CONFIG_SITE=
244
245 define Host/Compile
246         $(call Host/Compile/Default,python Parser/pgen sharedmods)
247 endef
248
249 define Host/Install
250         $(MAKE) -C $(HOST_BUILD_DIR) install
251         $(INSTALL_DIR) $(HOST_PYTHON_DIR)/bin/
252         $(INSTALL_BIN) $(HOST_BUILD_DIR)/Parser/pgen $(HOST_PYTHON_DIR)/bin/pgen2
253 endef
254
255 $(eval $(call HostBuild))
256
257 $(foreach package, $(PYTHON_PACKAGES),  \
258         $(eval $(call PyPackage,$(package))) \
259         $(eval $(call BuildPackage,$(package))) \
260 )
261
262 $(eval $(call PyPackage,python-base))
263 $(eval $(call PyPackage,python-light))
264 $(eval $(call PyPackage,python))
265
266 $(eval $(call BuildPackage,python-base))
267 $(eval $(call BuildPackage,python-light))
268 $(eval $(call BuildPackage,python))