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.

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