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. PYTHON3_VERSION:=3.4
  8. PYTHON3_VERSION_MICRO:=2
  9. PYTHON3_DIR:=$(STAGING_DIR)/usr
  10. PYTHON3_BIN_DIR:=$(PYTHON3_DIR)/bin
  11. PYTHON3_INC_DIR:=$(PYTHON3_DIR)/include/python$(PYTHON3_VERSION)
  12. PYTHON3_LIB_DIR:=$(PYTHON3_DIR)/lib/python$(PYTHON3_VERSION)
  13. PYTHON3_PKG_DIR:=/usr/lib/python$(PYTHON3_VERSION)/site-packages
  14. PYTHON3:=python$(PYTHON3_VERSION)
  15. HOST_PYTHON3_LIB_DIR:=$(STAGING_DIR_HOST)/lib/python$(PYTHON3_VERSION)
  16. HOST_PYTHON3_BIN:=$(STAGING_DIR_HOST)/bin/python3
  17. PYTHON3PATH:=$(PYTHON3_LIB_DIR):$(STAGING_DIR)/$(PYTHON3_PKG_DIR):$(PKG_INSTALL_DIR)/$(PYTHON3_PKG_DIR)
  18. define HostPython3
  19. ( export PYTHONPATH="$(PYTHON3PATH)"; \
  20. export PYTHONOPTIMIZE=""; \
  21. export PYTHONDONTWRITEBYTECODE=1; \
  22. $(1) \
  23. $(HOST_PYTHON3_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 Py3Package
  33. # Add default PyPackage filespec none defined
  34. ifndef Py3Package/$(1)/filespec
  35. define Py3Package/$(1)/filespec
  36. +|$(PYTHON3_PKG_DIR)
  37. endef
  38. endif
  39. $(call shexport,Py3Package/$(1)/filespec)
  40. define Package/$(1)/install
  41. find $(PKG_INSTALL_DIR) -name "*\.pyc" -o -name "*\.pyo" | xargs rm -f
  42. @echo "$$$$$$$$$$(call shvar,Py3Package/$(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 Py3Package/$(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/Py3Mod
  79. $(INSTALL_DIR) $(PKG_INSTALL_DIR)/$(PYTHON3_PKG_DIR)
  80. $(call HostPython3, \
  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$(PYTHON3_INC_DIR)" \
  88. LDFLAGS="$(TARGET_LDFLAGS) -lpython$(PYTHON3_VERSION)" \
  89. _PYTHON_HOST_PLATFORM=linux2 \
  90. __PYVENV_LAUNCHER__="/usr/bin/$(PYTHON3)" \
  91. $(3) \
  92. , \
  93. ./setup.py $(2) \
  94. )
  95. find $(PKG_INSTALL_DIR) -name "*\.pyc" -o -name "*\.pyo" | xargs rm -f
  96. endef