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.

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