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.

152 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. # 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 Py3Shebang
  30. $(SED) "1"'!'"b;s,^#"'!'".*python.*,#"'!'"/usr/bin/python3," -i --follow-symlinks $(1)
  31. endef
  32. define Py3Package
  33. define Package/$(1)-src
  34. $(call Package/$(1))
  35. DEPENDS:=
  36. CONFLICTS:=
  37. PROVIDES:=
  38. EXTRA_DEPENDS:=
  39. TITLE+= (sources)
  40. USERID:=
  41. MENU:=
  42. endef
  43. define Package/$(1)-src/description
  44. $(call Package/$(1)/description).
  45. (Contains the Python3 sources for this package).
  46. endef
  47. # Add default PyPackage filespec none defined
  48. ifndef Py3Package/$(1)/filespec
  49. define Py3Package/$(1)/filespec
  50. +|$(PYTHON3_PKG_DIR)
  51. endef
  52. endif
  53. ifndef Py3Package/$(1)/install
  54. define Py3Package/$(1)/install
  55. if [ -d $(PKG_INSTALL_DIR)/usr/bin ]; then \
  56. $(INSTALL_DIR) $$(1)/usr/bin ; \
  57. $(CP) $(PKG_INSTALL_DIR)/usr/bin/* $$(1)/usr/bin/ ; \
  58. fi
  59. endef
  60. endif
  61. ifndef Package/$(1)/install
  62. $(call shexport,Py3Package/$(1)/filespec)
  63. define Package/$(1)/install
  64. $$(call Py3Package/$(1)/install,$$(1))
  65. $(SHELL) $(python3_mk_path)python-package-install.sh "3" \
  66. "$(PKG_INSTALL_DIR)" "$$(1)" \
  67. "$(HOST_PYTHON3_BIN)" "$$(2)" \
  68. "$$$$$$$$$$(call shvar,Py3Package/$(1)/filespec)" && \
  69. if [ -d "$$(1)/usr/bin" ]; then \
  70. $(call Py3Shebang,$$(1)/usr/bin/*) ; \
  71. fi
  72. endef
  73. define Package/$(1)-src/install
  74. $$(call Package/$(1)/install,$$(1),sources)
  75. endef
  76. endif # Package/$(1)/install
  77. endef
  78. # $(1) => commands to execute before running pythons script
  79. # $(2) => python script and its arguments
  80. # $(3) => additional variables
  81. define Build/Compile/HostPy3RunTarget
  82. $(call HostPython3, \
  83. $(if $(1),$(1);) \
  84. CC="$(TARGET_CC)" \
  85. CCSHARED="$(TARGET_CC) $(FPIC)" \
  86. CXX="$(TARGET_CXX)" \
  87. LD="$(TARGET_CC)" \
  88. LDSHARED="$(TARGET_CC) -shared" \
  89. CFLAGS="$(TARGET_CFLAGS)" \
  90. CPPFLAGS="$(TARGET_CPPFLAGS) -I$(PYTHON3_INC_DIR)" \
  91. LDFLAGS="$(TARGET_LDFLAGS) -lpython$(PYTHON3_VERSION)" \
  92. _PYTHON_HOST_PLATFORM=linux2 \
  93. __PYVENV_LAUNCHER__="/usr/bin/$(PYTHON3)" \
  94. $(3) \
  95. , \
  96. $(2) \
  97. )
  98. endef
  99. # $(1) => build subdir
  100. # $(2) => additional arguments to setup.py
  101. # $(3) => additional variables
  102. define Build/Compile/Py3Mod
  103. $(INSTALL_DIR) $(PKG_INSTALL_DIR)/$(PYTHON3_PKG_DIR)
  104. $(call Build/Compile/HostPy3RunTarget, \
  105. cd $(PKG_BUILD_DIR)/$(strip $(1)), \
  106. ./setup.py $(2), \
  107. $(3))
  108. endef
  109. PYTHON3_PKG_SETUP_DIR ?=
  110. PYTHON3_PKG_SETUP_GLOABL_ARGS ?=
  111. PYTHON3_PKG_SETUP_ARGS ?= --single-version-externally-managed
  112. PYTHON3_PKG_SETUP_VARS ?=
  113. define Py3Build/Compile/Default
  114. $(if $(HOST_PYTHON3_PACKAGE_BUILD_DEPENDS),
  115. $(call Build/Compile/HostPy3PipInstall,$(HOST_PYTHON3_PACKAGE_BUILD_DEPENDS))
  116. )
  117. $(call Build/Compile/Py3Mod, \
  118. $(PYTHON3_PKG_SETUP_DIR), \
  119. $(PYTHON3_PKG_SETUP_GLOBAL_ARGS) \
  120. install --prefix="/usr" --root="$(PKG_INSTALL_DIR)" \
  121. $(PYTHON3_PKG_SETUP_ARGS), \
  122. $(PYTHON3_PKG_SETUP_VARS) \
  123. )
  124. endef
  125. Py3Build/Compile=$(Py3Build/Compile/Default)
  126. ifeq ($(BUILD_VARIANT),python3)
  127. define Build/Compile
  128. $(call Py3Build/Compile)
  129. endef
  130. endif # python3