python.mk 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. ################################################################################
  2. #
  3. # python
  4. #
  5. ################################################################################
  6. PYTHON_VERSION_MAJOR = 2.7
  7. PYTHON_VERSION = $(PYTHON_VERSION_MAJOR).13
  8. PYTHON_SOURCE = Python-$(PYTHON_VERSION).tar.xz
  9. PYTHON_SITE = http://python.org/ftp/python/$(PYTHON_VERSION)
  10. PYTHON_LICENSE = Python software foundation license v2, 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-ssl \
  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
  52. HOST_PYTHON_DEPENDENCIES = host-expat host-zlib
  53. PYTHON_INSTALL_STAGING = YES
  54. ifeq ($(BR2_PACKAGE_PYTHON_READLINE),y)
  55. PYTHON_DEPENDENCIES += readline
  56. endif
  57. ifeq ($(BR2_PACKAGE_PYTHON_CURSES),y)
  58. PYTHON_DEPENDENCIES += ncurses
  59. else
  60. PYTHON_CONF_OPTS += --disable-curses
  61. endif
  62. ifeq ($(BR2_PACKAGE_PYTHON_PYEXPAT),y)
  63. PYTHON_DEPENDENCIES += expat
  64. PYTHON_CONF_OPTS += --with-expat=system
  65. else
  66. PYTHON_CONF_OPTS += --with-expat=none
  67. endif
  68. ifeq ($(BR2_PACKAGE_PYTHON_BSDDB),y)
  69. PYTHON_DEPENDENCIES += berkeleydb
  70. else
  71. PYTHON_CONF_OPTS += --disable-bsddb
  72. endif
  73. ifeq ($(BR2_PACKAGE_PYTHON_SQLITE),y)
  74. PYTHON_DEPENDENCIES += sqlite
  75. else
  76. PYTHON_CONF_OPTS += --disable-sqlite3
  77. endif
  78. ifeq ($(BR2_PACKAGE_PYTHON_SSL),y)
  79. PYTHON_DEPENDENCIES += openssl
  80. else
  81. PYTHON_CONF_OPTS += --disable-ssl
  82. endif
  83. ifneq ($(BR2_PACKAGE_PYTHON_CODECSCJK),y)
  84. PYTHON_CONF_OPTS += --disable-codecs-cjk
  85. endif
  86. ifneq ($(BR2_PACKAGE_PYTHON_UNICODEDATA),y)
  87. PYTHON_CONF_OPTS += --disable-unicodedata
  88. endif
  89. # Default is UCS2 w/o a conf opt
  90. ifeq ($(BR2_PACKAGE_PYTHON_UCS4),y)
  91. # host-python must have the same UCS2/4 configuration as the target
  92. # python
  93. HOST_PYTHON_CONF_OPTS += --enable-unicode=ucs4
  94. PYTHON_CONF_OPTS += --enable-unicode=ucs4
  95. endif
  96. ifeq ($(BR2_PACKAGE_PYTHON_BZIP2),y)
  97. PYTHON_DEPENDENCIES += bzip2
  98. else
  99. PYTHON_CONF_OPTS += --disable-bz2
  100. endif
  101. ifeq ($(BR2_PACKAGE_PYTHON_ZLIB),y)
  102. PYTHON_DEPENDENCIES += zlib
  103. else
  104. PYTHON_CONF_OPTS += --disable-zlib
  105. endif
  106. ifeq ($(BR2_PACKAGE_PYTHON_HASHLIB),y)
  107. PYTHON_DEPENDENCIES += openssl
  108. endif
  109. ifeq ($(BR2_PACKAGE_PYTHON_OSSAUDIODEV),y)
  110. PYTHON_CONF_OPTS += --enable-ossaudiodev
  111. else
  112. PYTHON_CONF_OPTS += --disable-ossaudiodev
  113. endif
  114. # Make python believe we don't have 'hg' and 'svn', so that it doesn't
  115. # try to communicate over the network during the build.
  116. PYTHON_CONF_ENV += \
  117. ac_cv_have_long_long_format=yes \
  118. ac_cv_file__dev_ptmx=yes \
  119. ac_cv_file__dev_ptc=yes \
  120. ac_cv_working_tzset=yes \
  121. ac_cv_prog_HAS_HG=/bin/false \
  122. ac_cv_prog_SVNVERSION=/bin/false
  123. # GCC is always compliant with IEEE754
  124. ifeq ($(BR2_ENDIAN),"LITTLE")
  125. PYTHON_CONF_ENV += ac_cv_little_endian_double=yes
  126. else
  127. PYTHON_CONF_ENV += ac_cv_big_endian_double=yes
  128. endif
  129. PYTHON_CONF_OPTS += \
  130. --without-cxx-main \
  131. --without-doc-strings \
  132. --with-system-ffi \
  133. --disable-pydoc \
  134. --disable-test-modules \
  135. --disable-lib2to3 \
  136. --disable-gdbm \
  137. --disable-tk \
  138. --disable-nis \
  139. --disable-dbm \
  140. --disable-pyo-build \
  141. --disable-pyc-build
  142. # This is needed to make sure the Python build process doesn't try to
  143. # regenerate those files with the pgen program. Otherwise, it builds
  144. # pgen for the target, and tries to run it on the host.
  145. define PYTHON_TOUCH_GRAMMAR_FILES
  146. touch $(@D)/Include/graminit.h $(@D)/Python/graminit.c
  147. endef
  148. PYTHON_POST_PATCH_HOOKS += PYTHON_TOUCH_GRAMMAR_FILES
  149. #
  150. # Remove useless files. In the config/ directory, only the Makefile
  151. # and the pyconfig.h files are needed at runtime.
  152. #
  153. # idle & smtpd.py have bad shebangs and are mostly samples
  154. #
  155. define PYTHON_REMOVE_USELESS_FILES
  156. rm -f $(TARGET_DIR)/usr/bin/python$(PYTHON_VERSION_MAJOR)-config
  157. rm -f $(TARGET_DIR)/usr/bin/python2-config
  158. rm -f $(TARGET_DIR)/usr/bin/python-config
  159. rm -f $(TARGET_DIR)/usr/bin/smtpd.py
  160. for i in `find $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR)/config/ \
  161. -type f -not -name pyconfig.h -a -not -name Makefile` ; do \
  162. rm -f $$i ; \
  163. done
  164. endef
  165. PYTHON_POST_INSTALL_TARGET_HOOKS += PYTHON_REMOVE_USELESS_FILES
  166. #
  167. # Make sure libpython gets stripped out on target
  168. #
  169. define PYTHON_ENSURE_LIBPYTHON_STRIPPED
  170. chmod u+w $(TARGET_DIR)/usr/lib/libpython$(PYTHON_VERSION_MAJOR)*.so
  171. endef
  172. PYTHON_POST_INSTALL_TARGET_HOOKS += PYTHON_ENSURE_LIBPYTHON_STRIPPED
  173. # Always install the python symlink in the target tree
  174. define PYTHON_INSTALL_TARGET_PYTHON_SYMLINK
  175. ln -sf python2 $(TARGET_DIR)/usr/bin/python
  176. endef
  177. PYTHON_POST_INSTALL_TARGET_HOOKS += PYTHON_INSTALL_TARGET_PYTHON_SYMLINK
  178. # Always install the python-config symlink in the staging tree
  179. define PYTHON_INSTALL_STAGING_PYTHON_CONFIG_SYMLINK
  180. ln -sf python2-config $(STAGING_DIR)/usr/bin/python-config
  181. endef
  182. PYTHON_POST_INSTALL_STAGING_HOOKS += PYTHON_INSTALL_STAGING_PYTHON_CONFIG_SYMLINK
  183. PYTHON_AUTORECONF = YES
  184. # Some packages may have build scripts requiring python2.
  185. # Only install the python symlink in the host tree if python3 is not enabled
  186. # for the target, otherwise the default python program may be missing.
  187. ifneq ($(BR2_PACKAGE_PYTHON3),y)
  188. define HOST_PYTHON_INSTALL_PYTHON_SYMLINK
  189. ln -sf python2 $(HOST_DIR)/usr/bin/python
  190. ln -sf python2-config $(HOST_DIR)/usr/bin/python-config
  191. endef
  192. HOST_PYTHON_POST_INSTALL_HOOKS += HOST_PYTHON_INSTALL_PYTHON_SYMLINK
  193. endif
  194. # Provided to other packages
  195. PYTHON_PATH = $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR)/sysconfigdata/:$(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR)/site-packages/
  196. $(eval $(autotools-package))
  197. $(eval $(host-autotools-package))
  198. define PYTHON_CREATE_PYC_FILES
  199. PYTHONPATH="$(PYTHON_PATH)" \
  200. $(HOST_DIR)/usr/bin/python$(PYTHON_VERSION_MAJOR) \
  201. support/scripts/pycompile.py \
  202. $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR)
  203. endef
  204. ifeq ($(BR2_PACKAGE_PYTHON_PYC_ONLY)$(BR2_PACKAGE_PYTHON_PY_PYC),y)
  205. PYTHON_TARGET_FINALIZE_HOOKS += PYTHON_CREATE_PYC_FILES
  206. endif
  207. ifeq ($(BR2_PACKAGE_PYTHON_PYC_ONLY),y)
  208. define PYTHON_REMOVE_PY_FILES
  209. find $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR) -name '*.py' -print0 | \
  210. xargs -0 --no-run-if-empty rm -f
  211. endef
  212. PYTHON_TARGET_FINALIZE_HOOKS += PYTHON_REMOVE_PY_FILES
  213. endif
  214. # Normally, *.pyc files should not have been compiled, but just in
  215. # case, we make sure we remove all of them.
  216. ifeq ($(BR2_PACKAGE_PYTHON_PY_ONLY),y)
  217. define PYTHON_REMOVE_PYC_FILES
  218. find $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR) -name '*.pyc' -print0 | \
  219. xargs -0 --no-run-if-empty rm -f
  220. endef
  221. PYTHON_TARGET_FINALIZE_HOOKS += PYTHON_REMOVE_PYC_FILES
  222. endif
  223. # In all cases, we don't want to keep the optimized .pyo files
  224. define PYTHON_REMOVE_PYO_FILES
  225. find $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR) -name '*.pyo' -print0 | \
  226. xargs -0 --no-run-if-empty rm -f
  227. endef
  228. PYTHON_TARGET_FINALIZE_HOOKS += PYTHON_REMOVE_PYO_FILES