2
1

python3.mk 8.4 KB

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