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.

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