cjson: bump to version 1.4.3
[buildroot-gz.git] / package / python3 / python3.mk
blobc8f8e1bf042700adb4e49d6013f6be8b9c679b1e
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 else
60 PYTHON3_CONF_OPTS += --disable-readline
61 endif
63 ifeq ($(BR2_PACKAGE_PYTHON3_CURSES),y)
64 PYTHON3_DEPENDENCIES += ncurses
65 else
66 PYTHON3_CONF_OPTS += --disable-curses
67 endif
69 ifeq ($(BR2_PACKAGE_PYTHON3_DECIMAL),y)
70 PYTHON3_DEPENDENCIES += mpdecimal
71 PYTHON3_CONF_OPTS += --with-libmpdec=system
72 else
73 PYTHON3_CONF_OPTS += --with-libmpdec=none
74 endif
76 ifeq ($(BR2_PACKAGE_PYTHON3_PYEXPAT),y)
77 PYTHON3_DEPENDENCIES += expat
78 PYTHON3_CONF_OPTS += --with-expat=system
79 else
80 PYTHON3_CONF_OPTS += --with-expat=none
81 endif
83 ifeq ($(BR2_PACKAGE_PYTHON3_PYC_ONLY),y)
84 PYTHON3_CONF_OPTS += --enable-old-stdlib-cache
85 endif
87 ifeq ($(BR2_PACKAGE_PYTHON3_SQLITE),y)
88 PYTHON3_DEPENDENCIES += sqlite
89 else
90 PYTHON3_CONF_OPTS += --disable-sqlite3
91 endif
93 ifeq ($(BR2_PACKAGE_PYTHON3_SSL),y)
94 PYTHON3_DEPENDENCIES += openssl
95 else
96 PYTHON3_CONF_OPTS += --disable-openssl
97 endif
99 ifneq ($(BR2_PACKAGE_PYTHON3_CODECSCJK),y)
100 PYTHON3_CONF_OPTS += --disable-codecs-cjk
101 endif
103 ifneq ($(BR2_PACKAGE_PYTHON3_UNICODEDATA),y)
104 PYTHON3_CONF_OPTS += --disable-unicodedata
105 endif
107 ifeq ($(BR2_PACKAGE_PYTHON3_BZIP2),y)
108 PYTHON3_DEPENDENCIES += bzip2
109 else
110 PYTHON3_CONF_OPTS += --disable-bzip2
111 endif
113 ifeq ($(BR2_PACKAGE_PYTHON3_XZ),y)
114 PYTHON3_DEPENDENCIES += xz
115 else
116 PYTHON3_CONF_OPTS += --disable-xz
117 endif
119 ifeq ($(BR2_PACKAGE_PYTHON3_ZLIB),y)
120 PYTHON3_DEPENDENCIES += zlib
121 else
122 PYTHON3_CONF_OPTS += --disable-zlib
123 endif
125 ifeq ($(BR2_PACKAGE_PYTHON3_OSSAUDIODEV),y)
126 PYTHON3_CONF_OPTS += --enable-ossaudiodev
127 else
128 PYTHON3_CONF_OPTS += --disable-ossaudiodev
129 endif
131 # Make python believe we don't have 'hg', so that it doesn't try to
132 # communicate over the network during the build.
133 PYTHON3_CONF_ENV += \
134 ac_cv_have_long_long_format=yes \
135 ac_cv_file__dev_ptmx=yes \
136 ac_cv_file__dev_ptc=yes \
137 ac_cv_working_tzset=yes \
138 ac_cv_prog_HAS_HG=/bin/false
140 # GCC is always compliant with IEEE754
141 ifeq ($(BR2_ENDIAN),"LITTLE")
142 PYTHON3_CONF_ENV += ac_cv_little_endian_double=yes
143 else
144 PYTHON3_CONF_ENV += ac_cv_big_endian_double=yes
145 endif
147 # uClibc is known to have a broken wcsftime() implementation, so tell
148 # Python 3 to fall back to strftime() instead.
149 ifeq ($(BR2_TOOLCHAIN_USES_UCLIBC),y)
150 PYTHON3_CONF_ENV += ac_cv_func_wcsftime=no
151 endif
153 PYTHON3_CONF_OPTS += \
154 --without-ensurepip \
155 --without-cxx-main \
156 --with-system-ffi \
157 --disable-pydoc \
158 --disable-test-modules \
159 --disable-lib2to3 \
160 --disable-tk \
161 --disable-nis \
162 --disable-idle3 \
163 --disable-pyc-build
165 # Python builds two tools to generate code: 'pgen' and
166 # '_freeze_importlib'. Unfortunately, for the target Python, they are
167 # built for the target, while we need to run them at build time. So
168 # when installing host-python, we copy them to
169 # $(HOST_DIR)/usr/bin. And then, when building the target python
170 # package, we tell the configure script where they are located.
171 define HOST_PYTHON3_INSTALL_TOOLS
172 cp $(@D)/Parser/pgen $(HOST_DIR)/usr/bin/python-pgen
173 cp $(@D)/Programs/_freeze_importlib $(HOST_DIR)/usr/bin/python-freeze-importlib
174 endef
175 HOST_PYTHON3_POST_INSTALL_HOOKS += HOST_PYTHON3_INSTALL_TOOLS
177 PYTHON3_CONF_ENV += \
178 PGEN_FOR_BUILD=$(HOST_DIR)/usr/bin/python-pgen \
179 FREEZE_IMPORTLIB_FOR_BUILD=$(HOST_DIR)/usr/bin/python-freeze-importlib
182 # Remove useless files. In the config/ directory, only the Makefile
183 # and the pyconfig.h files are needed at runtime.
185 define PYTHON3_REMOVE_USELESS_FILES
186 rm -f $(TARGET_DIR)/usr/bin/python$(PYTHON3_VERSION_MAJOR)-config
187 rm -f $(TARGET_DIR)/usr/bin/python$(PYTHON3_VERSION_MAJOR)m-config
188 rm -f $(TARGET_DIR)/usr/bin/python3-config
189 rm -f $(TARGET_DIR)/usr/bin/smtpd.py.3
190 for i in `find $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/config-$(PYTHON3_VERSION_MAJOR)m/ \
191 -type f -not -name pyconfig.h -a -not -name Makefile` ; do \
192 rm -f $$i ; \
193 done
194 rm -rf $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/__pycache__/
195 rm -rf $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/lib-dynload/sysconfigdata/__pycache__
196 rm -rf $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/collections/__pycache__
197 rm -rf $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/importlib/__pycache__
198 endef
200 PYTHON3_POST_INSTALL_TARGET_HOOKS += PYTHON3_REMOVE_USELESS_FILES
203 # Make sure libpython gets stripped out on target
205 define PYTHON3_ENSURE_LIBPYTHON_STRIPPED
206 chmod u+w $(TARGET_DIR)/usr/lib/libpython$(PYTHON3_VERSION_MAJOR)*.so
207 endef
209 PYTHON3_POST_INSTALL_TARGET_HOOKS += PYTHON3_ENSURE_LIBPYTHON_STRIPPED
211 PYTHON3_AUTORECONF = YES
213 define PYTHON3_INSTALL_SYMLINK
214 ln -fs python3 $(TARGET_DIR)/usr/bin/python
215 endef
217 ifneq ($(BR2_PACKAGE_PYTHON),y)
218 PYTHON3_POST_INSTALL_TARGET_HOOKS += PYTHON3_INSTALL_SYMLINK
219 endif
221 # Some packages may have build scripts requiring python3, whatever is the
222 # python version chosen for the target.
223 # Only install the python symlink in the host tree if python3 is enabled
224 # for the target.
225 ifeq ($(BR2_PACKAGE_PYTHON3),y)
226 define HOST_PYTHON3_INSTALL_SYMLINK
227 ln -fs python3 $(HOST_DIR)/usr/bin/python
228 ln -fs python3-config $(HOST_DIR)/usr/bin/python-config
229 endef
231 HOST_PYTHON3_POST_INSTALL_HOOKS += HOST_PYTHON3_INSTALL_SYMLINK
232 endif
234 # Provided to other packages
235 PYTHON3_PATH = $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/sysconfigdata/:$(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/site-packages/
237 $(eval $(autotools-package))
238 $(eval $(host-autotools-package))
240 define PYTHON3_CREATE_PYC_FILES
241 PYTHONPATH="$(PYTHON3_PATH)" \
242 $(HOST_DIR)/usr/bin/python$(PYTHON3_VERSION_MAJOR) \
243 support/scripts/pycompile.py \
244 $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)
245 endef
247 ifeq ($(BR2_PACKAGE_PYTHON3_PYC_ONLY)$(BR2_PACKAGE_PYTHON3_PY_PYC),y)
248 PYTHON3_TARGET_FINALIZE_HOOKS += PYTHON3_CREATE_PYC_FILES
249 endif
251 ifeq ($(BR2_PACKAGE_PYTHON3_PYC_ONLY),y)
252 define PYTHON3_REMOVE_PY_FILES
253 find $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR) -name '*.py' -print0 | \
254 xargs -0 --no-run-if-empty rm -f
255 endef
256 PYTHON3_TARGET_FINALIZE_HOOKS += PYTHON3_REMOVE_PY_FILES
257 endif
259 # Normally, *.pyc files should not have been compiled, but just in
260 # case, we make sure we remove all of them.
261 ifeq ($(BR2_PACKAGE_PYTHON3_PY_ONLY),y)
262 define PYTHON3_REMOVE_PYC_FILES
263 find $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR) -name '*.pyc' -print0 | \
264 xargs -0 --no-run-if-empty rm -f
265 endef
266 PYTHON3_TARGET_FINALIZE_HOOKS += PYTHON3_REMOVE_PYC_FILES
267 endif
269 # In all cases, we don't want to keep the optimized .opt-1.pyc and
270 # .opt-2.pyc files, since they can't work without their non-optimized
271 # variant.
272 define PYTHON3_REMOVE_OPTIMIZED_PYC_FILES
273 find $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR) -name '*.opt-1.pyc' -print0 -o -name '*.opt-2.pyc' -print0 | \
274 xargs -0 --no-run-if-empty rm -f
275 endef
276 PYTHON3_TARGET_FINALIZE_HOOKS += PYTHON3_REMOVE_OPTIMIZED_PYC_FILES