python3.mk 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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_SQLITE),y)
  68. PYTHON3_DEPENDENCIES += sqlite
  69. else
  70. PYTHON3_CONF_OPTS += --disable-sqlite3
  71. endif
  72. ifeq ($(BR2_PACKAGE_PYTHON3_SSL),y)
  73. PYTHON3_DEPENDENCIES += openssl
  74. endif
  75. ifneq ($(BR2_PACKAGE_PYTHON3_CODECSCJK),y)
  76. PYTHON3_CONF_OPTS += --disable-codecs-cjk
  77. endif
  78. ifneq ($(BR2_PACKAGE_PYTHON3_UNICODEDATA),y)
  79. PYTHON3_CONF_OPTS += --disable-unicodedata
  80. endif
  81. ifeq ($(BR2_PACKAGE_PYTHON3_BZIP2),y)
  82. PYTHON3_DEPENDENCIES += bzip2
  83. endif
  84. ifeq ($(BR2_PACKAGE_PYTHON3_ZLIB),y)
  85. PYTHON3_DEPENDENCIES += zlib
  86. endif
  87. ifeq ($(BR2_PACKAGE_PYTHON3_OSSAUDIODEV),y)
  88. PYTHON3_CONF_OPTS += --enable-ossaudiodev
  89. else
  90. PYTHON3_CONF_OPTS += --disable-ossaudiodev
  91. endif
  92. PYTHON3_CONF_ENV += \
  93. ac_cv_have_long_long_format=yes \
  94. ac_cv_file__dev_ptmx=yes \
  95. ac_cv_file__dev_ptc=yes \
  96. ac_cv_working_tzset=yes
  97. # uClibc is known to have a broken wcsftime() implementation, so tell
  98. # Python 3 to fall back to strftime() instead.
  99. ifeq ($(BR2_TOOLCHAIN_USES_UCLIBC),y)
  100. PYTHON3_CONF_ENV += ac_cv_func_wcsftime=no
  101. endif
  102. PYTHON3_CONF_OPTS += \
  103. --without-ensurepip \
  104. --without-cxx-main \
  105. --with-system-ffi \
  106. --disable-pydoc \
  107. --disable-test-modules \
  108. --disable-lib2to3 \
  109. --disable-tk \
  110. --disable-nis \
  111. --disable-idle3 \
  112. --disable-pyc-build
  113. # Python builds two tools to generate code: 'pgen' and
  114. # '_freeze_importlib'. Unfortunately, for the target Python, they are
  115. # built for the target, while we need to run them at build time. So
  116. # when installing host-python, we copy them to
  117. # $(HOST_DIR)/usr/bin. And then, when building the target python
  118. # package, we tell the configure script where they are located.
  119. define HOST_PYTHON3_INSTALL_TOOLS
  120. cp $(@D)/Parser/pgen $(HOST_DIR)/usr/bin/python-pgen
  121. cp $(@D)/Programs/_freeze_importlib $(HOST_DIR)/usr/bin/python-freeze-importlib
  122. endef
  123. HOST_PYTHON3_POST_INSTALL_HOOKS += HOST_PYTHON3_INSTALL_TOOLS
  124. PYTHON3_CONF_ENV += \
  125. PGEN_FOR_BUILD=$(HOST_DIR)/usr/bin/python-pgen \
  126. FREEZE_IMPORTLIB_FOR_BUILD=$(HOST_DIR)/usr/bin/python-freeze-importlib
  127. #
  128. # Remove useless files. In the config/ directory, only the Makefile
  129. # and the pyconfig.h files are needed at runtime.
  130. #
  131. define PYTHON3_REMOVE_USELESS_FILES
  132. rm -f $(TARGET_DIR)/usr/bin/python$(PYTHON3_VERSION_MAJOR)-config
  133. rm -f $(TARGET_DIR)/usr/bin/python$(PYTHON3_VERSION_MAJOR)m-config
  134. rm -f $(TARGET_DIR)/usr/bin/python3-config
  135. rm -f $(TARGET_DIR)/usr/bin/smtpd.py.3
  136. for i in `find $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/config-$(PYTHON3_VERSION_MAJOR)m/ \
  137. -type f -not -name pyconfig.h -a -not -name Makefile` ; do \
  138. rm -f $$i ; \
  139. done
  140. rm -rf $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/__pycache__/
  141. rm -rf $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/lib-dynload/sysconfigdata/__pycache__
  142. rm -rf $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/collections/__pycache__
  143. rm -rf $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/importlib/__pycache__
  144. endef
  145. PYTHON3_POST_INSTALL_TARGET_HOOKS += PYTHON3_REMOVE_USELESS_FILES
  146. #
  147. # Make sure libpython gets stripped out on target
  148. #
  149. define PYTHON3_ENSURE_LIBPYTHON_STRIPPED
  150. chmod u+w $(TARGET_DIR)/usr/lib/libpython$(PYTHON3_VERSION_MAJOR)*.so
  151. endef
  152. PYTHON3_POST_INSTALL_TARGET_HOOKS += PYTHON3_ENSURE_LIBPYTHON_STRIPPED
  153. PYTHON3_AUTORECONF = YES
  154. define PYTHON3_INSTALL_SYMLINK
  155. ln -fs python3 $(TARGET_DIR)/usr/bin/python
  156. endef
  157. ifneq ($(BR2_PACKAGE_PYTHON),y)
  158. PYTHON3_POST_INSTALL_TARGET_HOOKS += PYTHON3_INSTALL_SYMLINK
  159. endif
  160. # Some packages may have build scripts requiring python3, whatever is the
  161. # python version chosen for the target.
  162. # Only install the python symlink in the host tree if python3 is enabled
  163. # for the target.
  164. ifeq ($(BR2_PACKAGE_PYTHON3),y)
  165. define HOST_PYTHON3_INSTALL_SYMLINK
  166. ln -fs python3 $(HOST_DIR)/usr/bin/python
  167. ln -fs python3-config $(HOST_DIR)/usr/bin/python-config
  168. endef
  169. HOST_PYTHON3_POST_INSTALL_HOOKS += HOST_PYTHON3_INSTALL_SYMLINK
  170. endif
  171. # Provided to other packages
  172. PYTHON3_PATH = $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/sysconfigdata/:$(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/site-packages/
  173. $(eval $(autotools-package))
  174. $(eval $(host-autotools-package))
  175. define PYTHON3_CREATE_PYC_FILES
  176. PYTHONPATH="$(PYTHON3_PATH)" \
  177. $(HOST_DIR)/usr/bin/python$(PYTHON3_VERSION_MAJOR) \
  178. support/scripts/pycompile.py \
  179. $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)
  180. endef
  181. ifeq ($(BR2_PACKAGE_PYTHON3_PYC_ONLY)$(BR2_PACKAGE_PYTHON3_PY_PYC),y)
  182. TARGET_FINALIZE_HOOKS += PYTHON3_CREATE_PYC_FILES
  183. endif
  184. ifeq ($(BR2_PACKAGE_PYTHON3_PYC_ONLY),y)
  185. define PYTHON3_REMOVE_PY_FILES
  186. find $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR) -name '*.py' -print0 | \
  187. xargs -0 --no-run-if-empty rm -f
  188. endef
  189. TARGET_FINALIZE_HOOKS += PYTHON3_REMOVE_PY_FILES
  190. endif
  191. # Normally, *.pyc files should not have been compiled, but just in
  192. # case, we make sure we remove all of them.
  193. ifeq ($(BR2_PACKAGE_PYTHON3_PY_ONLY),y)
  194. define PYTHON3_REMOVE_PYC_FILES
  195. find $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR) -name '*.pyc' -print0 | \
  196. xargs -0 --no-run-if-empty rm -f
  197. endef
  198. TARGET_FINALIZE_HOOKS += PYTHON3_REMOVE_PYC_FILES
  199. endif
  200. # In all cases, we don't want to keep the optimized .opt-1.pyc and
  201. # .opt-2.pyc files, since they can't work without their non-optimized
  202. # variant.
  203. ifeq ($(BR2_PACKAGE_PYTHON3),y)
  204. define PYTHON3_REMOVE_OPTIMIZED_PYC_FILES
  205. find $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR) -name '*.opt-1.pyc' -print0 -o -name '*.opt-2.pyc' -print0 | \
  206. xargs -0 --no-run-if-empty rm -f
  207. endef
  208. TARGET_FINALIZE_HOOKS += PYTHON3_REMOVE_OPTIMIZED_PYC_FILES
  209. endif