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.

126 lines
4.0 KiB

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