python.mk 6.4 KB

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