python3.mk 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. ################################################################################
  2. #
  3. # python3
  4. #
  5. ################################################################################
  6. PYTHON3_VERSION_MAJOR = 3.4
  7. PYTHON3_VERSION = $(PYTHON3_VERSION_MAJOR).3
  8. PYTHON3_SOURCE = Python-$(PYTHON3_VERSION).tar.xz
  9. PYTHON3_SITE = http://python.org/ftp/python/$(PYTHON3_VERSION)
  10. PYTHON3_LICENSE = Python software foundation license v2, others
  11. PYTHON3_LICENSE_FILES = LICENSE
  12. # Python itself doesn't use libtool, but it includes the source code
  13. # of libffi, which uses libtool. Unfortunately, it uses a beta version
  14. # of libtool for which we don't have a matching patch. However, this
  15. # is not a problem, because we don't use the libffi copy included in
  16. # the Python sources, but instead use an external libffi library.
  17. PYTHON3_LIBTOOL_PATCH = NO
  18. # Python needs itself and a "pgen" program to build itself, both being
  19. # provided in the Python sources. So in order to cross-compile Python,
  20. # we need to build a host Python first. This host Python is also
  21. # installed in $(HOST_DIR), as it is needed when cross-compiling
  22. # third-party Python modules.
  23. HOST_PYTHON3_CONF_OPTS += \
  24. --without-ensurepip \
  25. --without-cxx-main \
  26. --disable-sqlite3 \
  27. --disable-tk \
  28. --with-expat=system \
  29. --disable-curses \
  30. --disable-codecs-cjk \
  31. --disable-nis \
  32. --enable-unicodedata \
  33. --disable-test-modules \
  34. --disable-idle3 \
  35. --disable-ossaudiodev \
  36. --disable-pyo-build
  37. # Make sure that LD_LIBRARY_PATH overrides -rpath.
  38. # This is needed because libpython may be installed at the same time that
  39. # python is called.
  40. HOST_PYTHON3_CONF_ENV += \
  41. LDFLAGS="$(HOST_LDFLAGS) -Wl,--enable-new-dtags"
  42. PYTHON3_DEPENDENCIES = host-python3 libffi
  43. HOST_PYTHON3_DEPENDENCIES = host-expat host-zlib
  44. PYTHON3_INSTALL_STAGING = YES
  45. ifeq ($(BR2_PACKAGE_PYTHON3_READLINE),y)
  46. PYTHON3_DEPENDENCIES += readline
  47. endif
  48. ifeq ($(BR2_PACKAGE_PYTHON3_CURSES),y)
  49. PYTHON3_DEPENDENCIES += ncurses
  50. else
  51. PYTHON3_CONF_OPTS += --disable-curses
  52. endif
  53. ifeq ($(BR2_PACKAGE_PYTHON3_DECIMAL),y)
  54. PYTHON3_DEPENDENCIES += mpdecimal
  55. PYTHON3_CONF_OPTS += --with-libmpdec=system
  56. else
  57. PYTHON3_CONF_OPTS += --with-libmpdec=none
  58. endif
  59. ifeq ($(BR2_PACKAGE_PYTHON3_PYEXPAT),y)
  60. PYTHON3_DEPENDENCIES += expat
  61. PYTHON3_CONF_OPTS += --with-expat=system
  62. else
  63. PYTHON3_CONF_OPTS += --with-expat=none
  64. endif
  65. ifeq ($(BR2_PACKAGE_PYTHON3_PYC_ONLY),y)
  66. PYTHON3_CONF_OPTS += --enable-old-stdlib-cache
  67. endif
  68. ifeq ($(BR2_PACKAGE_PYTHON3_PY_ONLY),y)
  69. PYTHON3_CONF_OPTS += --disable-pyc-build
  70. endif
  71. ifeq ($(BR2_PACKAGE_PYTHON3_SQLITE),y)
  72. PYTHON3_DEPENDENCIES += sqlite
  73. else
  74. PYTHON3_CONF_OPTS += --disable-sqlite3
  75. endif
  76. ifeq ($(BR2_PACKAGE_PYTHON3_SSL),y)
  77. PYTHON3_DEPENDENCIES += openssl
  78. endif
  79. ifneq ($(BR2_PACKAGE_PYTHON3_CODECSCJK),y)
  80. PYTHON3_CONF_OPTS += --disable-codecs-cjk
  81. endif
  82. ifneq ($(BR2_PACKAGE_PYTHON3_UNICODEDATA),y)
  83. PYTHON3_CONF_OPTS += --disable-unicodedata
  84. endif
  85. ifeq ($(BR2_PACKAGE_PYTHON3_BZIP2),y)
  86. PYTHON3_DEPENDENCIES += bzip2
  87. endif
  88. ifeq ($(BR2_PACKAGE_PYTHON3_ZLIB),y)
  89. PYTHON3_DEPENDENCIES += zlib
  90. endif
  91. ifeq ($(BR2_PACKAGE_PYTHON3_OSSAUDIODEV),y)
  92. PYTHON3_CONF_OPTS += --enable-ossaudiodev
  93. else
  94. PYTHON3_CONF_OPTS += --disable-ossaudiodev
  95. endif
  96. PYTHON3_CONF_ENV += \
  97. ac_cv_have_long_long_format=yes \
  98. ac_cv_file__dev_ptmx=yes \
  99. ac_cv_file__dev_ptc=yes \
  100. ac_cv_working_tzset=yes
  101. # uClibc is known to have a broken wcsftime() implementation, so tell
  102. # Python 3 to fall back to strftime() instead.
  103. ifeq ($(BR2_TOOLCHAIN_USES_UCLIBC),y)
  104. PYTHON3_CONF_ENV += ac_cv_func_wcsftime=no
  105. endif
  106. PYTHON3_CONF_OPTS += \
  107. --without-ensurepip \
  108. --without-cxx-main \
  109. --with-system-ffi \
  110. --disable-pydoc \
  111. --disable-test-modules \
  112. --disable-lib2to3 \
  113. --disable-tk \
  114. --disable-nis \
  115. --disable-idle3 \
  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 PYTHON3_TOUCH_GRAMMAR_FILES
  121. touch $(@D)/Include/graminit.h $(@D)/Python/graminit.c
  122. endef
  123. PYTHON3_POST_PATCH_HOOKS += PYTHON3_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. define PYTHON3_REMOVE_USELESS_FILES
  129. rm -f $(TARGET_DIR)/usr/bin/python$(PYTHON3_VERSION_MAJOR)-config
  130. rm -f $(TARGET_DIR)/usr/bin/python$(PYTHON3_VERSION_MAJOR)m-config
  131. rm -f $(TARGET_DIR)/usr/bin/python3-config
  132. rm -f $(TARGET_DIR)/usr/bin/smtpd.py.3
  133. for i in `find $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/config-$(PYTHON3_VERSION_MAJOR)m/ \
  134. -type f -not -name pyconfig.h -a -not -name Makefile` ; do \
  135. rm -f $$i ; \
  136. done
  137. rm -rf $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/__pycache__/
  138. rm -rf $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/lib-dynload/sysconfigdata/__pycache__
  139. rm -rf $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/collections/__pycache__
  140. rm -rf $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/importlib/__pycache__
  141. endef
  142. PYTHON3_POST_INSTALL_TARGET_HOOKS += PYTHON3_REMOVE_USELESS_FILES
  143. #
  144. # Make sure libpython gets stripped out on target
  145. #
  146. define PYTHON3_ENSURE_LIBPYTHON_STRIPPED
  147. chmod u+w $(TARGET_DIR)/usr/lib/libpython$(PYTHON3_VERSION_MAJOR)*.so
  148. endef
  149. PYTHON3_POST_INSTALL_TARGET_HOOKS += PYTHON3_ENSURE_LIBPYTHON_STRIPPED
  150. PYTHON3_AUTORECONF = YES
  151. define PYTHON3_INSTALL_SYMLINK
  152. ln -fs python3 $(TARGET_DIR)/usr/bin/python
  153. endef
  154. ifneq ($(BR2_PACKAGE_PYTHON),y)
  155. PYTHON3_POST_INSTALL_TARGET_HOOKS += PYTHON3_INSTALL_SYMLINK
  156. endif
  157. # Some packages may have build scripts requiring python3, whatever is the
  158. # python version chosen for the target.
  159. # Only install the python symlink in the host tree if python3 is enabled
  160. # for the target.
  161. ifeq ($(BR2_PACKAGE_PYTHON3),y)
  162. define HOST_PYTHON3_INSTALL_SYMLINK
  163. ln -fs python3 $(HOST_DIR)/usr/bin/python
  164. ln -fs python3-config $(HOST_DIR)/usr/bin/python-config
  165. endef
  166. HOST_PYTHON3_POST_INSTALL_HOOKS += HOST_PYTHON3_INSTALL_SYMLINK
  167. endif
  168. # Provided to other packages
  169. PYTHON3_PATH = $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/sysconfigdata/:$(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/site-packages/
  170. $(eval $(autotools-package))
  171. $(eval $(host-autotools-package))
  172. ifeq ($(BR2_PACKAGE_PYTHON3_PYC_ONLY),y)
  173. define PYTHON3_FINALIZE_TARGET
  174. find $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR) -name '*.py' -print0 | xargs -0 rm -f
  175. endef
  176. endif
  177. ifeq ($(BR2_PACKAGE_PYTHON3_PY_ONLY),y)
  178. define PYTHON3_FINALIZE_TARGET
  179. find $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR) -name '*.pyc' -print0 | xargs -0 rm -f
  180. endef
  181. endif
  182. TARGET_FINALIZE_HOOKS += PYTHON3_FINALIZE_TARGET