python3-host.mk 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. # $(1) => build subdir
  55. # $(2) => additional arguments to setup.py
  56. # $(3) => additional variables
  57. define Build/Compile/HostPy3Mod
  58. $(call Build/Compile/HostPy3RunHost, \
  59. cd $(HOST_BUILD_DIR)/$(strip $(1)), \
  60. ./setup.py $(2), \
  61. $(3))
  62. endef
  63. define HostPy3/Compile/Default
  64. $(call Build/Compile/HostPy3Mod,,\
  65. install --root="$(STAGING_DIR_HOSTPKG)" --prefix="" \
  66. --single-version-externally-managed \
  67. )
  68. endef
  69. ifeq ($(BUILD_VARIANT),python3)
  70. define Host/Compile
  71. $(call HostPy3/Compile/Default)
  72. endef
  73. define Host/Install
  74. endef
  75. endif # python3
  76. endif # __python3_host_mk_inc