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.

109 lines
3.2 KiB

  1. #
  2. # Copyright (C) 2007-2014 OpenWrt.org
  3. #
  4. # This is free software, licensed under the GNU General Public License v2.
  5. # See /LICENSE for more information.
  6. #
  7. PYTHON_VERSION:=2.7
  8. PYTHON_VERSION_MICRO:=9
  9. PYTHON_DIR:=$(STAGING_DIR)/usr
  10. PYTHON_BIN_DIR:=$(PYTHON_DIR)/bin
  11. PYTHON_INC_DIR:=$(PYTHON_DIR)/include/python$(PYTHON_VERSION)
  12. PYTHON_LIB_DIR:=$(PYTHON_DIR)/lib/python$(PYTHON_VERSION)
  13. PYTHON_PKG_DIR:=/usr/lib/python$(PYTHON_VERSION)/site-packages
  14. PYTHON:=python$(PYTHON_VERSION)
  15. HOST_PYTHON_LIB_DIR:=$(STAGING_DIR_HOST)/lib/python$(PYTHON_VERSION)
  16. HOST_PYTHON_BIN:=$(STAGING_DIR_HOST)/bin/python2
  17. PYTHONPATH:=$(PYTHON_LIB_DIR):$(STAGING_DIR)/$(PYTHON_PKG_DIR):$(PKG_INSTALL_DIR)/$(PYTHON_PKG_DIR)
  18. define HostPython
  19. ( export PYTHONPATH="$(PYTHONPATH)"; \
  20. export PYTHONOPTIMIZE=""; \
  21. export PYTHONDONTWRITEBYTECODE=1; \
  22. $(1) \
  23. $(HOST_PYTHON_BIN) $(2); \
  24. )
  25. endef
  26. PKG_USE_MIPS16:=0
  27. # This is required in addition to PKG_USE_MIPS16:=0 because otherwise MIPS16
  28. # flags are inherited from the Python base package (via sysconfig module)
  29. ifdef CONFIG_USE_MIPS16
  30. TARGET_CFLAGS += -mno-mips16 -mno-interlink-mips16
  31. endif
  32. define PyPackage
  33. # Add default PyPackage filespec none defined
  34. ifndef PyPackage/$(1)/filespec
  35. define PyPackage/$(1)/filespec
  36. +|$(PYTHON_PKG_DIR)
  37. endef
  38. endif
  39. $(call shexport,PyPackage/$(1)/filespec)
  40. define Package/$(1)/install
  41. find $(PKG_INSTALL_DIR) -name "*\.pyc" -o -name "*\.pyo" | xargs rm -f
  42. @echo "$$$$$$$$$$(call shvar,PyPackage/$(1)/filespec)" | ( \
  43. IFS='|'; \
  44. while read fop fspec fperm; do \
  45. fop=`echo "$$$$$$$$fop" | tr -d ' \t\n'`; \
  46. if [ "$$$$$$$$fop" = "+" ]; then \
  47. if [ ! -e "$(PKG_INSTALL_DIR)$$$$$$$$fspec" ]; then \
  48. echo "File not found '$(PKG_INSTALL_DIR)$$$$$$$$fspec'"; \
  49. exit 1; \
  50. fi; \
  51. dpath=`dirname "$$$$$$$$fspec"`; \
  52. if [ -n "$$$$$$$$fperm" ]; then \
  53. dperm="-m$$$$$$$$fperm"; \
  54. else \
  55. dperm=`stat -c "%a" $(PKG_INSTALL_DIR)$$$$$$$$dpath`; \
  56. fi; \
  57. mkdir -p $$$$$$$$$dperm $$(1)$$$$$$$$dpath; \
  58. echo "copying: '$$$$$$$$fspec'"; \
  59. cp -fpR $(PKG_INSTALL_DIR)$$$$$$$$fspec $$(1)$$$$$$$$dpath/; \
  60. if [ -n "$$$$$$$$fperm" ]; then \
  61. chmod -R $$$$$$$$fperm $$(1)$$$$$$$$fspec; \
  62. fi; \
  63. elif [ "$$$$$$$$fop" = "-" ]; then \
  64. echo "removing: '$$$$$$$$fspec'"; \
  65. rm -fR $$(1)$$$$$$$$fspec; \
  66. elif [ "$$$$$$$$fop" = "=" ]; then \
  67. echo "setting permissions: '$$$$$$$$fperm' on '$$$$$$$$fspec'"; \
  68. chmod -R $$$$$$$$fperm $$(1)$$$$$$$$fspec; \
  69. fi; \
  70. done; \
  71. )
  72. $(call PyPackage/$(1)/install,$$(1))
  73. endef
  74. endef
  75. # $(1) => build subdir
  76. # $(2) => additional arguments to setup.py
  77. # $(3) => additional variables
  78. define Build/Compile/PyMod
  79. $(INSTALL_DIR) $(PKG_INSTALL_DIR)/$(PYTHON_PKG_DIR)
  80. $(call HostPython, \
  81. cd $(PKG_BUILD_DIR)/$(strip $(1)); \
  82. CC="$(TARGET_CC)" \
  83. CCSHARED="$(TARGET_CC) $(FPIC)" \
  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. ./setup.py $(2) \
  94. )
  95. find $(PKG_INSTALL_DIR) -name "*\.pyc" -o -name "*\.pyo" | xargs rm -f
  96. endef