python.mk 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. ################################################################################
  2. #
  3. # python
  4. #
  5. ################################################################################
  6. PYTHON_VERSION_MAJOR = 2.7
  7. PYTHON_VERSION = $(PYTHON_VERSION_MAJOR).18
  8. PYTHON_SOURCE = Python-$(PYTHON_VERSION).tar.xz
  9. PYTHON_SITE = https://python.org/ftp/python/$(PYTHON_VERSION)
  10. PYTHON_LICENSE = Python-2.0, others
  11. PYTHON_LICENSE_FILES = LICENSE
  12. PYTHON_CPE_ID_VENDOR = python
  13. PYTHON_LIBTOOL_PATCH = NO
  14. # Python needs itself to be built, so in order to cross-compile
  15. # Python, we need to build a host Python first. This host Python is
  16. # also installed in $(HOST_DIR), as it is needed when cross-compiling
  17. # third-party Python modules.
  18. HOST_PYTHON_CONF_OPTS += \
  19. --enable-static \
  20. --without-cxx-main \
  21. --disable-sqlite3 \
  22. --disable-tk \
  23. --with-expat=system \
  24. --with-system-ffi \
  25. --disable-curses \
  26. --disable-codecs-cjk \
  27. --disable-nis \
  28. --enable-unicodedata \
  29. --disable-dbm \
  30. --disable-gdbm \
  31. --disable-bsddb \
  32. --disable-test-modules \
  33. --disable-bz2 \
  34. --disable-ossaudiodev \
  35. --disable-pyo-build
  36. # Make sure that LD_LIBRARY_PATH overrides -rpath.
  37. # This is needed because libpython may be installed at the same time that
  38. # python is called.
  39. # Make python believe we don't have 'hg' and 'svn', so that it doesn't
  40. # try to communicate over the network during the build.
  41. HOST_PYTHON_CONF_ENV += \
  42. LDFLAGS="$(HOST_LDFLAGS) -Wl,--enable-new-dtags" \
  43. ac_cv_prog_HAS_HG=/bin/false \
  44. ac_cv_prog_SVNVERSION=/bin/false
  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)
  52. PYTHON_DEPENDENCIES = host-python libffi $(TARGET_NLS_DEPENDENCIES)
  53. HOST_PYTHON_DEPENDENCIES = host-expat host-libffi host-zlib
  54. ifeq ($(BR2_PACKAGE_HOST_PYTHON_SSL),y)
  55. HOST_PYTHON_DEPENDENCIES += host-openssl
  56. else
  57. HOST_PYTHON_CONF_OPTS += --disable-ssl
  58. endif
  59. PYTHON_INSTALL_STAGING = YES
  60. ifeq ($(BR2_PACKAGE_PYTHON_READLINE),y)
  61. PYTHON_DEPENDENCIES += readline
  62. else
  63. PYTHON_CONF_OPTS += --disable-readline
  64. endif
  65. ifeq ($(BR2_PACKAGE_PYTHON_CURSES),y)
  66. PYTHON_DEPENDENCIES += ncurses
  67. else
  68. PYTHON_CONF_OPTS += --disable-curses
  69. endif
  70. ifeq ($(BR2_PACKAGE_PYTHON_PYEXPAT),y)
  71. PYTHON_DEPENDENCIES += expat
  72. PYTHON_CONF_OPTS += --with-expat=system
  73. else
  74. PYTHON_CONF_OPTS += --with-expat=none
  75. endif
  76. ifeq ($(BR2_PACKAGE_PYTHON_BSDDB),y)
  77. PYTHON_DEPENDENCIES += berkeleydb
  78. else
  79. PYTHON_CONF_OPTS += --disable-bsddb
  80. endif
  81. ifeq ($(BR2_PACKAGE_PYTHON_SQLITE),y)
  82. PYTHON_DEPENDENCIES += sqlite
  83. else
  84. PYTHON_CONF_OPTS += --disable-sqlite3
  85. endif
  86. ifeq ($(BR2_PACKAGE_PYTHON_SSL),y)
  87. PYTHON_DEPENDENCIES += openssl
  88. else
  89. PYTHON_CONF_OPTS += --disable-ssl
  90. endif
  91. ifneq ($(BR2_PACKAGE_PYTHON_CODECSCJK),y)
  92. PYTHON_CONF_OPTS += --disable-codecs-cjk
  93. endif
  94. ifneq ($(BR2_PACKAGE_PYTHON_UNICODEDATA),y)
  95. PYTHON_CONF_OPTS += --disable-unicodedata
  96. endif
  97. # Default is UCS2 w/o a conf opt
  98. ifeq ($(BR2_PACKAGE_PYTHON_UCS4),y)
  99. # host-python must have the same UCS2/4 configuration as the target
  100. # python
  101. HOST_PYTHON_CONF_OPTS += --enable-unicode=ucs4
  102. PYTHON_CONF_OPTS += --enable-unicode=ucs4
  103. endif
  104. ifeq ($(BR2_PACKAGE_PYTHON_2TO3),y)
  105. PYTHON_CONF_OPTS += --enable-lib2to3
  106. else
  107. PYTHON_CONF_OPTS += --disable-lib2to3
  108. endif
  109. ifeq ($(BR2_PACKAGE_PYTHON_BZIP2),y)
  110. PYTHON_DEPENDENCIES += bzip2
  111. else
  112. PYTHON_CONF_OPTS += --disable-bz2
  113. endif
  114. ifeq ($(BR2_PACKAGE_PYTHON_ZLIB),y)
  115. PYTHON_DEPENDENCIES += zlib
  116. else
  117. PYTHON_CONF_OPTS += --disable-zlib
  118. endif
  119. ifeq ($(BR2_PACKAGE_PYTHON_HASHLIB),y)
  120. PYTHON_DEPENDENCIES += openssl
  121. else
  122. PYTHON_CONF_OPTS += --disable-hashlib
  123. endif
  124. ifeq ($(BR2_PACKAGE_PYTHON_OSSAUDIODEV),y)
  125. PYTHON_CONF_OPTS += --enable-ossaudiodev
  126. else
  127. PYTHON_CONF_OPTS += --disable-ossaudiodev
  128. endif
  129. # Make python believe we don't have 'hg' and 'svn', so that it doesn't
  130. # try to communicate over the network during the build.
  131. PYTHON_CONF_ENV += \
  132. ac_cv_have_long_long_format=yes \
  133. ac_cv_file__dev_ptmx=yes \
  134. ac_cv_file__dev_ptc=yes \
  135. ac_cv_working_tzset=yes \
  136. ac_cv_prog_HAS_HG=/bin/false \
  137. ac_cv_prog_SVNVERSION=/bin/false
  138. # GCC is always compliant with IEEE754
  139. ifeq ($(BR2_ENDIAN),"LITTLE")
  140. PYTHON_CONF_ENV += ac_cv_little_endian_double=yes
  141. else
  142. PYTHON_CONF_ENV += ac_cv_big_endian_double=yes
  143. endif
  144. PYTHON_CONF_OPTS += \
  145. --without-cxx-main \
  146. --without-doc-strings \
  147. --with-system-ffi \
  148. --disable-pydoc \
  149. --disable-test-modules \
  150. --disable-gdbm \
  151. --disable-tk \
  152. --disable-nis \
  153. --disable-dbm \
  154. --disable-pyo-build \
  155. --disable-pyc-build
  156. # This is needed to make sure the Python build process doesn't try to
  157. # regenerate those files with the pgen program. Otherwise, it builds
  158. # pgen for the target, and tries to run it on the host.
  159. define PYTHON_TOUCH_GRAMMAR_FILES
  160. touch $(@D)/Include/graminit.h $(@D)/Python/graminit.c
  161. endef
  162. PYTHON_POST_PATCH_HOOKS += PYTHON_TOUCH_GRAMMAR_FILES
  163. #
  164. # Remove useless files. In the config/ directory, only the Makefile
  165. # and the pyconfig.h files are needed at runtime.
  166. #
  167. # idle & smtpd.py have bad shebangs and are mostly samples
  168. #
  169. define PYTHON_REMOVE_USELESS_FILES
  170. rm -f $(TARGET_DIR)/usr/bin/python$(PYTHON_VERSION_MAJOR)-config
  171. rm -f $(TARGET_DIR)/usr/bin/python2-config
  172. rm -f $(TARGET_DIR)/usr/bin/python-config
  173. rm -f $(TARGET_DIR)/usr/bin/smtpd.py
  174. rm -f $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR)/distutils/command/wininst*.exe
  175. for i in `find $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR)/config/ \
  176. -type f -not -name pyconfig.h -a -not -name Makefile` ; do \
  177. rm -f $$i ; \
  178. done
  179. endef
  180. PYTHON_POST_INSTALL_TARGET_HOOKS += PYTHON_REMOVE_USELESS_FILES
  181. #
  182. # Make sure libpython gets stripped out on target
  183. #
  184. define PYTHON_ENSURE_LIBPYTHON_STRIPPED
  185. chmod u+w $(TARGET_DIR)/usr/lib/libpython$(PYTHON_VERSION_MAJOR)*.so
  186. endef
  187. PYTHON_POST_INSTALL_TARGET_HOOKS += PYTHON_ENSURE_LIBPYTHON_STRIPPED
  188. # Always install the python symlink in the target tree
  189. define PYTHON_INSTALL_TARGET_PYTHON_SYMLINK
  190. ln -sf python2 $(TARGET_DIR)/usr/bin/python
  191. endef
  192. 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
  197. PYTHON_POST_INSTALL_STAGING_HOOKS += PYTHON_INSTALL_STAGING_PYTHON_CONFIG_SYMLINK
  198. PYTHON_AUTORECONF = YES
  199. # Some packages may have build scripts requiring python2.
  200. # Only install the python symlink in the host tree if python3 is not enabled
  201. # for the target, otherwise the default python program may be missing.
  202. ifneq ($(BR2_PACKAGE_PYTHON3),y)
  203. define HOST_PYTHON_INSTALL_PYTHON_SYMLINK
  204. ln -sf python2 $(HOST_DIR)/bin/python
  205. ln -sf python2-config $(HOST_DIR)/bin/python-config
  206. endef
  207. HOST_PYTHON_POST_INSTALL_HOOKS += HOST_PYTHON_INSTALL_PYTHON_SYMLINK
  208. endif
  209. # Provided to other packages
  210. PYTHON_PATH = $(STAGING_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR)/sysconfigdata/
  211. $(eval $(autotools-package))
  212. $(eval $(host-autotools-package))
  213. ifeq ($(BR2_REPRODUCIBLE),y)
  214. define PYTHON_FIX_TIME
  215. find $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR) -name '*.py' -print0 | \
  216. xargs -0 --no-run-if-empty touch -d @$(SOURCE_DATE_EPOCH)
  217. endef
  218. endif
  219. define PYTHON_CREATE_PYC_FILES
  220. $(PYTHON_FIX_TIME)
  221. PYTHONPATH="$(PYTHON_PATH)" \
  222. $(HOST_DIR)/bin/python$(PYTHON_VERSION_MAJOR) \
  223. $(TOPDIR)/support/scripts/pycompile.py \
  224. $(if $(VERBOSE),--verbose) \
  225. --strip-root $(TARGET_DIR) \
  226. $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR)
  227. endef
  228. ifeq ($(BR2_PACKAGE_PYTHON_PYC_ONLY)$(BR2_PACKAGE_PYTHON_PY_PYC),y)
  229. PYTHON_TARGET_FINALIZE_HOOKS += PYTHON_CREATE_PYC_FILES
  230. endif
  231. ifeq ($(BR2_PACKAGE_PYTHON_PYC_ONLY),y)
  232. define PYTHON_REMOVE_PY_FILES
  233. find $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR) -name '*.py' \
  234. $(if $(strip $(KEEP_PYTHON_PY_FILES)),-not \( $(call finddirclauses,$(TARGET_DIR),$(KEEP_PYTHON_PY_FILES)) \) ) \
  235. -print0 | \
  236. xargs -0 --no-run-if-empty rm -f
  237. endef
  238. PYTHON_TARGET_FINALIZE_HOOKS += PYTHON_REMOVE_PY_FILES
  239. endif
  240. # Normally, *.pyc files should not have been compiled, but just in
  241. # case, we make sure we remove all of them.
  242. ifeq ($(BR2_PACKAGE_PYTHON_PY_ONLY),y)
  243. define PYTHON_REMOVE_PYC_FILES
  244. find $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR) -name '*.pyc' -print0 | \
  245. xargs -0 --no-run-if-empty rm -f
  246. endef
  247. PYTHON_TARGET_FINALIZE_HOOKS += PYTHON_REMOVE_PYC_FILES
  248. endif
  249. # In all cases, we don't want to keep the optimized .pyo files
  250. define PYTHON_REMOVE_PYO_FILES
  251. find $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR) -name '*.pyo' -print0 | \
  252. xargs -0 --no-run-if-empty rm -f
  253. endef
  254. PYTHON_TARGET_FINALIZE_HOOKS += PYTHON_REMOVE_PYO_FILES