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.

146 lines
3.8 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. DEPENDS:=
  33. CONFLICTS:=
  34. PROVIDES:=
  35. EXTRA_DEPENDS:=
  36. TITLE+= (sources)
  37. USERID:=
  38. endef
  39. define Package/$(1)-src/description
  40. $(call Package/$(1)/description).
  41. (Contains the Python sources for this package).
  42. endef
  43. # Add default PyPackage filespec none defined
  44. ifndef PyPackage/$(1)/filespec
  45. define PyPackage/$(1)/filespec
  46. +|$(PYTHON_PKG_DIR)
  47. endef
  48. endif
  49. ifndef PyPackage/$(1)/install
  50. define PyPackage/$(1)/install
  51. if [ -d $(PKG_INSTALL_DIR)/usr/bin ]; then \
  52. $(INSTALL_DIR) $$(1)/usr/bin ; \
  53. $(CP) $(PKG_INSTALL_DIR)/usr/bin/* $$(1)/usr/bin/ ; \
  54. fi
  55. endef
  56. endif
  57. ifndef Package/$(1)/install
  58. $(call shexport,PyPackage/$(1)/filespec)
  59. define Package/$(1)/install
  60. $$(call PyPackage/$(1)/install,$$(1))
  61. SED="$(SED)" \
  62. $(SHELL) $(python_mk_path)python-package-install.sh "2" \
  63. "$(PKG_INSTALL_DIR)" "$$(1)" \
  64. "$(HOST_PYTHON_BIN)" "$$(2)" \
  65. "$$$$$$$$$$(call shvar,PyPackage/$(1)/filespec)"
  66. endef
  67. define Package/$(1)-src/install
  68. $$(call Package/$(1)/install,$$(1),sources)
  69. endef
  70. endif # Package/$(1)/install
  71. endef
  72. # $(1) => commands to execute before running pythons script
  73. # $(2) => python script and its arguments
  74. # $(3) => additional variables
  75. define Build/Compile/HostPyRunTarget
  76. $(call HostPython, \
  77. $(if $(1),$(1);) \
  78. CC="$(TARGET_CC)" \
  79. CCSHARED="$(TARGET_CC) $(FPIC)" \
  80. CXX="$(TARGET_CXX)" \
  81. LD="$(TARGET_CC)" \
  82. LDSHARED="$(TARGET_CC) -shared" \
  83. CFLAGS="$(TARGET_CFLAGS)" \
  84. CPPFLAGS="$(TARGET_CPPFLAGS) -I$(PYTHON_INC_DIR)" \
  85. LDFLAGS="$(TARGET_LDFLAGS) -lpython$(PYTHON_VERSION)" \
  86. _PYTHON_HOST_PLATFORM=linux2 \
  87. __PYVENV_LAUNCHER__="/usr/bin/$(PYTHON)" \
  88. $(3) \
  89. , \
  90. $(2) \
  91. )
  92. endef
  93. # $(1) => build subdir
  94. # $(2) => additional arguments to setup.py
  95. # $(3) => additional variables
  96. define Build/Compile/PyMod
  97. $(INSTALL_DIR) $(PKG_INSTALL_DIR)/$(PYTHON_PKG_DIR)
  98. $(call Build/Compile/HostPyRunTarget, \
  99. cd $(PKG_BUILD_DIR)/$(strip $(1)), \
  100. ./setup.py $(2), \
  101. $(3))
  102. endef
  103. PYTHON_PKG_SETUP_DIR ?=
  104. PYTHON_PKG_SETUP_GLOBAL_ARGS ?=
  105. PYTHON_PKG_SETUP_ARGS ?= --single-version-externally-managed
  106. PYTHON_PKG_SETUP_VARS ?=
  107. define PyBuild/Compile/Default
  108. $(if $(HOST_PYTHON_PACKAGE_BUILD_DEPENDS),
  109. $(call Build/Compile/HostPyPipInstall,$(HOST_PYTHON_PACKAGE_BUILD_DEPENDS))
  110. )
  111. $(call Build/Compile/PyMod, \
  112. $(PYTHON_PKG_SETUP_DIR), \
  113. $(PYTHON_PKG_SETUP_GLOBAL_ARGS) \
  114. install --prefix="/usr" --root="$(PKG_INSTALL_DIR)" \
  115. $(PYTHON_PKG_SETUP_ARGS), \
  116. $(PYTHON_PKG_SETUP_VARS) \
  117. )
  118. endef
  119. PyBuild/Compile=$(PyBuild/Compile/Default)
  120. ifeq ($(BUILD_VARIANT),python)
  121. define Build/Compile
  122. $(call PyBuild/Compile)
  123. endef
  124. endif # python