Makefile 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #
  2. # Copyright (C) 2016 Yousong Zhou <yszhou4tech@gmail.com>
  3. #
  4. # This is free software, licensed under the GNU General Public License v2.
  5. # See /LICENSE for more information.
  6. #
  7. include $(TOPDIR)/rules.mk
  8. PKG_NAME:=python-packages
  9. PKG_VERSION:=1.0
  10. PKG_RELEASE:=1
  11. PKG_MAINTAINER:=Yousong Zhou <yszhou4tech@gmail.com>
  12. #
  13. # NOTE: move the host module installation to Host/Compile when
  14. # HOST_CONFIG_DEPENDS is supported
  15. #
  16. # NOTE: PKG_CONFIG_DEPENDS cannot correctly track changes of string type config
  17. # options, so you may want to do manual cleanup on config change.
  18. #
  19. PKG_CONFIG_DEPENDS:= \
  20. CONFIG_PACKAGE_python-packages-list-host \
  21. CONFIG_PACKAGE_python-packages-list \
  22. CONFIG_PACKAGE_python-packages-list-cleanup \
  23. CONFIG_PACKAGE_python-packages-envs \
  24. CONFIG_PACKAGE_python-packages-extra-deps \
  25. CONFIG_PACKAGE_python-packages-index-url \
  26. CONFIG_PACKAGE_python-packages-pip-opts \
  27. PKG_BUILD_DEPENDS:=python python-pip/host
  28. include $(INCLUDE_DIR)/package.mk
  29. $(call include_mk, python-host.mk)
  30. $(call include_mk, python-package.mk)
  31. define Package/python-packages
  32. SUBMENU:=Python
  33. SECTION:=lang
  34. CATEGORY:=Languages
  35. TITLE:=A dummy package for packaging python modules with pip
  36. DEPENDS:=@DEVEL +python
  37. endef
  38. define Package/python-packages/config
  39. if PACKAGE_python-packages
  40. config PACKAGE_python-packages-list-host
  41. string "List of python packages to install on host"
  42. config PACKAGE_python-packages-list
  43. string "List of python packages to install on target"
  44. config PACKAGE_python-packages-list-cleanup
  45. string "List of python packages to cleanup to avoid clash with existing packages"
  46. config PACKAGE_python-packages-envs
  47. string "Extra environment variables to pass on to pip and its children on target build"
  48. config PACKAGE_python-packages-extra-deps
  49. string "List of deps fulfilled but not tracked by the build system"
  50. config PACKAGE_python-packages-index-url
  51. string "Index URL passed to pip with --index-url"
  52. config PACKAGE_python-packages-pip-opts
  53. string "Additional arguments to pip command line"
  54. endif
  55. endef
  56. CONFIG_PACKAGE_python-packages-list-host:=$(call qstrip,$(CONFIG_PACKAGE_python-packages-list-host))
  57. CONFIG_PACKAGE_python-packages-list:=$(call qstrip,$(CONFIG_PACKAGE_python-packages-list))
  58. CONFIG_PACKAGE_python-packages-list-cleanup:=$(call qstrip,$(CONFIG_PACKAGE_python-packages-list-cleanup))
  59. CONFIG_PACKAGE_python-packages-envs:=$(call qstrip,$(CONFIG_PACKAGE_python-packages-envs))
  60. CONFIG_PACKAGE_python-packages-extra-deps:=$(call qstrip,$(CONFIG_PACKAGE_python-packages-extra-deps))
  61. CONFIG_PACKAGE_python-packages-pip-opts:=$(call qstrip,$(CONFIG_PACKAGE_python-packages-pip-opts))
  62. HOST_PYTHON_PIP:=$(STAGING_DIR_HOSTPKG)/bin/pip$(PYTHON_VERSION)
  63. decr=$(word $(1),0 1 2 3 4 5 6 7 8 9 10)
  64. recur=$(if $(subst 0,,$(2)),$(call recur,$(1),$(call decr,$(2)),$(call $(1)$(2),$(3))),$(3))
  65. _req2dir1=$(subst >,gt,$(1))
  66. _req2dir2=$(subst <,lt,$(1))
  67. _req2dir3=$(subst >=,geq,$(1))
  68. _req2dir4=$(subst <=,leq,$(1))
  69. _req2dir5=$(subst ://,:::,$(1))
  70. _req2dir6=$(subst *,_,$(1))
  71. _req2dir7=$(subst ?,_,$(1))
  72. req2dir=$(call recur,_req2dir,7,$(1))
  73. # --ignore-installed, it may happen that host pip will ignore target install if
  74. # it was already installed as host module, e.g. cffi deps of cryptograph
  75. HOST_PYTHON_PIP_INSTALL=$(HOST_PYTHON_PIP) install \
  76. --root=$(1) \
  77. --prefix=$(2) \
  78. --ignore-installed \
  79. --no-compile \
  80. $(if $(CONFIG_PACKAGE_python-packages-index-url), --index-url $(CONFIG_PACKAGE_python-packages-index-url)) \
  81. $(if $(CONFIG_PACKAGE_python-packages-pip-opts), $(CONFIG_PACKAGE_python-packages-pip-opts)) \
  82. HOST_PYTHON_PIP_INSTALL_HOST:=$(call HOST_PYTHON_PIP_INSTALL,$(STAGING_DIR_HOSTPKG),"")
  83. HOST_PYTHON_PIP_INSTALL_TARGET=$(call HOST_PYTHON_PIP_INSTALL,$(PKG_INSTALL_DIR)/$(call req2dir,$(pkg)),/usr)
  84. HOST_PYTHON_PIP_INSTALL_CLEANUP:=$(call HOST_PYTHON_PIP_INSTALL,$(PKG_INSTALL_DIR)/_cleanup,/usr)
  85. define Build/Compile
  86. $(foreach pkg,$(CONFIG_PACKAGE_python-packages-list-host),
  87. $(call Build/Compile/HostPyRunHost,,$(HOST_PYTHON_PIP_INSTALL_HOST) $(pkg))
  88. )
  89. $(foreach pkg,$(CONFIG_PACKAGE_python-packages-list),
  90. $(call Build/Compile/HostPyRunTarget,,$(call HOST_PYTHON_PIP_INSTALL_TARGET,$(pkg)) $(pkg),$(CONFIG_PACKAGE_python-packages-envs))
  91. )
  92. $(foreach pkg,$(CONFIG_PACKAGE_python-packages-list-cleanup),
  93. $(call Build/Compile/HostPyRunTarget,,$(HOST_PYTHON_PIP_INSTALL_CLEANUP) $(pkg),$(CONFIG_PACKAGE_python-packages-envs))
  94. )
  95. endef
  96. define Package/python-packages/install
  97. $(foreach pkg,$(CONFIG_PACKAGE_python-packages-list),
  98. $(CP) "$(PKG_INSTALL_DIR)/$(call req2dir,$(pkg))"/* $(1)
  99. )
  100. find "$(PKG_INSTALL_DIR)/_cleanup" -mindepth 1 -depth | while read sf; do \
  101. tf="$$$${sf#$(PKG_INSTALL_DIR)/_cleanup/}"; \
  102. tf="$(1)/$$$$tf"; \
  103. if [ -f "$$$$tf" -o -L "$$$$tf" ]; then \
  104. rm -vf "$$$$tf"; \
  105. elif [ -d "$$$$tf" ]; then \
  106. rmdir -v -p "$$$$tf" || true; \
  107. fi \
  108. done
  109. endef
  110. define Package/python-packages/extra_provides
  111. echo $(CONFIG_PACKAGE_python-packages-extra-deps) | tr ' ' '\n'
  112. endef
  113. $(eval $(call BuildPackage,python-packages))