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.

137 lines
3.8 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. $(call shexport,Py3Package/$(1)/filespec)
  52. define Package/$(1)/install
  53. $(call Py3Package/$(1)/install,$$(1))
  54. find $(PKG_INSTALL_DIR) -name "*\.exe" | xargs rm -f
  55. if [ -e files/python3-package-install.sh ] ; then \
  56. $(SHELL) files/python3-package-install.sh \
  57. "$(PKG_INSTALL_DIR)" "$$(1)" \
  58. "$(HOST_PYTHON3_BIN)" "$$(2)" \
  59. "$$$$$$$$$$(call shvar,Py3Package/$(1)/filespec)" ; \
  60. elif [ -e $(STAGING_DIR)/mk/python3-package-install.sh ] ; then \
  61. $(SHELL) $(STAGING_DIR)/mk/python3-package-install.sh \
  62. "$(PKG_INSTALL_DIR)" "$$(1)" \
  63. "$(HOST_PYTHON3_BIN)" "$$(2)" \
  64. "$$$$$$$$$$(call shvar,Py3Package/$(1)/filespec)" ; \
  65. else \
  66. echo "No 'python3-package-install.sh' script found" ; \
  67. exit 1 ; \
  68. fi
  69. endef
  70. define Package/$(1)-src/install
  71. $$(call Package/$(1)/install,$$(1),sources)
  72. endef
  73. endef
  74. $(call include_mk, python3-host.mk)
  75. # $(1) => commands to execute before running pythons script
  76. # $(2) => python script and its arguments
  77. # $(3) => additional variables
  78. define Build/Compile/HostPy3RunTarget
  79. $(call HostPython3, \
  80. $(if $(1),$(1);) \
  81. CC="$(TARGET_CC)" \
  82. CCSHARED="$(TARGET_CC) $(FPIC)" \
  83. CXX="$(TARGET_CXX)" \
  84. LD="$(TARGET_CC)" \
  85. LDSHARED="$(TARGET_CC) -shared" \
  86. CFLAGS="$(TARGET_CFLAGS)" \
  87. CPPFLAGS="$(TARGET_CPPFLAGS) -I$(PYTHON3_INC_DIR)" \
  88. LDFLAGS="$(TARGET_LDFLAGS) -lpython$(PYTHON3_VERSION)" \
  89. _PYTHON_HOST_PLATFORM=linux2 \
  90. __PYVENV_LAUNCHER__="/usr/bin/$(PYTHON3)" \
  91. $(3) \
  92. , \
  93. $(2) \
  94. )
  95. endef
  96. # $(1) => build subdir
  97. # $(2) => additional arguments to setup.py
  98. # $(3) => additional variables
  99. define Build/Compile/Py3Mod
  100. $(INSTALL_DIR) $(PKG_INSTALL_DIR)/$(PYTHON3_PKG_DIR)
  101. $(call Build/Compile/HostPy3RunTarget, \
  102. cd $(PKG_BUILD_DIR)/$(strip $(1)), \
  103. ./setup.py $(2), \
  104. $(3))
  105. find $(PKG_INSTALL_DIR) -name "*\.exe" | xargs rm -f
  106. endef
  107. define Py3Build/Compile/Default
  108. $(call Build/Compile/Py3Mod,, \
  109. install --prefix="/usr" --root="$(PKG_INSTALL_DIR)" \
  110. --single-version-externally-managed \
  111. )
  112. endef
  113. ifeq ($(BUILD_VARIANT),python3)
  114. define Build/Compile
  115. $(call Py3Build/Compile/Default)
  116. endef
  117. endif # python3