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.

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