open-plc-utils: new package
[buildroot-gz.git] / package / python / python.mk
blob4a3e71c8a4b3660d2b8812eb9a329624df24144a
1 ################################################################################
3 # python
5 ################################################################################
7 PYTHON_VERSION_MAJOR = 2.7
8 PYTHON_VERSION = $(PYTHON_VERSION_MAJOR).9
9 PYTHON_SOURCE = Python-$(PYTHON_VERSION).tar.xz
10 PYTHON_SITE = http://python.org/ftp/python/$(PYTHON_VERSION)
11 PYTHON_LICENSE = Python software foundation license v2, others
12 PYTHON_LICENSE_FILES = LICENSE
13 PYTHON_LIBTOOL_PATCH = NO
15 # Python needs itself to be built, so in order to cross-compile
16 # Python, we need to build a host Python first. This host Python is
17 # also installed in $(HOST_DIR), as it is needed when cross-compiling
18 # third-party Python modules.
20 HOST_PYTHON_CONF_OPTS += \
21 --enable-static \
22 --without-cxx-main \
23 --disable-sqlite3 \
24 --disable-tk \
25 --with-expat=system \
26 --disable-curses \
27 --disable-codecs-cjk \
28 --disable-nis \
29 --enable-unicodedata \
30 --disable-dbm \
31 --disable-gdbm \
32 --disable-bsddb \
33 --disable-test-modules \
34 --disable-bz2 \
35 --disable-ssl \
36 --disable-ossaudiodev \
37 --disable-pyo-build
39 # Make sure that LD_LIBRARY_PATH overrides -rpath.
40 # This is needed because libpython may be installed at the same time that
41 # python is called.
42 HOST_PYTHON_CONF_ENV += \
43 LDFLAGS="$(HOST_LDFLAGS) -Wl,--enable-new-dtags"
45 # Building host python in parallel sometimes triggers a "Bus error"
46 # during the execution of "./python setup.py build" in the
47 # installation step. It is probably due to the installation of a
48 # shared library taking place in parallel to the execution of
49 # ./python, causing spurious Bus error. Building host-python with
50 # MAKE1 has shown to workaround the problem.
51 HOST_PYTHON_MAKE = $(MAKE1)
53 PYTHON_DEPENDENCIES = host-python libffi
55 HOST_PYTHON_DEPENDENCIES = host-expat host-zlib
57 PYTHON_INSTALL_STAGING = YES
59 ifeq ($(BR2_PACKAGE_PYTHON_READLINE),y)
60 PYTHON_DEPENDENCIES += readline
61 endif
63 ifeq ($(BR2_PACKAGE_PYTHON_CURSES),y)
64 PYTHON_DEPENDENCIES += ncurses
65 else
66 PYTHON_CONF_OPTS += --disable-curses
67 endif
69 ifeq ($(BR2_PACKAGE_PYTHON_PYEXPAT),y)
70 PYTHON_DEPENDENCIES += expat
71 PYTHON_CONF_OPTS += --with-expat=system
72 else
73 PYTHON_CONF_OPTS += --with-expat=none
74 endif
76 ifeq ($(BR2_PACKAGE_PYTHON_BSDDB),y)
77 PYTHON_DEPENDENCIES += berkeleydb
78 else
79 PYTHON_CONF_OPTS += --disable-bsddb
80 endif
82 ifeq ($(BR2_PACKAGE_PYTHON_SQLITE),y)
83 PYTHON_DEPENDENCIES += sqlite
84 else
85 PYTHON_CONF_OPTS += --disable-sqlite3
86 endif
88 ifeq ($(BR2_PACKAGE_PYTHON_SSL),y)
89 PYTHON_DEPENDENCIES += openssl
90 else
91 PYTHON_CONF_OPTS += --disable-ssl
92 endif
94 ifneq ($(BR2_PACKAGE_PYTHON_CODECSCJK),y)
95 PYTHON_CONF_OPTS += --disable-codecs-cjk
96 endif
98 ifneq ($(BR2_PACKAGE_PYTHON_UNICODEDATA),y)
99 PYTHON_CONF_OPTS += --disable-unicodedata
100 endif
102 # Default is UCS2 w/o a conf opt
103 ifeq ($(BR2_PACKAGE_PYTHON_UCS4),y)
104 PYTHON_CONF_OPTS += --enable-unicode=ucs4
105 endif
107 ifeq ($(BR2_PACKAGE_PYTHON_BZIP2),y)
108 PYTHON_DEPENDENCIES += bzip2
109 else
110 PYTHON_CONF_OPTS += --disable-bz2
111 endif
113 ifeq ($(BR2_PACKAGE_PYTHON_ZLIB),y)
114 PYTHON_DEPENDENCIES += zlib
115 else
116 PYTHON_CONF_OPTS += --disable-zlib
117 endif
119 ifeq ($(BR2_PACKAGE_PYTHON_HASHLIB),y)
120 PYTHON_DEPENDENCIES += openssl
121 endif
123 ifeq ($(BR2_PACKAGE_PYTHON_OSSAUDIODEV),y)
124 PYTHON_CONF_OPTS += --enable-ossaudiodev
125 else
126 PYTHON_CONF_OPTS += --disable-ossaudiodev
127 endif
129 PYTHON_CONF_ENV += \
130 ac_cv_have_long_long_format=yes \
131 ac_cv_file__dev_ptmx=yes \
132 ac_cv_file__dev_ptc=yes \
133 ac_cv_working_tzset=yes
135 PYTHON_CONF_OPTS += \
136 --without-cxx-main \
137 --without-doc-strings \
138 --with-system-ffi \
139 --disable-pydoc \
140 --disable-test-modules \
141 --disable-lib2to3 \
142 --disable-gdbm \
143 --disable-tk \
144 --disable-nis \
145 --disable-dbm \
146 --disable-pyo-build
148 # This is needed to make sure the Python build process doesn't try to
149 # regenerate those files with the pgen program. Otherwise, it builds
150 # pgen for the target, and tries to run it on the host.
152 define PYTHON_TOUCH_GRAMMAR_FILES
153 touch $(@D)/Include/graminit.h $(@D)/Python/graminit.c
154 endef
156 PYTHON_POST_PATCH_HOOKS += PYTHON_TOUCH_GRAMMAR_FILES
159 # Remove useless files. In the config/ directory, only the Makefile
160 # and the pyconfig.h files are needed at runtime.
162 # idle & smtpd.py have bad shebangs and are mostly samples
164 define PYTHON_REMOVE_USELESS_FILES
165 rm -f $(TARGET_DIR)/usr/bin/python$(PYTHON_VERSION_MAJOR)-config
166 rm -f $(TARGET_DIR)/usr/bin/python2-config
167 rm -f $(TARGET_DIR)/usr/bin/python-config
168 rm -f $(TARGET_DIR)/usr/bin/smtpd.py
169 for i in `find $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR)/config/ \
170 -type f -not -name pyconfig.h -a -not -name Makefile` ; do \
171 rm -f $$i ; \
172 done
173 endef
175 PYTHON_POST_INSTALL_TARGET_HOOKS += PYTHON_REMOVE_USELESS_FILES
178 # Make sure libpython gets stripped out on target
180 define PYTHON_ENSURE_LIBPYTHON_STRIPPED
181 chmod u+w $(TARGET_DIR)/usr/lib/libpython$(PYTHON_VERSION_MAJOR)*.so
182 endef
184 PYTHON_POST_INSTALL_TARGET_HOOKS += PYTHON_ENSURE_LIBPYTHON_STRIPPED
186 # Always install the python symlink in the target tree
187 define PYTHON_INSTALL_TARGET_PYTHON_SYMLINK
188 ln -sf python2 $(TARGET_DIR)/usr/bin/python
189 endef
191 PYTHON_POST_INSTALL_TARGET_HOOKS += PYTHON_INSTALL_TARGET_PYTHON_SYMLINK
193 # Always install the python-config symlink in the staging tree
194 define PYTHON_INSTALL_STAGING_PYTHON_CONFIG_SYMLINK
195 ln -sf python2-config $(STAGING_DIR)/usr/bin/python-config
196 endef
198 PYTHON_POST_INSTALL_STAGING_HOOKS += PYTHON_INSTALL_STAGING_PYTHON_CONFIG_SYMLINK
200 PYTHON_AUTORECONF = YES
202 # Some packages may have build scripts requiring python2.
203 # Only install the python symlink in the host tree if python3 is not enabled
204 # for the target, otherwise the default python program may be missing.
205 ifneq ($(BR2_PACKAGE_PYTHON3),y)
206 define HOST_PYTHON_INSTALL_PYTHON_SYMLINK
207 ln -sf python2 $(HOST_DIR)/usr/bin/python
208 ln -sf python2-config $(HOST_DIR)/usr/bin/python-config
209 endef
211 HOST_PYTHON_POST_INSTALL_HOOKS += HOST_PYTHON_INSTALL_PYTHON_SYMLINK
212 endif
214 # Provided to other packages
215 PYTHON_PATH = $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR)/sysconfigdata/:$(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR)/site-packages/
217 $(eval $(autotools-package))
218 $(eval $(host-autotools-package))
220 ifeq ($(BR2_PACKAGE_PYTHON_PYC_ONLY),y)
221 define PYTHON_FINALIZE_TARGET
222 find $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR) -name '*.py' -print0 | xargs -0 rm -f
223 endef
224 endif
226 ifeq ($(BR2_PACKAGE_PYTHON_PY_ONLY),y)
227 define PYTHON_FINALIZE_TARGET
228 find $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR) -name '*.pyc' -print0 | xargs -0 rm -f
229 endef
230 endif
232 TARGET_FINALIZE_HOOKS += PYTHON_FINALIZE_TARGET