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.

98 lines
2.9 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:=8
  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)
  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. $(call shexport,PyPackage/$(1)/filespec)
  34. define Package/$(1)/install
  35. find $(PKG_INSTALL_DIR) -name "*\.pyc" -o -name "*\.pyo" | xargs rm -f
  36. @echo "$$$$$$$$$$(call shvar,PyPackage/$(1)/filespec)" | ( \
  37. IFS='|'; \
  38. while read fop fspec fperm; do \
  39. if [ "$$$$$$$$fop" = "+" ]; then \
  40. if [ ! -e "$(PKG_INSTALL_DIR)$$$$$$$$fspec" ]; then \
  41. echo "File not found '$(PKG_INSTALL_DIR)$$$$$$$$fspec'"; \
  42. exit 1; \
  43. fi; \
  44. dpath=`dirname "$$$$$$$$fspec"`; \
  45. if [ -n "$$$$$$$$fperm" ]; then \
  46. dperm="-m$$$$$$$$fperm"; \
  47. else \
  48. dperm=`stat -c "%a" $(PKG_INSTALL_DIR)$$$$$$$$dpath`; \
  49. fi; \
  50. mkdir -p $$$$$$$$$dperm $$(1)$$$$$$$$dpath; \
  51. echo "copying: '$$$$$$$$fspec'"; \
  52. cp -fpR $(PKG_INSTALL_DIR)$$$$$$$$fspec $$(1)$$$$$$$$dpath/; \
  53. if [ -n "$$$$$$$$fperm" ]; then \
  54. chmod -R $$$$$$$$fperm $$(1)$$$$$$$$fspec; \
  55. fi; \
  56. elif [ "$$$$$$$$fop" = "-" ]; then \
  57. echo "removing: '$$$$$$$$fspec'"; \
  58. rm -fR $$(1)$$$$$$$$fspec; \
  59. elif [ "$$$$$$$$fop" = "=" ]; then \
  60. echo "setting permissions: '$$$$$$$$fperm' on '$$$$$$$$fspec'"; \
  61. chmod -R $$$$$$$$fperm $$(1)$$$$$$$$fspec; \
  62. fi; \
  63. done; \
  64. )
  65. $(call PyPackage/$(1)/install,$$(1))
  66. endef
  67. endef
  68. # $(1) => build subdir
  69. # $(2) => additional arguments to setup.py
  70. # $(3) => additional variables
  71. define Build/Compile/PyMod
  72. $(call HostPython, \
  73. cd $(PKG_BUILD_DIR)/$(strip $(1)); \
  74. CC="$(TARGET_CC)" \
  75. CCSHARED="$(TARGET_CC) $(FPIC)" \
  76. LD="$(TARGET_CC)" \
  77. LDSHARED="$(TARGET_CC) -shared" \
  78. CFLAGS="$(TARGET_CFLAGS)" \
  79. CPPFLAGS="$(TARGET_CPPFLAGS) -I$(PYTHON_INC_DIR)" \
  80. LDFLAGS="$(TARGET_LDFLAGS) -lpython$(PYTHON_VERSION)" \
  81. _PYTHON_HOST_PLATFORM="linux-$(ARCH)" \
  82. __PYVENV_LAUNCHER__="/usr/bin/$(PYTHON)" \
  83. $(3) \
  84. , \
  85. ./setup.py $(2) \
  86. )
  87. find $(PKG_INSTALL_DIR) -name "*\.pyc" -o -name "*\.pyo" | xargs rm -f
  88. endef