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.

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