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.

95 lines
2.6 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. # $(1) => packages to install
  64. define Build/Compile/HostPy3PipInstall
  65. $(call host_python3_settings) \
  66. $(HOST_PYTHON3_PIP) \
  67. --disable-pip-version-check \
  68. --cache-dir "$(DL_DIR)/pip-cache" \
  69. install \
  70. $(1)
  71. endef
  72. # $(1) => build subdir
  73. # $(2) => additional arguments to setup.py
  74. # $(3) => additional variables
  75. define Build/Compile/HostPy3Mod
  76. $(call Build/Compile/HostPy3RunHost, \
  77. cd $(HOST_BUILD_DIR)/$(strip $(1)), \
  78. ./setup.py $(2), \
  79. $(3))
  80. endef
  81. endif # __python3_host_mk_inc