python3.mk 8.8 KB

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