1
0

python-package.mk 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. $(call include_mk, python-version.mk)
  8. PYTHON_DIR:=$(STAGING_DIR)/usr
  9. PYTHON_BIN_DIR:=$(PYTHON_DIR)/bin
  10. PYTHON_INC_DIR:=$(PYTHON_DIR)/include/python$(PYTHON_VERSION)
  11. PYTHON_LIB_DIR:=$(PYTHON_DIR)/lib/python$(PYTHON_VERSION)
  12. PYTHON_PKG_DIR:=/usr/lib/python$(PYTHON_VERSION)/site-packages
  13. PYTHON:=python$(PYTHON_VERSION)
  14. PYTHONPATH:=$(PYTHON_LIB_DIR):$(STAGING_DIR)/$(PYTHON_PKG_DIR):$(PKG_INSTALL_DIR)/$(PYTHON_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 PyPackage
  28. # Add default PyPackage filespec none defined
  29. ifndef PyPackage/$(1)/filespec
  30. define PyPackage/$(1)/filespec
  31. +|$(PYTHON_PKG_DIR)
  32. endef
  33. endif
  34. ifndef PyPackage/$(1)/install
  35. define PyPackage/$(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,PyPackage/$(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,PyPackage/$(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 PyPackage/$(1)/install,$$(1))
  76. endef
  77. endef
  78. $(call include_mk, python-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/HostPyRunTarget
  83. $(call HostPython, \
  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$(PYTHON_INC_DIR)" \
  92. LDFLAGS="$(TARGET_LDFLAGS) -lpython$(PYTHON_VERSION)" \
  93. _PYTHON_HOST_PLATFORM=linux2 \
  94. __PYVENV_LAUNCHER__="/usr/bin/$(PYTHON)" \
  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/PyMod
  104. $(INSTALL_DIR) $(PKG_INSTALL_DIR)/$(PYTHON_PKG_DIR)
  105. $(call Build/Compile/HostPyRunTarget, \
  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 PyBuild/Compile/Default
  112. $(call Build/Compile/PyMod,, \
  113. install --prefix="/usr" --root="$(PKG_INSTALL_DIR)" \
  114. --single-version-externally-managed \
  115. )
  116. endef
  117. ifeq ($(BUILD_VARIANT),python)
  118. define Build/Compile
  119. $(call PyBuild/Compile/Default)
  120. endef
  121. endif # python