python3.mk 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. ################################################################################
  2. #
  3. # python3
  4. #
  5. ################################################################################
  6. PYTHON3_VERSION_MAJOR = 3.5
  7. PYTHON3_VERSION = $(PYTHON3_VERSION_MAJOR).1
  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. # Make sure that LD_LIBRARY_PATH overrides -rpath.
  37. # This is needed because libpython may be installed at the same time that
  38. # python is called.
  39. HOST_PYTHON3_CONF_ENV += \
  40. LDFLAGS="$(HOST_LDFLAGS) -Wl,--enable-new-dtags"
  41. PYTHON3_DEPENDENCIES = host-python3 libffi
  42. HOST_PYTHON3_DEPENDENCIES = host-expat host-zlib
  43. PYTHON3_INSTALL_STAGING = YES
  44. ifeq ($(BR2_PACKAGE_PYTHON3_READLINE),y)
  45. PYTHON3_DEPENDENCIES += readline
  46. endif
  47. ifeq ($(BR2_PACKAGE_PYTHON3_CURSES),y)
  48. PYTHON3_DEPENDENCIES += ncurses
  49. else
  50. PYTHON3_CONF_OPTS += --disable-curses
  51. endif
  52. ifeq ($(BR2_PACKAGE_PYTHON3_DECIMAL),y)
  53. PYTHON3_DEPENDENCIES += mpdecimal
  54. PYTHON3_CONF_OPTS += --with-libmpdec=system
  55. else
  56. PYTHON3_CONF_OPTS += --with-libmpdec=none
  57. endif
  58. ifeq ($(BR2_PACKAGE_PYTHON3_PYEXPAT),y)
  59. PYTHON3_DEPENDENCIES += expat
  60. PYTHON3_CONF_OPTS += --with-expat=system
  61. else
  62. PYTHON3_CONF_OPTS += --with-expat=none
  63. endif
  64. ifeq ($(BR2_PACKAGE_PYTHON3_PYC_ONLY),y)
  65. PYTHON3_CONF_OPTS += --enable-old-stdlib-cache
  66. endif
  67. ifeq ($(BR2_PACKAGE_PYTHON3_PY_ONLY),y)
  68. PYTHON3_CONF_OPTS += --disable-pyc-build
  69. endif
  70. ifeq ($(BR2_PACKAGE_PYTHON3_SQLITE),y)
  71. PYTHON3_DEPENDENCIES += sqlite
  72. else
  73. PYTHON3_CONF_OPTS += --disable-sqlite3
  74. endif
  75. ifeq ($(BR2_PACKAGE_PYTHON3_SSL),y)
  76. PYTHON3_DEPENDENCIES += openssl
  77. endif
  78. ifneq ($(BR2_PACKAGE_PYTHON3_CODECSCJK),y)
  79. PYTHON3_CONF_OPTS += --disable-codecs-cjk
  80. endif
  81. ifneq ($(BR2_PACKAGE_PYTHON3_UNICODEDATA),y)
  82. PYTHON3_CONF_OPTS += --disable-unicodedata
  83. endif
  84. ifeq ($(BR2_PACKAGE_PYTHON3_BZIP2),y)
  85. PYTHON3_DEPENDENCIES += bzip2
  86. endif
  87. ifeq ($(BR2_PACKAGE_PYTHON3_ZLIB),y)
  88. PYTHON3_DEPENDENCIES += zlib
  89. endif
  90. ifeq ($(BR2_PACKAGE_PYTHON3_OSSAUDIODEV),y)
  91. PYTHON3_CONF_OPTS += --enable-ossaudiodev
  92. else
  93. PYTHON3_CONF_OPTS += --disable-ossaudiodev
  94. endif
  95. PYTHON3_CONF_ENV += \
  96. ac_cv_have_long_long_format=yes \
  97. ac_cv_file__dev_ptmx=yes \
  98. ac_cv_file__dev_ptc=yes \
  99. ac_cv_working_tzset=yes
  100. # uClibc is known to have a broken wcsftime() implementation, so tell
  101. # Python 3 to fall back to strftime() instead.
  102. ifeq ($(BR2_TOOLCHAIN_USES_UCLIBC),y)
  103. PYTHON3_CONF_ENV += ac_cv_func_wcsftime=no
  104. endif
  105. PYTHON3_CONF_OPTS += \
  106. --without-ensurepip \
  107. --without-cxx-main \
  108. --with-system-ffi \
  109. --disable-pydoc \
  110. --disable-test-modules \
  111. --disable-lib2to3 \
  112. --disable-tk \
  113. --disable-nis \
  114. --disable-idle3
  115. # Python builds two tools to generate code: 'pgen' and
  116. # '_freeze_importlib'. Unfortunately, for the target Python, they are
  117. # built for the target, while we need to run them at build time. So
  118. # when installing host-python, we copy them to
  119. # $(HOST_DIR)/usr/bin. And then, when building the target python
  120. # package, we tell the configure script where they are located.
  121. define HOST_PYTHON3_INSTALL_TOOLS
  122. cp $(@D)/Parser/pgen $(HOST_DIR)/usr/bin/python-pgen
  123. cp $(@D)/Programs/_freeze_importlib $(HOST_DIR)/usr/bin/python-freeze-importlib
  124. endef
  125. HOST_PYTHON3_POST_INSTALL_HOOKS += HOST_PYTHON3_INSTALL_TOOLS
  126. PYTHON3_CONF_ENV += \
  127. PGEN_FOR_BUILD=$(HOST_DIR)/usr/bin/python-pgen \
  128. FREEZE_IMPORTLIB_FOR_BUILD=$(HOST_DIR)/usr/bin/python-freeze-importlib
  129. #
  130. # Remove useless files. In the config/ directory, only the Makefile
  131. # and the pyconfig.h files are needed at runtime.
  132. #
  133. define PYTHON3_REMOVE_USELESS_FILES
  134. rm -f $(TARGET_DIR)/usr/bin/python$(PYTHON3_VERSION_MAJOR)-config
  135. rm -f $(TARGET_DIR)/usr/bin/python$(PYTHON3_VERSION_MAJOR)m-config
  136. rm -f $(TARGET_DIR)/usr/bin/python3-config
  137. rm -f $(TARGET_DIR)/usr/bin/smtpd.py.3
  138. for i in `find $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/config-$(PYTHON3_VERSION_MAJOR)m/ \
  139. -type f -not -name pyconfig.h -a -not -name Makefile` ; do \
  140. rm -f $$i ; \
  141. done
  142. rm -rf $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/__pycache__/
  143. rm -rf $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/lib-dynload/sysconfigdata/__pycache__
  144. rm -rf $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/collections/__pycache__
  145. rm -rf $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/importlib/__pycache__
  146. endef
  147. PYTHON3_POST_INSTALL_TARGET_HOOKS += PYTHON3_REMOVE_USELESS_FILES
  148. #
  149. # Make sure libpython gets stripped out on target
  150. #
  151. define PYTHON3_ENSURE_LIBPYTHON_STRIPPED
  152. chmod u+w $(TARGET_DIR)/usr/lib/libpython$(PYTHON3_VERSION_MAJOR)*.so
  153. endef
  154. PYTHON3_POST_INSTALL_TARGET_HOOKS += PYTHON3_ENSURE_LIBPYTHON_STRIPPED
  155. PYTHON3_AUTORECONF = YES
  156. define PYTHON3_INSTALL_SYMLINK
  157. ln -fs python3 $(TARGET_DIR)/usr/bin/python
  158. endef
  159. ifneq ($(BR2_PACKAGE_PYTHON),y)
  160. PYTHON3_POST_INSTALL_TARGET_HOOKS += PYTHON3_INSTALL_SYMLINK
  161. endif
  162. # Some packages may have build scripts requiring python3, whatever is the
  163. # python version chosen for the target.
  164. # Only install the python symlink in the host tree if python3 is enabled
  165. # for the target.
  166. ifeq ($(BR2_PACKAGE_PYTHON3),y)
  167. define HOST_PYTHON3_INSTALL_SYMLINK
  168. ln -fs python3 $(HOST_DIR)/usr/bin/python
  169. ln -fs python3-config $(HOST_DIR)/usr/bin/python-config
  170. endef
  171. HOST_PYTHON3_POST_INSTALL_HOOKS += HOST_PYTHON3_INSTALL_SYMLINK
  172. endif
  173. # Provided to other packages
  174. PYTHON3_PATH = $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/sysconfigdata/:$(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/site-packages/
  175. $(eval $(autotools-package))
  176. $(eval $(host-autotools-package))
  177. ifeq ($(BR2_PACKAGE_PYTHON3_PYC_ONLY),y)
  178. define PYTHON3_REMOVE_PY_FILES
  179. find $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR) -name '*.py' -print0 | xargs -0 rm -f
  180. endef
  181. TARGET_FINALIZE_HOOKS += PYTHON3_REMOVE_PY_FILES
  182. endif
  183. ifeq ($(BR2_PACKAGE_PYTHON3_PY_ONLY),y)
  184. define PYTHON3_REMOVE_PYC_FILES
  185. find $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR) -name '*.pyc' -print0 | xargs -0 rm -f
  186. endef
  187. TARGET_FINALIZE_HOOKS += PYTHON3_REMOVE_PYC_FILES
  188. endif
  189. # In all cases, we don't want to keep the optimized .opt-1.pyc and
  190. # .opt-2.pyc files, since they can't work without their non-optimized
  191. # variant.
  192. ifeq ($(BR2_PACKAGE_PYTHON3),y)
  193. define PYTHON3_REMOVE_OPTIMIZED_PYC_FILES
  194. find $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR) -name '*.opt-1.pyc' -print0 -o -name '*.opt-2.pyc' -print0 | xargs -0 rm -f
  195. endef
  196. TARGET_FINALIZE_HOOKS += PYTHON3_REMOVE_OPTIMIZED_PYC_FILES
  197. endif