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.

129 lines
4.2 KiB

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