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
4.3 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. # Add default PyPackage filespec none defined
  29. ifndef PyPackage/$(1)/filespec
  30. define PyPackage/$(1)/filespec
  31. +|$(PYTHON_PKG_DIR)
  32. endef
  33. endif
  34. $(call shexport,PyPackage/$(1)/filespec)
  35. define Package/$(1)/install
  36. find $(PKG_INSTALL_DIR) -name "*\.pyc" -o -name "*\.pyo" -o -name "*\.exe" | xargs rm -f
  37. @echo "$$$$$$$$$$(call shvar,PyPackage/$(1)/filespec)" | ( \
  38. IFS='|'; \
  39. while read fop fspec fperm; do \
  40. fop=`echo "$$$$$$$$fop" | tr -d ' \t\n'`; \
  41. if [ "$$$$$$$$fop" = "+" ]; then \
  42. if [ ! -e "$(PKG_INSTALL_DIR)$$$$$$$$fspec" ]; then \
  43. echo "File not found '$(PKG_INSTALL_DIR)$$$$$$$$fspec'"; \
  44. exit 1; \
  45. fi; \
  46. dpath=`dirname "$$$$$$$$fspec"`; \
  47. if [ -n "$$$$$$$$fperm" ]; then \
  48. dperm="-m$$$$$$$$fperm"; \
  49. else \
  50. dperm=`stat -c "%a" $(PKG_INSTALL_DIR)$$$$$$$$dpath`; \
  51. fi; \
  52. mkdir -p $$$$$$$$$dperm $$(1)$$$$$$$$dpath; \
  53. echo "copying: '$$$$$$$$fspec'"; \
  54. cp -fpR $(PKG_INSTALL_DIR)$$$$$$$$fspec $$(1)$$$$$$$$dpath/; \
  55. if [ -n "$$$$$$$$fperm" ]; then \
  56. chmod -R $$$$$$$$fperm $$(1)$$$$$$$$fspec; \
  57. fi; \
  58. elif [ "$$$$$$$$fop" = "-" ]; then \
  59. echo "removing: '$$$$$$$$fspec'"; \
  60. rm -fR $$(1)$$$$$$$$fspec; \
  61. elif [ "$$$$$$$$fop" = "=" ]; then \
  62. echo "setting permissions: '$$$$$$$$fperm' on '$$$$$$$$fspec'"; \
  63. chmod -R $$$$$$$$fperm $$(1)$$$$$$$$fspec; \
  64. fi; \
  65. done; \
  66. )
  67. $(call PyPackage/$(1)/install,$$(1))
  68. endef
  69. endef
  70. $(call include_mk, python-host.mk)
  71. # $(1) => commands to execute before running pythons script
  72. # $(2) => python script and its arguments
  73. # $(3) => additional variables
  74. define Build/Compile/HostPyRunTarget
  75. $(call HostPython, \
  76. $(if $(1),$(1);) \
  77. CC="$(TARGET_CC)" \
  78. CCSHARED="$(TARGET_CC) $(FPIC)" \
  79. CXX="$(TARGET_CXX)" \
  80. LD="$(TARGET_CC)" \
  81. LDSHARED="$(TARGET_CC) -shared" \
  82. CFLAGS="$(TARGET_CFLAGS)" \
  83. CPPFLAGS="$(TARGET_CPPFLAGS) -I$(PYTHON_INC_DIR)" \
  84. LDFLAGS="$(TARGET_LDFLAGS) -lpython$(PYTHON_VERSION)" \
  85. _PYTHON_HOST_PLATFORM=linux2 \
  86. __PYVENV_LAUNCHER__="/usr/bin/$(PYTHON)" \
  87. $(3) \
  88. , \
  89. $(2) \
  90. )
  91. endef
  92. # $(1) => build subdir
  93. # $(2) => additional arguments to setup.py
  94. # $(3) => additional variables
  95. define Build/Compile/PyMod
  96. $(INSTALL_DIR) $(PKG_INSTALL_DIR)/$(PYTHON_PKG_DIR)
  97. $(call Build/Compile/HostPyRunTarget, \
  98. cd $(PKG_BUILD_DIR)/$(strip $(1)), \
  99. ./setup.py $(2), \
  100. $(3))
  101. find $(PKG_INSTALL_DIR) -name "*\.pyc" -o -name "*\.pyo" -o -name "*\.exe" | xargs rm -f
  102. endef
  103. define PyMod/Default
  104. define Build/Compile
  105. $$(call Build/Compile/PyMod,,install --prefix=/usr --root=$(PKG_INSTALL_DIR))
  106. endef
  107. define Package/$(PKG_NAME)/install
  108. $(INSTALL_DIR) $$(1)$(PYTHON_PKG_DIR) $$(1)/usr/bin
  109. if [ -d $(PKG_INSTALL_DIR)/usr/bin ]; then find $(PKG_INSTALL_DIR)/usr/bin -mindepth 1 -maxdepth 1 -type f -exec $(CP) \{\} $$(1)/usr/bin/ \; ; fi
  110. find $(PKG_INSTALL_DIR)$(PYTHON_PKG_DIR) -mindepth 1 -maxdepth 1 \( -type f -o -type d \) -exec $(CP) \{\} $$(1)$(PYTHON_PKG_DIR)/ \;
  111. endef
  112. define Build/InstallDev
  113. $(INSTALL_DIR) $$(1)/usr/bin $$(1)$(PYTHON_PKG_DIR)
  114. if [ -d $(PKG_INSTALL_DIR)/usr/bin ]; then find $(PKG_INSTALL_DIR)/usr/bin -mindepth 1 -maxdepth 1 -type f -exec $(CP) \{\} $$(1)/usr/bin/ \; ; fi
  115. find $(PKG_INSTALL_DIR)$(PYTHON_PKG_DIR) -mindepth 1 -maxdepth 1 \( -type f -o -type d \) -exec $(CP) \{\} $$(1)$(PYTHON_PKG_DIR)/ \;
  116. endef
  117. endef