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.

135 lines
3.7 KiB

  1. #
  2. # Copyright (C) 2006-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. python_mk_path:=$(dir $(lastword $(MAKEFILE_LIST)))
  9. include $(python_mk_path)python-host.mk
  10. PYTHON_DIR:=$(STAGING_DIR)/usr
  11. PYTHON_BIN_DIR:=$(PYTHON_DIR)/bin
  12. PYTHON_INC_DIR:=$(PYTHON_DIR)/include/python$(PYTHON_VERSION)
  13. PYTHON_LIB_DIR:=$(PYTHON_DIR)/lib/python$(PYTHON_VERSION)
  14. PYTHON_PKG_DIR:=/usr/lib/python$(PYTHON_VERSION)/site-packages
  15. PYTHON:=python$(PYTHON_VERSION)
  16. PYTHONPATH:=$(PYTHON_LIB_DIR):$(STAGING_DIR)/$(PYTHON_PKG_DIR):$(PKG_INSTALL_DIR)/$(PYTHON_PKG_DIR)
  17. # These configure args are needed in detection of path to Python header files
  18. # using autotools.
  19. CONFIGURE_ARGS += \
  20. _python_sysroot="$(STAGING_DIR)" \
  21. _python_prefix="/usr" \
  22. _python_exec_prefix="/usr"
  23. PKG_USE_MIPS16:=0
  24. # This is required in addition to PKG_USE_MIPS16:=0 because otherwise MIPS16
  25. # flags are inherited from the Python base package (via sysconfig module)
  26. ifdef CONFIG_USE_MIPS16
  27. TARGET_CFLAGS += -mno-mips16 -mno-interlink-mips16
  28. endif
  29. define PyPackage
  30. define Package/$(1)-src
  31. $(call Package/$(1))
  32. TITLE+= (sources)
  33. DEPENDS:=$$$$(foreach dep,$$$$(filter +python-%,$$$$(DEPENDS)),$$$$(dep)-src)
  34. endef
  35. define Package/$(1)-src/description
  36. $(call Package/$(1)/description).
  37. (Contains the Python sources for this package).
  38. endef
  39. # Add default PyPackage filespec none defined
  40. ifndef PyPackage/$(1)/filespec
  41. define PyPackage/$(1)/filespec
  42. +|$(PYTHON_PKG_DIR)
  43. endef
  44. endif
  45. ifndef PyPackage/$(1)/install
  46. define PyPackage/$(1)/install
  47. if [ -d $(PKG_INSTALL_DIR)/usr/bin ]; then \
  48. $(INSTALL_DIR) $$(1)/usr/bin ; \
  49. $(CP) $(PKG_INSTALL_DIR)/usr/bin/* $$(1)/usr/bin/ ; \
  50. fi
  51. endef
  52. endif
  53. ifndef Package/$(1)/install
  54. $(call shexport,PyPackage/$(1)/filespec)
  55. define Package/$(1)/install
  56. $(call PyPackage/$(1)/install,$$(1))
  57. find $(PKG_INSTALL_DIR) -name "*\.exe" | xargs rm -f
  58. $(SHELL) $(python_mk_path)python-package-install.sh "2" \
  59. "$(PKG_INSTALL_DIR)" "$$(1)" \
  60. "$(HOST_PYTHON_BIN)" "$$(2)" \
  61. "$$$$$$$$$$(call shvar,PyPackage/$(1)/filespec)"
  62. endef
  63. define Package/$(1)-src/install
  64. $$(call Package/$(1)/install,$$(1),sources)
  65. endef
  66. endif # Package/$(1)/install
  67. endef
  68. # $(1) => commands to execute before running pythons script
  69. # $(2) => python script and its arguments
  70. # $(3) => additional variables
  71. define Build/Compile/HostPyRunTarget
  72. $(call HostPython, \
  73. $(if $(1),$(1);) \
  74. CC="$(TARGET_CC)" \
  75. CCSHARED="$(TARGET_CC) $(FPIC)" \
  76. CXX="$(TARGET_CXX)" \
  77. LD="$(TARGET_CC)" \
  78. LDSHARED="$(TARGET_CC) -shared" \
  79. CFLAGS="$(TARGET_CFLAGS)" \
  80. CPPFLAGS="$(TARGET_CPPFLAGS) -I$(PYTHON_INC_DIR)" \
  81. LDFLAGS="$(TARGET_LDFLAGS) -lpython$(PYTHON_VERSION)" \
  82. _PYTHON_HOST_PLATFORM=linux2 \
  83. __PYVENV_LAUNCHER__="/usr/bin/$(PYTHON)" \
  84. $(3) \
  85. , \
  86. $(2) \
  87. )
  88. endef
  89. # $(1) => build subdir
  90. # $(2) => additional arguments to setup.py
  91. # $(3) => additional variables
  92. define Build/Compile/PyMod
  93. $(INSTALL_DIR) $(PKG_INSTALL_DIR)/$(PYTHON_PKG_DIR)
  94. $(call Build/Compile/HostPyRunTarget, \
  95. cd $(PKG_BUILD_DIR)/$(strip $(1)), \
  96. ./setup.py $(2), \
  97. $(3))
  98. find $(PKG_INSTALL_DIR) -name "*\.exe" | xargs rm -f
  99. endef
  100. define PyBuild/Compile/Default
  101. $(foreach pkg,$(HOST_PYTHON_PACKAGE_BUILD_DEPENDS),
  102. $(call host_python_pip_install_host,$(pkg))
  103. )
  104. $(call Build/Compile/PyMod,, \
  105. install --prefix="/usr" --root="$(PKG_INSTALL_DIR)" \
  106. --single-version-externally-managed \
  107. )
  108. endef
  109. PyBuild/Compile=$(PyBuild/Compile/Default)
  110. ifeq ($(BUILD_VARIANT),python)
  111. define Build/Compile
  112. $(call PyBuild/Compile)
  113. endef
  114. endif # python