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