janus-gateway: make echo test plugin optional
[buildroot-gz.git] / package / python3 / python3.mk
blob8bfae79f58e1d2ffea84dfa9dc8b95a48ce52641
1 ################################################################################
3 # python3
5 ################################################################################
7 PYTHON3_VERSION_MAJOR = 3.5
8 PYTHON3_VERSION = $(PYTHON3_VERSION_MAJOR).2
9 PYTHON3_SOURCE = Python-$(PYTHON3_VERSION).tar.xz
10 PYTHON3_SITE = http://python.org/ftp/python/$(PYTHON3_VERSION)
11 PYTHON3_LICENSE = Python software foundation license v2, others
12 PYTHON3_LICENSE_FILES = LICENSE
14 # Python itself doesn't use libtool, but it includes the source code
15 # of libffi, which uses libtool. Unfortunately, it uses a beta version
16 # of libtool for which we don't have a matching patch. However, this
17 # is not a problem, because we don't use the libffi copy included in
18 # the Python sources, but instead use an external libffi library.
19 PYTHON3_LIBTOOL_PATCH = NO
21 # Python needs itself and a "pgen" program to build itself, both being
22 # provided in the Python sources. So in order to cross-compile Python,
23 # we need to build a host Python first. This host Python is also
24 # installed in $(HOST_DIR), as it is needed when cross-compiling
25 # third-party Python modules.
27 HOST_PYTHON3_CONF_OPTS += \
28 --without-ensurepip \
29 --without-cxx-main \
30 --disable-sqlite3 \
31 --disable-tk \
32 --with-expat=system \
33 --disable-curses \
34 --disable-codecs-cjk \
35 --disable-nis \
36 --enable-unicodedata \
37 --disable-test-modules \
38 --disable-idle3 \
39 --disable-ossaudiodev \
40 --disable-openssl
42 # Make sure that LD_LIBRARY_PATH overrides -rpath.
43 # This is needed because libpython may be installed at the same time that
44 # python is called.
45 # Make python believe we don't have 'hg', so that it doesn't try to
46 # communicate over the network during the build.
47 HOST_PYTHON3_CONF_ENV += \
48 LDFLAGS="$(HOST_LDFLAGS) -Wl,--enable-new-dtags" \
49 ac_cv_prog_HAS_HG=/bin/false
51 PYTHON3_DEPENDENCIES = host-python3 libffi
53 HOST_PYTHON3_DEPENDENCIES = host-expat host-zlib
55 PYTHON3_INSTALL_STAGING = YES
57 ifeq ($(BR2_PACKAGE_PYTHON3_READLINE),y)
58 PYTHON3_DEPENDENCIES += readline
59 endif
61 ifeq ($(BR2_PACKAGE_PYTHON3_CURSES),y)
62 PYTHON3_DEPENDENCIES += ncurses
63 else
64 PYTHON3_CONF_OPTS += --disable-curses
65 endif
67 ifeq ($(BR2_PACKAGE_PYTHON3_DECIMAL),y)
68 PYTHON3_DEPENDENCIES += mpdecimal
69 PYTHON3_CONF_OPTS += --with-libmpdec=system
70 else
71 PYTHON3_CONF_OPTS += --with-libmpdec=none
72 endif
74 ifeq ($(BR2_PACKAGE_PYTHON3_PYEXPAT),y)
75 PYTHON3_DEPENDENCIES += expat
76 PYTHON3_CONF_OPTS += --with-expat=system
77 else
78 PYTHON3_CONF_OPTS += --with-expat=none
79 endif
81 ifeq ($(BR2_PACKAGE_PYTHON3_PYC_ONLY),y)
82 PYTHON3_CONF_OPTS += --enable-old-stdlib-cache
83 endif
85 ifeq ($(BR2_PACKAGE_PYTHON3_SQLITE),y)
86 PYTHON3_DEPENDENCIES += sqlite
87 else
88 PYTHON3_CONF_OPTS += --disable-sqlite3
89 endif
91 ifeq ($(BR2_PACKAGE_PYTHON3_SSL),y)
92 PYTHON3_DEPENDENCIES += openssl
93 endif
95 ifneq ($(BR2_PACKAGE_PYTHON3_CODECSCJK),y)
96 PYTHON3_CONF_OPTS += --disable-codecs-cjk
97 endif
99 ifneq ($(BR2_PACKAGE_PYTHON3_UNICODEDATA),y)
100 PYTHON3_CONF_OPTS += --disable-unicodedata
101 endif
103 ifeq ($(BR2_PACKAGE_PYTHON3_BZIP2),y)
104 PYTHON3_DEPENDENCIES += bzip2
105 endif
107 ifeq ($(BR2_PACKAGE_PYTHON3_XZ),y)
108 PYTHON3_DEPENDENCIES += xz
109 endif
111 ifeq ($(BR2_PACKAGE_PYTHON3_ZLIB),y)
112 PYTHON3_DEPENDENCIES += zlib
113 endif
115 ifeq ($(BR2_PACKAGE_PYTHON3_OSSAUDIODEV),y)
116 PYTHON3_CONF_OPTS += --enable-ossaudiodev
117 else
118 PYTHON3_CONF_OPTS += --disable-ossaudiodev
119 endif
121 # Make python believe we don't have 'hg', so that it doesn't try to
122 # communicate over the network during the build.
123 PYTHON3_CONF_ENV += \
124 ac_cv_have_long_long_format=yes \
125 ac_cv_file__dev_ptmx=yes \
126 ac_cv_file__dev_ptc=yes \
127 ac_cv_working_tzset=yes \
128 ac_cv_prog_HAS_HG=/bin/false
130 # GCC is always compliant with IEEE754
131 ifeq ($(BR2_ENDIAN),"LITTLE")
132 PYTHON3_CONF_ENV += ac_cv_little_endian_double=yes
133 else
134 PYTHON3_CONF_ENV += ac_cv_big_endian_double=yes
135 endif
137 # uClibc is known to have a broken wcsftime() implementation, so tell
138 # Python 3 to fall back to strftime() instead.
139 ifeq ($(BR2_TOOLCHAIN_USES_UCLIBC),y)
140 PYTHON3_CONF_ENV += ac_cv_func_wcsftime=no
141 endif
143 PYTHON3_CONF_OPTS += \
144 --without-ensurepip \
145 --without-cxx-main \
146 --with-system-ffi \
147 --disable-pydoc \
148 --disable-test-modules \
149 --disable-lib2to3 \
150 --disable-tk \
151 --disable-nis \
152 --disable-idle3 \
153 --disable-pyc-build
155 # Python builds two tools to generate code: 'pgen' and
156 # '_freeze_importlib'. Unfortunately, for the target Python, they are
157 # built for the target, while we need to run them at build time. So
158 # when installing host-python, we copy them to
159 # $(HOST_DIR)/usr/bin. And then, when building the target python
160 # package, we tell the configure script where they are located.
161 define HOST_PYTHON3_INSTALL_TOOLS
162 cp $(@D)/Parser/pgen $(HOST_DIR)/usr/bin/python-pgen
163 cp $(@D)/Programs/_freeze_importlib $(HOST_DIR)/usr/bin/python-freeze-importlib
164 endef
165 HOST_PYTHON3_POST_INSTALL_HOOKS += HOST_PYTHON3_INSTALL_TOOLS
167 PYTHON3_CONF_ENV += \
168 PGEN_FOR_BUILD=$(HOST_DIR)/usr/bin/python-pgen \
169 FREEZE_IMPORTLIB_FOR_BUILD=$(HOST_DIR)/usr/bin/python-freeze-importlib
172 # Remove useless files. In the config/ directory, only the Makefile
173 # and the pyconfig.h files are needed at runtime.
175 define PYTHON3_REMOVE_USELESS_FILES
176 rm -f $(TARGET_DIR)/usr/bin/python$(PYTHON3_VERSION_MAJOR)-config
177 rm -f $(TARGET_DIR)/usr/bin/python$(PYTHON3_VERSION_MAJOR)m-config
178 rm -f $(TARGET_DIR)/usr/bin/python3-config
179 rm -f $(TARGET_DIR)/usr/bin/smtpd.py.3
180 for i in `find $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/config-$(PYTHON3_VERSION_MAJOR)m/ \
181 -type f -not -name pyconfig.h -a -not -name Makefile` ; do \
182 rm -f $$i ; \
183 done
184 rm -rf $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/__pycache__/
185 rm -rf $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/lib-dynload/sysconfigdata/__pycache__
186 rm -rf $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/collections/__pycache__
187 rm -rf $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/importlib/__pycache__
188 endef
190 PYTHON3_POST_INSTALL_TARGET_HOOKS += PYTHON3_REMOVE_USELESS_FILES
193 # Make sure libpython gets stripped out on target
195 define PYTHON3_ENSURE_LIBPYTHON_STRIPPED
196 chmod u+w $(TARGET_DIR)/usr/lib/libpython$(PYTHON3_VERSION_MAJOR)*.so
197 endef
199 PYTHON3_POST_INSTALL_TARGET_HOOKS += PYTHON3_ENSURE_LIBPYTHON_STRIPPED
201 PYTHON3_AUTORECONF = YES
203 define PYTHON3_INSTALL_SYMLINK
204 ln -fs python3 $(TARGET_DIR)/usr/bin/python
205 endef
207 ifneq ($(BR2_PACKAGE_PYTHON),y)
208 PYTHON3_POST_INSTALL_TARGET_HOOKS += PYTHON3_INSTALL_SYMLINK
209 endif
211 # Some packages may have build scripts requiring python3, whatever is the
212 # python version chosen for the target.
213 # Only install the python symlink in the host tree if python3 is enabled
214 # for the target.
215 ifeq ($(BR2_PACKAGE_PYTHON3),y)
216 define HOST_PYTHON3_INSTALL_SYMLINK
217 ln -fs python3 $(HOST_DIR)/usr/bin/python
218 ln -fs python3-config $(HOST_DIR)/usr/bin/python-config
219 endef
221 HOST_PYTHON3_POST_INSTALL_HOOKS += HOST_PYTHON3_INSTALL_SYMLINK
222 endif
224 # Provided to other packages
225 PYTHON3_PATH = $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/sysconfigdata/:$(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/site-packages/
227 $(eval $(autotools-package))
228 $(eval $(host-autotools-package))
230 define PYTHON3_CREATE_PYC_FILES
231 PYTHONPATH="$(PYTHON3_PATH)" \
232 $(HOST_DIR)/usr/bin/python$(PYTHON3_VERSION_MAJOR) \
233 support/scripts/pycompile.py \
234 $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)
235 endef
237 ifeq ($(BR2_PACKAGE_PYTHON3_PYC_ONLY)$(BR2_PACKAGE_PYTHON3_PY_PYC),y)
238 PYTHON3_TARGET_FINALIZE_HOOKS += PYTHON3_CREATE_PYC_FILES
239 endif
241 ifeq ($(BR2_PACKAGE_PYTHON3_PYC_ONLY),y)
242 define PYTHON3_REMOVE_PY_FILES
243 find $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR) -name '*.py' -print0 | \
244 xargs -0 --no-run-if-empty rm -f
245 endef
246 PYTHON3_TARGET_FINALIZE_HOOKS += PYTHON3_REMOVE_PY_FILES
247 endif
249 # Normally, *.pyc files should not have been compiled, but just in
250 # case, we make sure we remove all of them.
251 ifeq ($(BR2_PACKAGE_PYTHON3_PY_ONLY),y)
252 define PYTHON3_REMOVE_PYC_FILES
253 find $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR) -name '*.pyc' -print0 | \
254 xargs -0 --no-run-if-empty rm -f
255 endef
256 PYTHON3_TARGET_FINALIZE_HOOKS += PYTHON3_REMOVE_PYC_FILES
257 endif
259 # In all cases, we don't want to keep the optimized .opt-1.pyc and
260 # .opt-2.pyc files, since they can't work without their non-optimized
261 # variant.
262 define PYTHON3_REMOVE_OPTIMIZED_PYC_FILES
263 find $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR) -name '*.opt-1.pyc' -print0 -o -name '*.opt-2.pyc' -print0 | \
264 xargs -0 --no-run-if-empty rm -f
265 endef
266 PYTHON3_TARGET_FINALIZE_HOOKS += PYTHON3_REMOVE_OPTIMIZED_PYC_FILES