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.

148 lines
4.1 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. PYTHON3_KEEP_EGGINFO ?= 0
  28. define Py3Package
  29. define Package/$(1)-src
  30. $(call Package/$(1))
  31. TITLE+= (sources)
  32. DEPENDS:=$$$$(foreach dep,$$$$(filter +python3-%,$$$$(DEPENDS)),$$$$(dep)-src)
  33. endef
  34. define Package/$(1)-src/description
  35. $(call Package/$(1)/description).
  36. (Contains the Python3 sources for this package).
  37. endef
  38. # Add default PyPackage filespec none defined
  39. ifndef Py3Package/$(1)/filespec
  40. define Py3Package/$(1)/filespec
  41. +|$(PYTHON3_PKG_DIR)
  42. endef
  43. endif
  44. ifndef Py3Package/$(1)/install
  45. define Py3Package/$(1)/install
  46. if [ -d $(PKG_INSTALL_DIR)/usr/bin ]; then \
  47. $(INSTALL_DIR) $$(1)/usr/bin ; \
  48. $(CP) $(PKG_INSTALL_DIR)/usr/bin/* $$(1)/usr/bin/ ; \
  49. fi
  50. endef
  51. endif
  52. ifndef Package/$(1)/install
  53. $(call shexport,Py3Package/$(1)/filespec)
  54. define Package/$(1)/install
  55. $(call Py3Package/$(1)/install,$$(1))
  56. find $(PKG_INSTALL_DIR) -name "*\.exe" | xargs rm -f
  57. if [ -e files/python3-package-install.sh ] ; then \
  58. PYTHON3_KEEP_EGGINFO="$(PYTHON3_KEEP_EGGINFO)" \
  59. $(SHELL) files/python3-package-install.sh \
  60. "$(PKG_INSTALL_DIR)" "$$(1)" \
  61. "$(HOST_PYTHON3_BIN)" "$$(2)" \
  62. "$$$$$$$$$$(call shvar,Py3Package/$(1)/filespec)" ; \
  63. elif [ -e $(STAGING_DIR)/mk/python3-package-install.sh ] ; then \
  64. PYTHON3_KEEP_EGGINFO="$(PYTHON3_KEEP_EGGINFO)" \
  65. $(SHELL) $(STAGING_DIR)/mk/python3-package-install.sh \
  66. "$(PKG_INSTALL_DIR)" "$$(1)" \
  67. "$(HOST_PYTHON3_BIN)" "$$(2)" \
  68. "$$$$$$$$$$(call shvar,Py3Package/$(1)/filespec)" ; \
  69. else \
  70. echo "No 'python3-package-install.sh' script found" ; \
  71. exit 1 ; \
  72. fi
  73. endef
  74. define Package/$(1)-src/install
  75. $$(call Package/$(1)/install,$$(1),sources)
  76. endef
  77. endif # Package/$(1)/install
  78. endef
  79. $(call include_mk, python3-host.mk)
  80. # $(1) => commands to execute before running pythons script
  81. # $(2) => python script and its arguments
  82. # $(3) => additional variables
  83. define Build/Compile/HostPy3RunTarget
  84. $(call HostPython3, \
  85. $(if $(1),$(1);) \
  86. CC="$(TARGET_CC)" \
  87. CCSHARED="$(TARGET_CC) $(FPIC)" \
  88. CXX="$(TARGET_CXX)" \
  89. LD="$(TARGET_CC)" \
  90. LDSHARED="$(TARGET_CC) -shared" \
  91. CFLAGS="$(TARGET_CFLAGS)" \
  92. CPPFLAGS="$(TARGET_CPPFLAGS) -I$(PYTHON3_INC_DIR)" \
  93. LDFLAGS="$(TARGET_LDFLAGS) -lpython$(PYTHON3_VERSION)" \
  94. _PYTHON_HOST_PLATFORM=linux2 \
  95. __PYVENV_LAUNCHER__="/usr/bin/$(PYTHON3)" \
  96. $(3) \
  97. , \
  98. $(2) \
  99. )
  100. endef
  101. # $(1) => build subdir
  102. # $(2) => additional arguments to setup.py
  103. # $(3) => additional variables
  104. define Build/Compile/Py3Mod
  105. $(INSTALL_DIR) $(PKG_INSTALL_DIR)/$(PYTHON3_PKG_DIR)
  106. $(call Build/Compile/HostPy3RunTarget, \
  107. cd $(PKG_BUILD_DIR)/$(strip $(1)), \
  108. ./setup.py $(2), \
  109. $(3))
  110. find $(PKG_INSTALL_DIR) -name "*\.exe" | xargs rm -f
  111. endef
  112. define Py3Build/Compile/Default
  113. $(foreach pkg,$(HOST_PYTHON3_PACKAGE_BUILD_DEPENDS),
  114. $(call host_python3_pip_install_host,$(pkg))
  115. )
  116. $(call Build/Compile/Py3Mod,, \
  117. install --prefix="/usr" --root="$(PKG_INSTALL_DIR)" \
  118. --single-version-externally-managed \
  119. )
  120. endef
  121. Py3Build/Compile=$(Py3Build/Compile/Default)
  122. ifeq ($(BUILD_VARIANT),python3)
  123. define Build/Compile
  124. $(call Py3Build/Compile)
  125. endef
  126. endif # python3