python.mk 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. ################################################################################
  2. #
  3. # python
  4. #
  5. ################################################################################
  6. PYTHON_VERSION_MAJOR = 2.7
  7. PYTHON_VERSION = $(PYTHON_VERSION_MAJOR).8
  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 needs itself to be built, so in order to cross-compile
  13. # Python, we need to build a host Python first. This host Python is
  14. # also installed in $(HOST_DIR), as it is needed when cross-compiling
  15. # third-party Python modules.
  16. HOST_PYTHON_CONF_OPTS += \
  17. --enable-static \
  18. --without-cxx-main \
  19. --disable-sqlite3 \
  20. --disable-tk \
  21. --with-expat=system \
  22. --disable-curses \
  23. --disable-codecs-cjk \
  24. --disable-nis \
  25. --enable-unicodedata \
  26. --disable-dbm \
  27. --disable-gdbm \
  28. --disable-bsddb \
  29. --disable-test-modules \
  30. --disable-bz2 \
  31. --disable-ssl \
  32. --disable-pyo-build
  33. # Make sure that LD_LIBRARY_PATH overrides -rpath.
  34. # This is needed because libpython may be installed at the same time that
  35. # python is called.
  36. HOST_PYTHON_CONF_ENV += \
  37. LDFLAGS="$(HOST_LDFLAGS) -Wl,--enable-new-dtags"
  38. # Building host python in parallel sometimes triggers a "Bus error"
  39. # during the execution of "./python setup.py build" in the
  40. # installation step. It is probably due to the installation of a
  41. # shared library taking place in parallel to the execution of
  42. # ./python, causing spurious Bus error. Building host-python with
  43. # MAKE1 has shown to workaround the problem.
  44. HOST_PYTHON_MAKE = $(MAKE1)
  45. PYTHON_DEPENDENCIES = host-python libffi
  46. HOST_PYTHON_DEPENDENCIES = host-expat host-zlib
  47. PYTHON_INSTALL_STAGING = YES
  48. ifeq ($(BR2_PACKAGE_PYTHON_READLINE),y)
  49. PYTHON_DEPENDENCIES += readline
  50. endif
  51. ifeq ($(BR2_PACKAGE_PYTHON_CURSES),y)
  52. PYTHON_DEPENDENCIES += ncurses
  53. else
  54. PYTHON_CONF_OPTS += --disable-curses
  55. endif
  56. ifeq ($(BR2_PACKAGE_PYTHON_PYEXPAT),y)
  57. PYTHON_DEPENDENCIES += expat
  58. PYTHON_CONF_OPTS += --with-expat=system
  59. else
  60. PYTHON_CONF_OPTS += --with-expat=none
  61. endif
  62. ifeq ($(BR2_PACKAGE_PYTHON_BSDDB),y)
  63. PYTHON_DEPENDENCIES += berkeleydb
  64. else
  65. PYTHON_CONF_OPTS += --disable-bsddb
  66. endif
  67. ifeq ($(BR2_PACKAGE_PYTHON_SQLITE),y)
  68. PYTHON_DEPENDENCIES += sqlite
  69. else
  70. PYTHON_CONF_OPTS += --disable-sqlite3
  71. endif
  72. ifeq ($(BR2_PACKAGE_PYTHON_SSL),y)
  73. PYTHON_DEPENDENCIES += openssl
  74. else
  75. PYTHON_CONF_OPTS += --disable-ssl
  76. endif
  77. ifneq ($(BR2_PACKAGE_PYTHON_CODECSCJK),y)
  78. PYTHON_CONF_OPTS += --disable-codecs-cjk
  79. endif
  80. ifneq ($(BR2_PACKAGE_PYTHON_UNICODEDATA),y)
  81. PYTHON_CONF_OPTS += --disable-unicodedata
  82. endif
  83. # Default is UCS2 w/o a conf opt
  84. ifeq ($(BR2_PACKAGE_PYTHON_UCS4),y)
  85. PYTHON_CONF_OPTS += --enable-unicode=ucs4
  86. endif
  87. ifeq ($(BR2_PACKAGE_PYTHON_BZIP2),y)
  88. PYTHON_DEPENDENCIES += bzip2
  89. else
  90. PYTHON_CONF_OPTS += --disable-bz2
  91. endif
  92. ifeq ($(BR2_PACKAGE_PYTHON_ZLIB),y)
  93. PYTHON_DEPENDENCIES += zlib
  94. else
  95. PYTHON_CONF_OPTS += --disable-zlib
  96. endif
  97. ifeq ($(BR2_PACKAGE_PYTHON_HASHLIB),y)
  98. PYTHON_DEPENDENCIES += openssl
  99. endif
  100. PYTHON_CONF_ENV += \
  101. ac_cv_have_long_long_format=yes \
  102. ac_cv_file__dev_ptmx=yes \
  103. ac_cv_file__dev_ptc=yes \
  104. ac_cv_working_tzset=yes
  105. PYTHON_CONF_OPTS += \
  106. --without-cxx-main \
  107. --without-doc-strings \
  108. --with-system-ffi \
  109. --disable-pydoc \
  110. --disable-test-modules \
  111. --disable-lib2to3 \
  112. --disable-gdbm \
  113. --disable-tk \
  114. --disable-nis \
  115. --disable-dbm \
  116. --disable-pyo-build
  117. # This is needed to make sure the Python build process doesn't try to
  118. # regenerate those files with the pgen program. Otherwise, it builds
  119. # pgen for the target, and tries to run it on the host.
  120. define PYTHON_TOUCH_GRAMMAR_FILES
  121. touch $(@D)/Include/graminit.h $(@D)/Python/graminit.c
  122. endef
  123. PYTHON_POST_PATCH_HOOKS += PYTHON_TOUCH_GRAMMAR_FILES
  124. #
  125. # Remove useless files. In the config/ directory, only the Makefile
  126. # and the pyconfig.h files are needed at runtime.
  127. #
  128. # idle & smtpd.py have bad shebangs and are mostly samples
  129. #
  130. define PYTHON_REMOVE_USELESS_FILES
  131. rm -f $(TARGET_DIR)/usr/bin/python$(PYTHON_VERSION_MAJOR)-config
  132. rm -f $(TARGET_DIR)/usr/bin/python2-config
  133. rm -f $(TARGET_DIR)/usr/bin/python-config
  134. rm -f $(TARGET_DIR)/usr/bin/smtpd.py
  135. for i in `find $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR)/config/ \
  136. -type f -not -name pyconfig.h -a -not -name Makefile` ; do \
  137. rm -f $$i ; \
  138. done
  139. endef
  140. PYTHON_POST_INSTALL_TARGET_HOOKS += PYTHON_REMOVE_USELESS_FILES
  141. #
  142. # Make sure libpython gets stripped out on target
  143. #
  144. define PYTHON_ENSURE_LIBPYTHON_STRIPPED
  145. chmod u+w $(TARGET_DIR)/usr/lib/libpython$(PYTHON_VERSION_MAJOR)*.so
  146. endef
  147. PYTHON_POST_INSTALL_TARGET_HOOKS += PYTHON_ENSURE_LIBPYTHON_STRIPPED
  148. # Always install the python symlink in the target tree
  149. define PYTHON_INSTALL_TARGET_PYTHON_SYMLINK
  150. ln -sf python2 $(TARGET_DIR)/usr/bin/python
  151. endef
  152. PYTHON_POST_INSTALL_TARGET_HOOKS += PYTHON_INSTALL_TARGET_PYTHON_SYMLINK
  153. # Always install the python-config symlink in the staging tree
  154. define PYTHON_INSTALL_STAGING_PYTHON_CONFIG_SYMLINK
  155. ln -sf python2-config $(STAGING_DIR)/usr/bin/python-config
  156. endef
  157. PYTHON_POST_INSTALL_STAGING_HOOKS += PYTHON_INSTALL_STAGING_PYTHON_CONFIG_SYMLINK
  158. PYTHON_AUTORECONF = YES
  159. # Some packages may have build scripts requiring python2.
  160. # Only install the python symlink in the host tree if python3 is not enabled
  161. # for the target, otherwise the default python program may be missing.
  162. ifneq ($(BR2_PACKAGE_PYTHON3),y)
  163. define HOST_PYTHON_INSTALL_PYTHON_SYMLINK
  164. ln -sf python2 $(HOST_DIR)/usr/bin/python
  165. ln -sf python2-config $(HOST_DIR)/usr/bin/python-config
  166. endef
  167. HOST_PYTHON_POST_INSTALL_HOOKS += HOST_PYTHON_INSTALL_PYTHON_SYMLINK
  168. endif
  169. # Provided to other packages
  170. PYTHON_PATH = $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR)/sysconfigdata/:$(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR)/site-packages/
  171. $(eval $(autotools-package))
  172. $(eval $(host-autotools-package))
  173. ifeq ($(BR2_PACKAGE_PYTHON_PYC_ONLY),y)
  174. define PYTHON_FINALIZE_TARGET
  175. find $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR) -name '*.py' -print0 | xargs -0 rm -f
  176. endef
  177. endif
  178. ifeq ($(BR2_PACKAGE_PYTHON_PY_ONLY),y)
  179. define PYTHON_FINALIZE_TARGET
  180. find $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR) -name '*.pyc' -print0 | xargs -0 rm -f
  181. endef
  182. endif
  183. TARGET_FINALIZE_HOOKS += PYTHON_FINALIZE_TARGET