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.

96 lines
2.6 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. # Note: include this after `include $(TOPDIR)/rules.mk in your package Makefile
  8. # if `python-package.mk` is included, this will already be included
  9. ifneq ($(__python_host_mk_inc),1)
  10. __python_host_mk_inc=1
  11. # For PYTHON_VERSION
  12. python_mk_path:=$(dir $(lastword $(MAKEFILE_LIST)))
  13. include $(python_mk_path)python-version.mk
  14. HOST_PYTHON_DIR:=$(STAGING_DIR_HOSTPKG)
  15. HOST_PYTHON_INC_DIR:=$(HOST_PYTHON_DIR)/include/python$(PYTHON_VERSION)
  16. HOST_PYTHON_LIB_DIR:=$(HOST_PYTHON_DIR)/lib/python$(PYTHON_VERSION)
  17. HOST_PYTHON_PKG_DIR:=$(HOST_PYTHON_DIR)/lib/python$(PYTHON_VERSION)/site-packages
  18. HOST_PYTHON_BIN:=$(HOST_PYTHON_DIR)/bin/python$(PYTHON_VERSION)
  19. HOST_PYTHONPATH:=$(HOST_PYTHON_LIB_DIR):$(HOST_PYTHON_PKG_DIR)
  20. define HostPython
  21. if [ "$(strip $(3))" == "HOST" ]; then \
  22. export PYTHONPATH="$(HOST_PYTHONPATH)"; \
  23. export PYTHONDONTWRITEBYTECODE=0; \
  24. else \
  25. export PYTHONPATH="$(PYTHONPATH)"; \
  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_PYTHON_BIN) $(2);
  34. endef
  35. define host_python_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_PYTHON_INC_DIR)" \
  44. LDFLAGS="$(HOST_LDFLAGS) -lpython$(PYTHON_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/HostPyRunHost
  51. $(call HostPython, \
  52. $(if $(1),$(1);) \
  53. $(call host_python_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_PYTHON_PIP:=$(STAGING_DIR_HOSTPKG)/bin/pip$(PYTHON_VERSION)
  63. define host_python_pip_install
  64. $(call host_python_settings) \
  65. $(HOST_PYTHON_PIP) install \
  66. --root=$(1) \
  67. --prefix=$(2) \
  68. $(3)
  69. endef
  70. define host_python_pip_install_host
  71. $(call host_python_pip_install,$(STAGING_DIR_HOSTPKG),"",$(1))
  72. endef
  73. # $(1) => build subdir
  74. # $(2) => additional arguments to setup.py
  75. # $(3) => additional variables
  76. define Build/Compile/HostPyMod
  77. $(call Build/Compile/HostPyRunHost, \
  78. cd $(HOST_BUILD_DIR)/$(strip $(1)), \
  79. ./setup.py $(2), \
  80. $(3))
  81. endef
  82. endif # __python_host_mk_inc