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.

81 lines
2.1 KiB

  1. #
  2. # Copyright (C) 2015-2016 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 ($(__python_host_mk_inc),1)
  8. __python_host_mk_inc=1
  9. # For PYTHON_VERSION
  10. $(call include_mk, python-version.mk)
  11. HOST_PYTHON_DIR:=$(STAGING_DIR_HOSTPKG)
  12. HOST_PYTHON_INC_DIR:=$(HOST_PYTHON_DIR)/include/python$(PYTHON_VERSION)
  13. HOST_PYTHON_LIB_DIR:=$(HOST_PYTHON_DIR)/lib/python$(PYTHON_VERSION)
  14. HOST_PYTHON_PKG_DIR:=$(HOST_PYTHON_DIR)/lib/python$(PYTHON_VERSION)/site-packages
  15. HOST_PYTHON_BIN:=$(HOST_PYTHON_DIR)/bin/python$(PYTHON_VERSION)
  16. HOST_PYTHONPATH:=$(HOST_PYTHON_LIB_DIR):$(HOST_PYTHON_PKG_DIR)
  17. define HostPython
  18. if [ "$(strip $(3))" == "HOST" ]; then \
  19. export PYTHONPATH="$(HOST_PYTHONPATH)"; \
  20. export PYTHONDONTWRITEBYTECODE=0; \
  21. else \
  22. export PYTHONPATH="$(PYTHONPATH)"; \
  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_PYTHON_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/HostPyRunHost
  36. $(call HostPython, \
  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_PYTHON_INC_DIR)" \
  45. LDFLAGS="$(HOST_LDFLAGS) -lpython$(PYTHON_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/HostPyMod
  58. $(call Build/Compile/HostPyRunHost, \
  59. cd $(HOST_BUILD_DIR)/$(strip $(1)), \
  60. ./setup.py $(2), \
  61. $(3))
  62. endef
  63. define HostPy/Compile/Default
  64. $(call Build/Compile/HostPyMod,,\
  65. install --root="$(STAGING_DIR_HOSTPKG)" --prefix="" \
  66. --single-version-externally-managed \
  67. )
  68. endef
  69. endif # __python_host_mk_inc