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.

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