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.

136 lines
4.3 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:=12
  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" -o -name "*\.exe" | 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) => commands to execute before running pythons script
  73. # $(2) => python script and its arguments
  74. # $(3) => additional variables
  75. define Build/Compile/HostPyRunTarget
  76. $(call HostPython, \
  77. $(if $(1),$(1);) \
  78. CC="$(TARGET_CC)" \
  79. CCSHARED="$(TARGET_CC) $(FPIC)" \
  80. CXX="$(TARGET_CXX)" \
  81. LD="$(TARGET_CC)" \
  82. LDSHARED="$(TARGET_CC) -shared" \
  83. CFLAGS="$(TARGET_CFLAGS)" \
  84. CPPFLAGS="$(TARGET_CPPFLAGS) -I$(PYTHON_INC_DIR)" \
  85. LDFLAGS="$(TARGET_LDFLAGS) -lpython$(PYTHON_VERSION)" \
  86. _PYTHON_HOST_PLATFORM=linux2 \
  87. __PYVENV_LAUNCHER__="/usr/bin/$(PYTHON)" \
  88. $(3) \
  89. , \
  90. $(2) \
  91. )
  92. endef
  93. # $(1) => build subdir
  94. # $(2) => additional arguments to setup.py
  95. # $(3) => additional variables
  96. define Build/Compile/PyMod
  97. $(INSTALL_DIR) $(PKG_INSTALL_DIR)/$(PYTHON_PKG_DIR)
  98. $(call Build/Compile/HostPyRunTarget, \
  99. cd $(PKG_BUILD_DIR)/$(strip $(1)), \
  100. ./setup.py $(2), \
  101. $(3))
  102. find $(PKG_INSTALL_DIR) -name "*\.pyc" -o -name "*\.pyo" -o -name "*\.exe" | xargs rm -f
  103. endef
  104. define PyMod/Default
  105. define Build/Compile
  106. $$(call Build/Compile/PyMod,,install --prefix=/usr --root=$(PKG_INSTALL_DIR))
  107. endef
  108. define Package/$(PKG_NAME)/install
  109. $(INSTALL_DIR) $$(1)$(PYTHON_PKG_DIR) $$(1)/usr/bin
  110. 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
  111. find $(PKG_INSTALL_DIR)$(PYTHON_PKG_DIR) -mindepth 1 -maxdepth 1 \( -type f -o -type d \) -exec $(CP) \{\} $$(1)$(PYTHON_PKG_DIR)/ \;
  112. endef
  113. define Build/InstallDev
  114. $(INSTALL_DIR) $$(1)/usr/bin $$(1)$(PYTHON_PKG_DIR)
  115. 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
  116. find $(PKG_INSTALL_DIR)$(PYTHON_PKG_DIR) -mindepth 1 -maxdepth 1 \( -type f -o -type d \) -exec $(CP) \{\} $$(1)$(PYTHON_PKG_DIR)/ \;
  117. endef
  118. endef