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.

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