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