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.

80 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. # Compatibility fallback for older OpenWrt and LEDE versions
  12. ifeq ($(STAGING_DIR_HOSTPKG),)
  13. $(warning STAGING_DIR_HOSTPKG is unset - falling back to $$(STAGING_DIR)/host)
  14. STAGING_DIR_HOSTPKG := $(STAGING_DIR)/host
  15. endif
  16. HOST_PYTHON_DIR:=$(STAGING_DIR_HOSTPKG)
  17. HOST_PYTHON_INC_DIR:=$(HOST_PYTHON_DIR)/include/python$(PYTHON_VERSION)
  18. HOST_PYTHON_LIB_DIR:=$(HOST_PYTHON_DIR)/lib/python$(PYTHON_VERSION)
  19. HOST_PYTHON_PKG_DIR:=$(HOST_PYTHON_DIR)/lib/python$(PYTHON_VERSION)/site-packages
  20. HOST_PYTHON_BIN:=$(HOST_PYTHON_DIR)/bin/python$(PYTHON_VERSION)
  21. HOST_PYTHONPATH:=$(HOST_PYTHON_LIB_DIR):$(HOST_PYTHON_PKG_DIR)
  22. define HostPython
  23. if [ "$(strip $(3))" == "HOST" ]; then \
  24. export PYTHONPATH="$(HOST_PYTHONPATH)"; \
  25. export PYTHONDONTWRITEBYTECODE=0; \
  26. else \
  27. export PYTHONPATH="$(PYTHONPATH)"; \
  28. export PYTHONDONTWRITEBYTECODE=1; \
  29. export _python_sysroot="$(STAGING_DIR)"; \
  30. export _python_prefix="/usr"; \
  31. export _python_exec_prefix="/usr"; \
  32. fi; \
  33. export PYTHONOPTIMIZE=""; \
  34. $(1) \
  35. $(HOST_PYTHON_BIN) $(2);
  36. endef
  37. # $(1) => commands to execute before running pythons script
  38. # $(2) => python script and its arguments
  39. # $(3) => additional variables
  40. define Build/Compile/HostPyRunHost
  41. $(call HostPython, \
  42. $(if $(1),$(1);) \
  43. CC="$(HOSTCC)" \
  44. CCSHARED="$(HOSTCC) $(HOST_FPIC)" \
  45. CXX="$(HOSTCXX)" \
  46. LD="$(HOSTCC)" \
  47. LDSHARED="$(HOSTCC) -shared" \
  48. CFLAGS="$(HOST_CFLAGS)" \
  49. CPPFLAGS="$(HOST_CPPFLAGS) -I$(HOST_PYTHON_INC_DIR)" \
  50. LDFLAGS="$(HOST_LDFLAGS) -lpython$(PYTHON_VERSION) -Wl$(comma)-rpath=$(STAGING_DIR_HOSTPKG)/lib" \
  51. _PYTHON_HOST_PLATFORM=linux2 \
  52. $(3) \
  53. , \
  54. $(2) \
  55. , \
  56. HOST \
  57. )
  58. endef
  59. # $(1) => build subdir
  60. # $(2) => additional arguments to setup.py
  61. # $(3) => additional variables
  62. define Build/Compile/HostPyMod
  63. $(call Build/Compile/HostPyRunHost, \
  64. cd $(HOST_BUILD_DIR)/$(strip $(1)), \
  65. ./setup.py $(2), \
  66. $(3))
  67. endef
  68. endif # __python_host_mk_inc