You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

144 lines
4.0 KiB

  1. #
  2. # Copyright (C) 2007-2016 OpenWrt.org
  3. #
  4. # This is free software, licensed under the GNU General Public License v2.
  5. # See /LICENSE for more information.
  6. #
  7. $(call include_mk, python3-version.mk)
  8. PYTHON3_DIR:=$(STAGING_DIR)/usr
  9. PYTHON3_BIN_DIR:=$(PYTHON3_DIR)/bin
  10. PYTHON3_INC_DIR:=$(PYTHON3_DIR)/include/python$(PYTHON3_VERSION)
  11. PYTHON3_LIB_DIR:=$(PYTHON3_DIR)/lib/python$(PYTHON3_VERSION)
  12. PYTHON3_PKG_DIR:=/usr/lib/python$(PYTHON3_VERSION)/site-packages
  13. PYTHON3:=python$(PYTHON3_VERSION)
  14. PYTHON3PATH:=$(PYTHON3_LIB_DIR):$(STAGING_DIR)/$(PYTHON3_PKG_DIR):$(PKG_INSTALL_DIR)/$(PYTHON3_PKG_DIR)
  15. # These configure args are needed in detection of path to Python header files
  16. # using autotools.
  17. CONFIGURE_ARGS += \
  18. _python_sysroot="$(STAGING_DIR)" \
  19. _python_prefix="/usr" \
  20. _python_exec_prefix="/usr"
  21. PKG_USE_MIPS16:=0
  22. # This is required in addition to PKG_USE_MIPS16:=0 because otherwise MIPS16
  23. # flags are inherited from the Python base package (via sysconfig module)
  24. ifdef CONFIG_USE_MIPS16
  25. TARGET_CFLAGS += -mno-mips16 -mno-interlink-mips16
  26. endif
  27. define Py3Package
  28. define Package/$(1)-src
  29. $(call Package/$(1))
  30. TITLE+= (sources)
  31. DEPENDS:=$$$$(foreach dep,$$$$(filter +python3-%,$$$$(DEPENDS)),$$$$(dep)-src)
  32. endef
  33. define Package/$(1)-src/description
  34. $(call Package/$(1)/description).
  35. (Contains the Python3 sources for this package).
  36. endef
  37. # Add default PyPackage filespec none defined
  38. ifndef Py3Package/$(1)/filespec
  39. define Py3Package/$(1)/filespec
  40. +|$(PYTHON3_PKG_DIR)
  41. endef
  42. endif
  43. ifndef Py3Package/$(1)/install
  44. define Py3Package/$(1)/install
  45. if [ -d $(PKG_INSTALL_DIR)/usr/bin ]; then \
  46. $(INSTALL_DIR) $$(1)/usr/bin ; \
  47. $(CP) $(PKG_INSTALL_DIR)/usr/bin/* $$(1)/usr/bin/ ; \
  48. fi
  49. endef
  50. endif
  51. ifndef Package/$(1)/install
  52. $(call shexport,Py3Package/$(1)/filespec)
  53. define Package/$(1)/install
  54. $(call Py3Package/$(1)/install,$$(1))
  55. find $(PKG_INSTALL_DIR) -name "*\.exe" | xargs rm -f
  56. if [ -e files/python3-package-install.sh ] ; then \
  57. $(SHELL) files/python3-package-install.sh \
  58. "$(PKG_INSTALL_DIR)" "$$(1)" \
  59. "$(HOST_PYTHON3_BIN)" "$$(2)" \
  60. "$$$$$$$$$$(call shvar,Py3Package/$(1)/filespec)" ; \
  61. elif [ -e $(STAGING_DIR)/mk/python3-package-install.sh ] ; then \
  62. $(SHELL) $(STAGING_DIR)/mk/python3-package-install.sh \
  63. "$(PKG_INSTALL_DIR)" "$$(1)" \
  64. "$(HOST_PYTHON3_BIN)" "$$(2)" \
  65. "$$$$$$$$$$(call shvar,Py3Package/$(1)/filespec)" ; \
  66. else \
  67. echo "No 'python3-package-install.sh' script found" ; \
  68. exit 1 ; \
  69. fi
  70. endef
  71. define Package/$(1)-src/install
  72. $$(call Package/$(1)/install,$$(1),sources)
  73. endef
  74. endif # Package/$(1)/install
  75. endef
  76. $(call include_mk, python3-host.mk)
  77. # $(1) => commands to execute before running pythons script
  78. # $(2) => python script and its arguments
  79. # $(3) => additional variables
  80. define Build/Compile/HostPy3RunTarget
  81. $(call HostPython3, \
  82. $(if $(1),$(1);) \
  83. CC="$(TARGET_CC)" \
  84. CCSHARED="$(TARGET_CC) $(FPIC)" \
  85. CXX="$(TARGET_CXX)" \
  86. LD="$(TARGET_CC)" \
  87. LDSHARED="$(TARGET_CC) -shared" \
  88. CFLAGS="$(TARGET_CFLAGS)" \
  89. CPPFLAGS="$(TARGET_CPPFLAGS) -I$(PYTHON3_INC_DIR)" \
  90. LDFLAGS="$(TARGET_LDFLAGS) -lpython$(PYTHON3_VERSION)" \
  91. _PYTHON_HOST_PLATFORM=linux2 \
  92. __PYVENV_LAUNCHER__="/usr/bin/$(PYTHON3)" \
  93. $(3) \
  94. , \
  95. $(2) \
  96. )
  97. endef
  98. # $(1) => build subdir
  99. # $(2) => additional arguments to setup.py
  100. # $(3) => additional variables
  101. define Build/Compile/Py3Mod
  102. $(INSTALL_DIR) $(PKG_INSTALL_DIR)/$(PYTHON3_PKG_DIR)
  103. $(call Build/Compile/HostPy3RunTarget, \
  104. cd $(PKG_BUILD_DIR)/$(strip $(1)), \
  105. ./setup.py $(2), \
  106. $(3))
  107. find $(PKG_INSTALL_DIR) -name "*\.exe" | xargs rm -f
  108. endef
  109. define Py3Build/Compile/Default
  110. $(foreach pkg,$(HOST_PYTHON3_PACKAGE_BUILD_DEPENDS),
  111. $(call host_python3_pip_install_host,$(pkg))
  112. )
  113. $(call Build/Compile/Py3Mod,, \
  114. install --prefix="/usr" --root="$(PKG_INSTALL_DIR)" \
  115. --single-version-externally-managed \
  116. )
  117. endef
  118. Py3Build/Compile=$(Py3Build/Compile/Default)
  119. ifeq ($(BUILD_VARIANT),python3)
  120. define Build/Compile
  121. $(call Py3Build/Compile)
  122. endef
  123. endif # python3