python.mk 8.6 KB

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