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.

112 lines
3.3 KiB

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