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.

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