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.

96 lines
2.5 KiB

  1. #
  2. # Copyright (C) 2017 OpenWrt.org
  3. #
  4. # This is free software, licensed under the GNU General Public License v2.
  5. # See /LICENSE for more information.
  6. #
  7. ifneq ($(__python3_host_mk_inc),1)
  8. __python3_host_mk_inc=1
  9. # For PYTHON3_VERSION
  10. $(call include_mk, python3-version.mk)
  11. # Compatibility fallback for older OpenWrt and LEDE versions
  12. ifeq ($(STAGING_DIR_HOSTPKG),)
  13. $(warning STAGING_DIR_HOSTPKG is unset - falling back to $$(STAGING_DIR)/host)
  14. STAGING_DIR_HOSTPKG := $(STAGING_DIR)/host
  15. endif
  16. HOST_PYTHON3_DIR:=$(STAGING_DIR_HOSTPKG)
  17. HOST_PYTHON3_INC_DIR:=$(HOST_PYTHON3_DIR)/include/python$(PYTHON3_VERSION)
  18. HOST_PYTHON3_LIB_DIR:=$(HOST_PYTHON3_DIR)/lib/python$(PYTHON3_VERSION)
  19. HOST_PYTHON3_PKG_DIR:=$(HOST_PYTHON3_DIR)/lib/python$(PYTHON3_VERSION)/site-packages
  20. HOST_PYTHON3_BIN:=$(HOST_PYTHON3_DIR)/bin/python$(PYTHON3_VERSION)
  21. HOST_PYTHON3PATH:=$(HOST_PYTHON3_LIB_DIR):$(HOST_PYTHON3_PKG_DIR)
  22. define HostPython3
  23. if [ "$(strip $(3))" == "HOST" ]; then \
  24. export PYTHONPATH="$(HOST_PYTHON3PATH)"; \
  25. export PYTHONDONTWRITEBYTECODE=0; \
  26. else \
  27. export PYTHONPATH="$(PYTHON3PATH)"; \
  28. export PYTHONDONTWRITEBYTECODE=1; \
  29. export _python_sysroot="$(STAGING_DIR)"; \
  30. export _python_prefix="/usr"; \
  31. export _python_exec_prefix="/usr"; \
  32. fi; \
  33. export PYTHONOPTIMIZE=""; \
  34. $(1) \
  35. $(HOST_PYTHON3_BIN) $(2);
  36. endef
  37. # $(1) => commands to execute before running pythons script
  38. # $(2) => python script and its arguments
  39. # $(3) => additional variables
  40. define Build/Compile/HostPy3RunHost
  41. $(call HostPython3, \
  42. $(if $(1),$(1);) \
  43. CC="$(HOSTCC)" \
  44. CCSHARED="$(HOSTCC) $(HOST_FPIC)" \
  45. CXX="$(HOSTCXX)" \
  46. LD="$(HOSTCC)" \
  47. LDSHARED="$(HOSTCC) -shared" \
  48. CFLAGS="$(HOST_CFLAGS)" \
  49. CPPFLAGS="$(HOST_CPPFLAGS) -I$(HOST_PYTHON3_INC_DIR)" \
  50. LDFLAGS="$(HOST_LDFLAGS) -lpython$(PYTHON3_VERSION) -Wl$(comma)-rpath=$(STAGING_DIR_HOSTPKG)/lib" \
  51. _PYTHON_HOST_PLATFORM=linux2 \
  52. $(3) \
  53. , \
  54. $(2) \
  55. , \
  56. HOST \
  57. )
  58. endef
  59. # $(1) => build subdir
  60. # $(2) => additional arguments to setup.py
  61. # $(3) => additional variables
  62. define Build/Compile/HostPy3Mod
  63. $(call Build/Compile/HostPy3RunHost, \
  64. cd $(HOST_BUILD_DIR)/$(strip $(1)), \
  65. ./setup.py $(2), \
  66. $(3))
  67. endef
  68. define HostPy3/Compile/Default
  69. $(call Build/Compile/HostPy3Mod,,\
  70. install --root="$(HOST_BUILD_PREFIX)" --prefix="" \
  71. --single-version-externally-managed \
  72. )
  73. endef
  74. ifeq ($(BUILD_VARIANT),python3)
  75. define Host/Compile
  76. $(call HostPy3/Compile/Default)
  77. endef
  78. define Host/Install
  79. endef
  80. endif # python3
  81. endif # __python3_host_mk_inc