python3.mk 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. ################################################################################
  2. #
  3. # python3
  4. #
  5. ################################################################################
  6. PYTHON3_VERSION_MAJOR = 3.5
  7. PYTHON3_VERSION = $(PYTHON3_VERSION_MAJOR).2
  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. # Make python believe we don't have 'hg', so that it doesn't try to
  40. # communicate over the network during the build.
  41. HOST_PYTHON3_CONF_ENV += \
  42. LDFLAGS="$(HOST_LDFLAGS) -Wl,--enable-new-dtags" \
  43. ac_cv_prog_HAS_HG=/bin/false
  44. PYTHON3_DEPENDENCIES = host-python3 libffi
  45. HOST_PYTHON3_DEPENDENCIES = host-expat host-zlib
  46. PYTHON3_INSTALL_STAGING = YES
  47. ifeq ($(BR2_PACKAGE_PYTHON3_READLINE),y)
  48. PYTHON3_DEPENDENCIES += readline
  49. endif
  50. ifeq ($(BR2_PACKAGE_PYTHON3_CURSES),y)
  51. PYTHON3_DEPENDENCIES += ncurses
  52. else
  53. PYTHON3_CONF_OPTS += --disable-curses
  54. endif
  55. ifeq ($(BR2_PACKAGE_PYTHON3_DECIMAL),y)
  56. PYTHON3_DEPENDENCIES += mpdecimal
  57. PYTHON3_CONF_OPTS += --with-libmpdec=system
  58. else
  59. PYTHON3_CONF_OPTS += --with-libmpdec=none
  60. endif
  61. ifeq ($(BR2_PACKAGE_PYTHON3_PYEXPAT),y)
  62. PYTHON3_DEPENDENCIES += expat
  63. PYTHON3_CONF_OPTS += --with-expat=system
  64. else
  65. PYTHON3_CONF_OPTS += --with-expat=none
  66. endif
  67. ifeq ($(BR2_PACKAGE_PYTHON3_PYC_ONLY),y)
  68. PYTHON3_CONF_OPTS += --enable-old-stdlib-cache
  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_XZ),y)
  88. PYTHON3_DEPENDENCIES += xz
  89. endif
  90. ifeq ($(BR2_PACKAGE_PYTHON3_ZLIB),y)
  91. PYTHON3_DEPENDENCIES += zlib
  92. endif
  93. ifeq ($(BR2_PACKAGE_PYTHON3_OSSAUDIODEV),y)
  94. PYTHON3_CONF_OPTS += --enable-ossaudiodev
  95. else
  96. PYTHON3_CONF_OPTS += --disable-ossaudiodev
  97. endif
  98. # Make python believe we don't have 'hg', so that it doesn't try to
  99. # communicate over the network during the build.
  100. PYTHON3_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. ac_cv_prog_HAS_HG=/bin/false
  106. # GCC is always compliant with IEEE754
  107. ifeq ($(BR2_ENDIAN),"LITTLE")
  108. PYTHON3_CONF_ENV += ac_cv_little_endian_double=yes
  109. else
  110. PYTHON3_CONF_ENV += ac_cv_big_endian_double=yes
  111. endif
  112. # uClibc is known to have a broken wcsftime() implementation, so tell
  113. # Python 3 to fall back to strftime() instead.
  114. ifeq ($(BR2_TOOLCHAIN_USES_UCLIBC),y)
  115. PYTHON3_CONF_ENV += ac_cv_func_wcsftime=no
  116. endif
  117. PYTHON3_CONF_OPTS += \
  118. --without-ensurepip \
  119. --without-cxx-main \
  120. --with-system-ffi \
  121. --disable-pydoc \
  122. --disable-test-modules \
  123. --disable-lib2to3 \
  124. --disable-tk \
  125. --disable-nis \
  126. --disable-idle3 \
  127. --disable-pyc-build
  128. # Python builds two tools to generate code: 'pgen' and
  129. # '_freeze_importlib'. Unfortunately, for the target Python, they are
  130. # built for the target, while we need to run them at build time. So
  131. # when installing host-python, we copy them to
  132. # $(HOST_DIR)/usr/bin. And then, when building the target python
  133. # package, we tell the configure script where they are located.
  134. define HOST_PYTHON3_INSTALL_TOOLS
  135. cp $(@D)/Parser/pgen $(HOST_DIR)/usr/bin/python-pgen
  136. cp $(@D)/Programs/_freeze_importlib $(HOST_DIR)/usr/bin/python-freeze-importlib
  137. endef
  138. HOST_PYTHON3_POST_INSTALL_HOOKS += HOST_PYTHON3_INSTALL_TOOLS
  139. PYTHON3_CONF_ENV += \
  140. PGEN_FOR_BUILD=$(HOST_DIR)/usr/bin/python-pgen \
  141. FREEZE_IMPORTLIB_FOR_BUILD=$(HOST_DIR)/usr/bin/python-freeze-importlib
  142. #
  143. # Remove useless files. In the config/ directory, only the Makefile
  144. # and the pyconfig.h files are needed at runtime.
  145. #
  146. define PYTHON3_REMOVE_USELESS_FILES
  147. rm -f $(TARGET_DIR)/usr/bin/python$(PYTHON3_VERSION_MAJOR)-config
  148. rm -f $(TARGET_DIR)/usr/bin/python$(PYTHON3_VERSION_MAJOR)m-config
  149. rm -f $(TARGET_DIR)/usr/bin/python3-config
  150. rm -f $(TARGET_DIR)/usr/bin/smtpd.py.3
  151. for i in `find $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/config-$(PYTHON3_VERSION_MAJOR)m/ \
  152. -type f -not -name pyconfig.h -a -not -name Makefile` ; do \
  153. rm -f $$i ; \
  154. done
  155. rm -rf $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/__pycache__/
  156. rm -rf $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/lib-dynload/sysconfigdata/__pycache__
  157. rm -rf $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/collections/__pycache__
  158. rm -rf $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/importlib/__pycache__
  159. endef
  160. PYTHON3_POST_INSTALL_TARGET_HOOKS += PYTHON3_REMOVE_USELESS_FILES
  161. #
  162. # Make sure libpython gets stripped out on target
  163. #
  164. define PYTHON3_ENSURE_LIBPYTHON_STRIPPED
  165. chmod u+w $(TARGET_DIR)/usr/lib/libpython$(PYTHON3_VERSION_MAJOR)*.so
  166. endef
  167. PYTHON3_POST_INSTALL_TARGET_HOOKS += PYTHON3_ENSURE_LIBPYTHON_STRIPPED
  168. PYTHON3_AUTORECONF = YES
  169. define PYTHON3_INSTALL_SYMLINK
  170. ln -fs python3 $(TARGET_DIR)/usr/bin/python
  171. endef
  172. ifneq ($(BR2_PACKAGE_PYTHON),y)
  173. PYTHON3_POST_INSTALL_TARGET_HOOKS += PYTHON3_INSTALL_SYMLINK
  174. endif
  175. # Some packages may have build scripts requiring python3, whatever is the
  176. # python version chosen for the target.
  177. # Only install the python symlink in the host tree if python3 is enabled
  178. # for the target.
  179. ifeq ($(BR2_PACKAGE_PYTHON3),y)
  180. define HOST_PYTHON3_INSTALL_SYMLINK
  181. ln -fs python3 $(HOST_DIR)/usr/bin/python
  182. ln -fs python3-config $(HOST_DIR)/usr/bin/python-config
  183. endef
  184. HOST_PYTHON3_POST_INSTALL_HOOKS += HOST_PYTHON3_INSTALL_SYMLINK
  185. endif
  186. # Provided to other packages
  187. PYTHON3_PATH = $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/sysconfigdata/:$(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/site-packages/
  188. $(eval $(autotools-package))
  189. $(eval $(host-autotools-package))
  190. define PYTHON3_CREATE_PYC_FILES
  191. PYTHONPATH="$(PYTHON3_PATH)" \
  192. $(HOST_DIR)/usr/bin/python$(PYTHON3_VERSION_MAJOR) \
  193. support/scripts/pycompile.py \
  194. $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)
  195. endef
  196. ifeq ($(BR2_PACKAGE_PYTHON3_PYC_ONLY)$(BR2_PACKAGE_PYTHON3_PY_PYC),y)
  197. PYTHON3_TARGET_FINALIZE_HOOKS += PYTHON3_CREATE_PYC_FILES
  198. endif
  199. ifeq ($(BR2_PACKAGE_PYTHON3_PYC_ONLY),y)
  200. define PYTHON3_REMOVE_PY_FILES
  201. find $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR) -name '*.py' -print0 | \
  202. xargs -0 --no-run-if-empty rm -f
  203. endef
  204. PYTHON3_TARGET_FINALIZE_HOOKS += PYTHON3_REMOVE_PY_FILES
  205. endif
  206. # Normally, *.pyc files should not have been compiled, but just in
  207. # case, we make sure we remove all of them.
  208. ifeq ($(BR2_PACKAGE_PYTHON3_PY_ONLY),y)
  209. define PYTHON3_REMOVE_PYC_FILES
  210. find $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR) -name '*.pyc' -print0 | \
  211. xargs -0 --no-run-if-empty rm -f
  212. endef
  213. PYTHON3_TARGET_FINALIZE_HOOKS += PYTHON3_REMOVE_PYC_FILES
  214. endif
  215. # In all cases, we don't want to keep the optimized .opt-1.pyc and
  216. # .opt-2.pyc files, since they can't work without their non-optimized
  217. # variant.
  218. define PYTHON3_REMOVE_OPTIMIZED_PYC_FILES
  219. find $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR) -name '*.opt-1.pyc' -print0 -o -name '*.opt-2.pyc' -print0 | \
  220. xargs -0 --no-run-if-empty rm -f
  221. endef
  222. PYTHON3_TARGET_FINALIZE_HOOKS += PYTHON3_REMOVE_OPTIMIZED_PYC_FILES