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.

122 lines
3.7 KiB

  1. #
  2. # Copyright (C) 2007-2016 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_MAJOR:=3
  8. PYTHON3_VERSION_MINOR:=5
  9. PYTHON3_VERSION_MICRO:=2
  10. PYTHON3_VERSION:=$(PYTHON3_VERSION_MAJOR).$(PYTHON3_VERSION_MINOR)
  11. PYTHON3_DIR:=$(STAGING_DIR)/usr
  12. PYTHON3_BIN_DIR:=$(PYTHON3_DIR)/bin
  13. PYTHON3_INC_DIR:=$(PYTHON3_DIR)/include/python$(PYTHON3_VERSION)
  14. PYTHON3_LIB_DIR:=$(PYTHON3_DIR)/lib/python$(PYTHON3_VERSION)
  15. PYTHON3_PKG_DIR:=/usr/lib/python$(PYTHON3_VERSION)/site-packages
  16. PYTHON3:=python$(PYTHON3_VERSION)
  17. HOST_PYTHON3_LIB_DIR:=$(STAGING_DIR)/host/lib/python$(PYTHON3_VERSION)
  18. HOST_PYTHON3_BIN:=$(STAGING_DIR)/host/bin/python3
  19. PYTHON3PATH:=$(PYTHON3_LIB_DIR):$(STAGING_DIR)/$(PYTHON3_PKG_DIR):$(PKG_INSTALL_DIR)/$(PYTHON3_PKG_DIR)
  20. define HostPython3
  21. ( export PYTHONPATH="$(PYTHON3PATH)"; \
  22. export PYTHONOPTIMIZE=""; \
  23. export PYTHONDONTWRITEBYTECODE=1; \
  24. export _python_sysroot="$(STAGING_DIR)"; \
  25. export _python_prefix="/usr"; \
  26. export _python_exec_prefix="/usr"; \
  27. $(1) \
  28. $(HOST_PYTHON3_BIN) $(2); \
  29. )
  30. endef
  31. # These configure args are needed in detection of path to Python header files
  32. # using autotools.
  33. CONFIGURE_ARGS += \
  34. _python_sysroot="$(STAGING_DIR)" \
  35. _python_prefix="/usr" \
  36. _python_exec_prefix="/usr"
  37. PKG_USE_MIPS16:=0
  38. # This is required in addition to PKG_USE_MIPS16:=0 because otherwise MIPS16
  39. # flags are inherited from the Python base package (via sysconfig module)
  40. ifdef CONFIG_USE_MIPS16
  41. TARGET_CFLAGS += -mno-mips16 -mno-interlink-mips16
  42. endif
  43. define Py3Package
  44. # Add default PyPackage filespec none defined
  45. ifndef Py3Package/$(1)/filespec
  46. define Py3Package/$(1)/filespec
  47. +|$(PYTHON3_PKG_DIR)
  48. endef
  49. endif
  50. $(call shexport,Py3Package/$(1)/filespec)
  51. define Package/$(1)/install
  52. find $(PKG_INSTALL_DIR) -name "*\.pyc" -o -name "*\.pyo" -o -name "*\.exe" | xargs rm -f
  53. @echo "$$$$$$$$$$(call shvar,Py3Package/$(1)/filespec)" | ( \
  54. IFS='|'; \
  55. while read fop fspec fperm; do \
  56. fop=`echo "$$$$$$$$fop" | tr -d ' \t\n'`; \
  57. if [ "$$$$$$$$fop" = "+" ]; then \
  58. if [ ! -e "$(PKG_INSTALL_DIR)$$$$$$$$fspec" ]; then \
  59. echo "File not found '$(PKG_INSTALL_DIR)$$$$$$$$fspec'"; \
  60. exit 1; \
  61. fi; \
  62. dpath=`dirname "$$$$$$$$fspec"`; \
  63. if [ -n "$$$$$$$$fperm" ]; then \
  64. dperm="-m$$$$$$$$fperm"; \
  65. else \
  66. dperm=`stat -c "%a" $(PKG_INSTALL_DIR)$$$$$$$$dpath`; \
  67. fi; \
  68. mkdir -p $$$$$$$$$dperm $$(1)$$$$$$$$dpath; \
  69. echo "copying: '$$$$$$$$fspec'"; \
  70. cp -fpR $(PKG_INSTALL_DIR)$$$$$$$$fspec $$(1)$$$$$$$$dpath/; \
  71. if [ -n "$$$$$$$$fperm" ]; then \
  72. chmod -R $$$$$$$$fperm $$(1)$$$$$$$$fspec; \
  73. fi; \
  74. elif [ "$$$$$$$$fop" = "-" ]; then \
  75. echo "removing: '$$$$$$$$fspec'"; \
  76. rm -fR $$(1)$$$$$$$$fspec; \
  77. elif [ "$$$$$$$$fop" = "=" ]; then \
  78. echo "setting permissions: '$$$$$$$$fperm' on '$$$$$$$$fspec'"; \
  79. chmod -R $$$$$$$$fperm $$(1)$$$$$$$$fspec; \
  80. fi; \
  81. done; \
  82. )
  83. $(call Py3Package/$(1)/install,$$(1))
  84. endef
  85. endef
  86. # $(1) => build subdir
  87. # $(2) => additional arguments to setup.py
  88. # $(3) => additional variables
  89. define Build/Compile/Py3Mod
  90. $(INSTALL_DIR) $(PKG_INSTALL_DIR)/$(PYTHON3_PKG_DIR)
  91. $(call HostPython3, \
  92. cd $(PKG_BUILD_DIR)/$(strip $(1)); \
  93. CC="$(TARGET_CC)" \
  94. CCSHARED="$(TARGET_CC) $(FPIC)" \
  95. LD="$(TARGET_CC)" \
  96. LDSHARED="$(TARGET_CC) -shared" \
  97. CFLAGS="$(TARGET_CFLAGS)" \
  98. CPPFLAGS="$(TARGET_CPPFLAGS) -I$(PYTHON3_INC_DIR)" \
  99. LDFLAGS="$(TARGET_LDFLAGS) -lpython$(PYTHON3_VERSION)" \
  100. _PYTHON_HOST_PLATFORM=linux2 \
  101. __PYVENV_LAUNCHER__="/usr/bin/$(PYTHON3)" \
  102. $(3) \
  103. , \
  104. ./setup.py $(2) \
  105. )
  106. find $(PKG_INSTALL_DIR) -name "*\.pyc" -o -name "*\.pyo" -o -name "*\.exe" | xargs rm -f
  107. endef