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.

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