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. 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)
  18. PYTHON3PATH+=:$(PKG_INSTALL_DIR)/$(PYTHON3_PKG_DIR)
  19. define HostPython3
  20. ( export PYTHONPATH="$(PYTHON3PATH)"; \
  21. export PYTHONOPTIMIZE=""; \
  22. export PYTHONDONTWRITEBYTECODE=1; \
  23. $(1) \
  24. $(HOST_PYTHON3_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 Py3Package
  34. $(call shexport,Py3Package/$(1)/filespec)
  35. define Package/$(1)/install
  36. find $(PKG_INSTALL_DIR) -name "*\.pyc" -o -name "*\.pyo" | xargs rm -f
  37. @echo "$$$$$$$$$$(call shvar,Py3Package/$(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 Py3Package/$(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/Py3Mod
  73. $(INSTALL_DIR) $(PKG_INSTALL_DIR)/$(PYTHON3_PKG_DIR)
  74. $(call HostPython3, \
  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$(PYTHON3_INC_DIR)" \
  82. LDFLAGS="$(TARGET_LDFLAGS) -lpython$(PYTHON3_VERSION)" \
  83. _PYTHON_HOST_PLATFORM="linux-$(ARCH)" \
  84. __PYVENV_LAUNCHER__="/usr/bin/$(PYTHON3)" \
  85. $(3) \
  86. , \
  87. ./setup.py $(2) \
  88. )
  89. find $(PKG_INSTALL_DIR) -name "*\.pyc" -o -name "*\.pyo" | xargs rm -f
  90. endef