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.

100 lines
3.0 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. PYTHONPATH+=:$(PKG_INSTALL_DIR)/$(PYTHON_PKG_DIR)
  19. define HostPython
  20. ( export PYTHONPATH="$(PYTHONPATH)"; \
  21. export PYTHONOPTIMIZE=""; \
  22. export PYTHONDONTWRITEBYTECODE=1; \
  23. $(1) \
  24. $(HOST_PYTHON_BIN) $(2); \
  25. )
  26. endef
  27. PKG_USE_MIPS16:=0
  28. # This is required in addition to PKG_USE_MIPS16:=0 because otherwise MIPS16
  29. # flags are inherited from the Python base package (via sysconfig module)
  30. ifdef CONFIG_USE_MIPS16
  31. TARGET_CFLAGS += -mno-mips16 -mno-interlink-mips16
  32. endif
  33. define PyPackage
  34. $(call shexport,PyPackage/$(1)/filespec)
  35. define Package/$(1)/install
  36. find $(PKG_INSTALL_DIR) -name "*\.pyc" -o -name "*\.pyo" | xargs rm -f
  37. @echo "$$$$$$$$$$(call shvar,PyPackage/$(1)/filespec)" | ( \
  38. IFS='|'; \
  39. while read fop fspec fperm; do \
  40. if [ "$$$$$$$$fop" = "+" ]; then \
  41. if [ ! -e "$(PKG_INSTALL_DIR)$$$$$$$$fspec" ]; then \
  42. echo "File not found '$(PKG_INSTALL_DIR)$$$$$$$$fspec'"; \
  43. exit 1; \
  44. fi; \
  45. dpath=`dirname "$$$$$$$$fspec"`; \
  46. if [ -n "$$$$$$$$fperm" ]; then \
  47. dperm="-m$$$$$$$$fperm"; \
  48. else \
  49. dperm=`stat -c "%a" $(PKG_INSTALL_DIR)$$$$$$$$dpath`; \
  50. fi; \
  51. mkdir -p $$$$$$$$$dperm $$(1)$$$$$$$$dpath; \
  52. echo "copying: '$$$$$$$$fspec'"; \
  53. cp -fpR $(PKG_INSTALL_DIR)$$$$$$$$fspec $$(1)$$$$$$$$dpath/; \
  54. if [ -n "$$$$$$$$fperm" ]; then \
  55. chmod -R $$$$$$$$fperm $$(1)$$$$$$$$fspec; \
  56. fi; \
  57. elif [ "$$$$$$$$fop" = "-" ]; then \
  58. echo "removing: '$$$$$$$$fspec'"; \
  59. rm -fR $$(1)$$$$$$$$fspec; \
  60. elif [ "$$$$$$$$fop" = "=" ]; then \
  61. echo "setting permissions: '$$$$$$$$fperm' on '$$$$$$$$fspec'"; \
  62. chmod -R $$$$$$$$fperm $$(1)$$$$$$$$fspec; \
  63. fi; \
  64. done; \
  65. )
  66. $(call PyPackage/$(1)/install,$$(1))
  67. endef
  68. endef
  69. # $(1) => build subdir
  70. # $(2) => additional arguments to setup.py
  71. # $(3) => additional variables
  72. define Build/Compile/PyMod
  73. $(INSTALL_DIR) $(PKG_INSTALL_DIR)/$(PYTHON_PKG_DIR)
  74. $(call HostPython, \
  75. cd $(PKG_BUILD_DIR)/$(strip $(1)); \
  76. CC="$(TARGET_CC)" \
  77. CCSHARED="$(TARGET_CC) $(FPIC)" \
  78. LD="$(TARGET_CC)" \
  79. LDSHARED="$(TARGET_CC) -shared" \
  80. CFLAGS="$(TARGET_CFLAGS)" \
  81. CPPFLAGS="$(TARGET_CPPFLAGS) -I$(PYTHON_INC_DIR)" \
  82. LDFLAGS="$(TARGET_LDFLAGS) -lpython$(PYTHON_VERSION)" \
  83. _PYTHON_HOST_PLATFORM="linux-$(ARCH)" \
  84. __PYVENV_LAUNCHER__="/usr/bin/$(PYTHON)" \
  85. $(3) \
  86. , \
  87. ./setup.py $(2) \
  88. )
  89. find $(PKG_INSTALL_DIR) -name "*\.pyc" -o -name "*\.pyo" | xargs rm -f
  90. endef