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.

87 lines
2.3 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. HOST_PYTHON3_DIR:=$(STAGING_DIR_HOSTPKG)
  12. HOST_PYTHON3_INC_DIR:=$(HOST_PYTHON3_DIR)/include/python$(PYTHON3_VERSION)
  13. HOST_PYTHON3_LIB_DIR:=$(HOST_PYTHON3_DIR)/lib/python$(PYTHON3_VERSION)
  14. HOST_PYTHON3_PKG_DIR:=$(HOST_PYTHON3_DIR)/lib/python$(PYTHON3_VERSION)/site-packages
  15. HOST_PYTHON3_BIN:=$(HOST_PYTHON3_DIR)/bin/python$(PYTHON3_VERSION)
  16. HOST_PYTHON3PATH:=$(HOST_PYTHON3_LIB_DIR):$(HOST_PYTHON3_PKG_DIR)
  17. define HostPython3
  18. if [ "$(strip $(3))" == "HOST" ]; then \
  19. export PYTHONPATH="$(HOST_PYTHON3PATH)"; \
  20. export PYTHONDONTWRITEBYTECODE=0; \
  21. else \
  22. export PYTHONPATH="$(PYTHON3PATH)"; \
  23. export PYTHONDONTWRITEBYTECODE=1; \
  24. export _python_sysroot="$(STAGING_DIR)"; \
  25. export _python_prefix="/usr"; \
  26. export _python_exec_prefix="/usr"; \
  27. fi; \
  28. export PYTHONOPTIMIZE=""; \
  29. $(1) \
  30. $(HOST_PYTHON3_BIN) $(2);
  31. endef
  32. # $(1) => commands to execute before running pythons script
  33. # $(2) => python script and its arguments
  34. # $(3) => additional variables
  35. define Build/Compile/HostPy3RunHost
  36. $(call HostPython3, \
  37. $(if $(1),$(1);) \
  38. CC="$(HOSTCC)" \
  39. CCSHARED="$(HOSTCC) $(HOST_FPIC)" \
  40. CXX="$(HOSTCXX)" \
  41. LD="$(HOSTCC)" \
  42. LDSHARED="$(HOSTCC) -shared" \
  43. CFLAGS="$(HOST_CFLAGS)" \
  44. CPPFLAGS="$(HOST_CPPFLAGS) -I$(HOST_PYTHON3_INC_DIR)" \
  45. LDFLAGS="$(HOST_LDFLAGS) -lpython$(PYTHON3_VERSION) -Wl$(comma)-rpath=$(STAGING_DIR_HOSTPKG)/lib" \
  46. _PYTHON_HOST_PLATFORM=linux2 \
  47. $(3) \
  48. , \
  49. $(2) \
  50. , \
  51. HOST \
  52. )
  53. endef
  54. # Note: I shamelessly copied this from Yousong's logic (from python-packages);
  55. HOST_PYTHON3_PIP:=$(STAGING_DIR_HOSTPKG)/bin/pip$(PYTHON3_VERSION)
  56. define host_python3_pip_install
  57. $(HOST_PYTHON3_PIP) install \
  58. --root=$(1) \
  59. --prefix=$(2) \
  60. --ignore-installed \
  61. $(3)
  62. endef
  63. define host_python3_pip_install_host
  64. $(call host_python3_pip_install,$(STAGING_DIR_HOSTPKG),"",$(1))
  65. endef
  66. # $(1) => build subdir
  67. # $(2) => additional arguments to setup.py
  68. # $(3) => additional variables
  69. define Build/Compile/HostPy3Mod
  70. $(call Build/Compile/HostPy3RunHost, \
  71. cd $(HOST_BUILD_DIR)/$(strip $(1)), \
  72. ./setup.py $(2), \
  73. $(3))
  74. endef
  75. endif # __python3_host_mk_inc