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.

93 lines
2.4 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. define host_python3_settings
  33. ARCH="$(HOST_ARCH)" \
  34. CC="$(HOSTCC)" \
  35. CCSHARED="$(HOSTCC) $(HOST_FPIC)" \
  36. CXX="$(HOSTCXX)" \
  37. LD="$(HOSTCC)" \
  38. LDSHARED="$(HOSTCC) -shared" \
  39. CFLAGS="$(HOST_CFLAGS)" \
  40. CPPFLAGS="$(HOST_CPPFLAGS) -I$(HOST_PYTHON3_INC_DIR)" \
  41. LDFLAGS="$(HOST_LDFLAGS) -lpython$(PYTHON3_VERSION) -Wl$(comma)-rpath=$(STAGING_DIR_HOSTPKG)/lib" \
  42. _PYTHON_HOST_PLATFORM=linux2
  43. endef
  44. # $(1) => commands to execute before running pythons script
  45. # $(2) => python script and its arguments
  46. # $(3) => additional variables
  47. define Build/Compile/HostPy3RunHost
  48. $(call HostPython3, \
  49. $(if $(1),$(1);) \
  50. $(call host_python3_settings) \
  51. $(3) \
  52. , \
  53. $(2) \
  54. , \
  55. HOST \
  56. )
  57. endef
  58. # Note: I shamelessly copied this from Yousong's logic (from python-packages);
  59. HOST_PYTHON3_PIP:=$(STAGING_DIR_HOSTPKG)/bin/pip$(PYTHON3_VERSION)
  60. define host_python3_pip_install
  61. $(call host_python3_settings) \
  62. $(HOST_PYTHON3_PIP) install \
  63. --root=$(1) \
  64. --prefix=$(2) \
  65. --ignore-installed \
  66. $(3)
  67. endef
  68. define host_python3_pip_install_host
  69. $(call host_python3_pip_install,$(STAGING_DIR_HOSTPKG),"",$(1))
  70. endef
  71. # $(1) => build subdir
  72. # $(2) => additional arguments to setup.py
  73. # $(3) => additional variables
  74. define Build/Compile/HostPy3Mod
  75. $(call Build/Compile/HostPy3RunHost, \
  76. cd $(HOST_BUILD_DIR)/$(strip $(1)), \
  77. ./setup.py $(2), \
  78. $(3))
  79. endef
  80. endif # __python3_host_mk_inc