2
1

python.mk 6.2 KB

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