python.mk 8.6 KB

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