The cirros image was rebuilt against the 3.13.0-83 kernel, drivers e1000e, igbvf...
[packages/trusty/cirros-testvm.git] / cirros-testvm / src-cirros / buildroot-2015.05 / package / pkg-download.mk
1 ################################################################################
2 #
3 # This file contains the download helpers for the various package
4 # infrastructures. It is used to handle downloads from HTTP servers,
5 # FTP servers, Git repositories, Subversion repositories, Mercurial
6 # repositories, Bazaar repositories, and SCP servers.
7 #
8 ################################################################################
9
10 # Download method commands
11 export WGET := $(call qstrip,$(BR2_WGET))
12 export SVN := $(call qstrip,$(BR2_SVN))
13 export CVS := $(call qstrip,$(BR2_CVS))
14 export BZR := $(call qstrip,$(BR2_BZR))
15 export GIT := $(call qstrip,$(BR2_GIT))
16 export HG := $(call qstrip,$(BR2_HG))
17 export SCP := $(call qstrip,$(BR2_SCP))
18 SSH := $(call qstrip,$(BR2_SSH))
19 export LOCALFILES := $(call qstrip,$(BR2_LOCALFILES))
20
21 DL_WRAPPER = support/download/dl-wrapper
22
23 # DL_DIR may have been set already from the environment
24 ifeq ($(origin DL_DIR),undefined)
25 DL_DIR ?= $(call qstrip,$(BR2_DL_DIR))
26 ifeq ($(DL_DIR),)
27 DL_DIR := $(TOPDIR)/dl
28 endif
29 else
30 # Restore the BR2_DL_DIR that was overridden by the .config file
31 BR2_DL_DIR = $(DL_DIR)
32 endif
33
34 # ensure it exists and a absolute path
35 DL_DIR := $(shell mkdir -p $(DL_DIR) && cd $(DL_DIR) >/dev/null && pwd)
36
37 #
38 # URI scheme helper functions
39 # Example URIs:
40 # * http://www.example.com/dir/file
41 # * scp://www.example.com:dir/file (with domainseparator :)
42 #
43 # geturischeme: http
44 geturischeme = $(firstword $(subst ://, ,$(call qstrip,$(1))))
45 # stripurischeme: www.example.com/dir/file
46 stripurischeme = $(lastword $(subst ://, ,$(call qstrip,$(1))))
47 # domain: www.example.com
48 domain = $(firstword $(subst $(call domainseparator,$(2)), ,$(call stripurischeme,$(1))))
49 # notdomain: dir/file
50 notdomain = $(patsubst $(call domain,$(1),$(2))$(call domainseparator,$(2))%,%,$(call stripurischeme,$(1)))
51 #
52 # default domainseparator is /, specify alternative value as first argument
53 domainseparator = $(if $(1),$(1),/)
54
55 # github(user,package,version): returns site of GitHub repository
56 github = https://github.com/$(1)/$(2)/archive/$(3)
57
58 # Expressly do not check hashes for those files
59 # Exported variables default to immediately expanded in some versions of
60 # make, but we need it to be recursively-epxanded, so explicitly assign it.
61 export BR_NO_CHECK_HASH_FOR =
62
63 ################################################################################
64 # The DOWNLOAD_* helpers are in charge of getting a working copy
65 # of the source repository for their corresponding SCM,
66 # checking out the requested version / commit / tag, and create an
67 # archive out of it. DOWNLOAD_SCP uses scp to obtain a remote file with
68 # ssh authentication. DOWNLOAD_WGET is the normal wget-based download
69 # mechanism.
70 #
71 # The SOURCE_CHECK_* helpers are in charge of simply checking that the source
72 # is available for download. This can be used to make sure one will be able
73 # to get all the sources needed for one's build configuration.
74 ################################################################################
75
76 define DOWNLOAD_GIT
77         $(EXTRA_ENV) $(DL_WRAPPER) -b git \
78                 -o $(DL_DIR)/$($(PKG)_SOURCE) \
79                 $(QUIET) \
80                 -- \
81                 $($(PKG)_SITE) \
82                 $($(PKG)_DL_VERSION) \
83                 $($(PKG)_BASE_NAME)
84 endef
85
86 # TODO: improve to check that the given PKG_DL_VERSION exists on the remote
87 # repository
88 define SOURCE_CHECK_GIT
89         $(GIT) ls-remote --heads $($(PKG)_SITE) > /dev/null
90 endef
91
92 define DOWNLOAD_BZR
93         $(EXTRA_ENV) $(DL_WRAPPER) -b bzr \
94                 -o $(DL_DIR)/$($(PKG)_SOURCE) \
95                 $(QUIET) \
96                 -- \
97                 $($(PKG)_SITE) \
98                 $($(PKG)_DL_VERSION) \
99                 $($(PKG)_BASE_NAME)
100 endef
101
102 define SOURCE_CHECK_BZR
103         $(BZR) ls --quiet $($(PKG)_SITE) > /dev/null
104 endef
105
106 define DOWNLOAD_CVS
107         $(EXTRA_ENV) $(DL_WRAPPER) -b cvs \
108                 -o $(DL_DIR)/$($(PKG)_SOURCE) \
109                 $(QUIET) \
110                 -- \
111                 $(call stripurischeme,$(call qstrip,$($(PKG)_SITE))) \
112                 $($(PKG)_DL_VERSION) \
113                 $($(PKG)_RAWNAME) \
114                 $($(PKG)_BASE_NAME)
115 endef
116
117 # Not all CVS servers support ls/rls, use login to see if we can connect
118 define SOURCE_CHECK_CVS
119         $(CVS) -d:pserver:anonymous:@$(call stripurischeme,$(call qstrip,$($(PKG)_SITE))) login
120 endef
121
122 define DOWNLOAD_SVN
123         $(EXTRA_ENV) $(DL_WRAPPER) -b svn \
124                 -o $(DL_DIR)/$($(PKG)_SOURCE) \
125                 $(QUIET) \
126                 -- \
127                 $($(PKG)_SITE) \
128                 $($(PKG)_DL_VERSION) \
129                 $($(PKG)_BASE_NAME)
130 endef
131
132 define SOURCE_CHECK_SVN
133         $(SVN) ls $($(PKG)_SITE)@$($(PKG)_DL_VERSION) > /dev/null
134 endef
135
136 # SCP URIs should be of the form scp://[user@]host:filepath
137 # Note that filepath is relative to the user's home directory, so you may want
138 # to prepend the path with a slash: scp://[user@]host:/absolutepath
139 define DOWNLOAD_SCP
140         $(EXTRA_ENV) $(DL_WRAPPER) -b scp \
141                 -o $(DL_DIR)/$(2) \
142                 -H $(PKGDIR)/$($(PKG)_RAWNAME).hash \
143                 $(QUIET) \
144                 -- \
145                 '$(call stripurischeme,$(call qstrip,$(1)))'
146 endef
147
148 define SOURCE_CHECK_SCP
149         $(SSH) $(call domain,$(1),:) ls '$(call notdomain,$(1),:)' > /dev/null
150 endef
151
152 define DOWNLOAD_HG
153         $(EXTRA_ENV) $(DL_WRAPPER) -b hg \
154                 -o $(DL_DIR)/$($(PKG)_SOURCE) \
155                 $(QUIET) \
156                 -- \
157                 $($(PKG)_SITE) \
158                 $($(PKG)_DL_VERSION) \
159                 $($(PKG)_BASE_NAME)
160 endef
161
162 # TODO: improve to check that the given PKG_DL_VERSION exists on the remote
163 # repository
164 define SOURCE_CHECK_HG
165         $(HG) incoming --force -l1 $($(PKG)_SITE) > /dev/null
166 endef
167
168 define DOWNLOAD_WGET
169         $(EXTRA_ENV) $(DL_WRAPPER) -b wget \
170                 -o $(DL_DIR)/$(2) \
171                 -H $(PKGDIR)/$($(PKG)_RAWNAME).hash \
172                 $(QUIET) \
173                 -- \
174                 '$(call qstrip,$(1))'
175 endef
176
177 define SOURCE_CHECK_WGET
178         $(WGET) --spider '$(call qstrip,$(1))'
179 endef
180
181 define DOWNLOAD_LOCALFILES
182         $(EXTRA_ENV) $(DL_WRAPPER) -b cp \
183                 -o $(DL_DIR)/$(2) \
184                 -H $(PKGDIR)/$($(PKG)_RAWNAME).hash \
185                 $(QUIET) \
186                 -- \
187                 $(call stripurischeme,$(call qstrip,$(1)))
188 endef
189
190 define SOURCE_CHECK_LOCALFILES
191         test -e $(call stripurischeme,$(call qstrip,$(1)))
192 endef
193
194 ################################################################################
195 # DOWNLOAD -- Download helper. Will try to download source from:
196 # 1) BR2_PRIMARY_SITE if enabled
197 # 2) Download site, unless BR2_PRIMARY_SITE_ONLY is set
198 # 3) BR2_BACKUP_SITE if enabled, unless BR2_PRIMARY_SITE_ONLY is set
199 #
200 # Argument 1 is the source location
201 #
202 # E.G. use like this:
203 # $(call DOWNLOAD,$(FOO_SITE))
204 ################################################################################
205
206 define DOWNLOAD
207         $(call DOWNLOAD_INNER,$(1),$(notdir $(1)),DOWNLOAD)
208 endef
209
210 define SOURCE_CHECK
211         $(call DOWNLOAD_INNER,$(1),$(notdir $(1)),SOURCE_CHECK)
212 endef
213
214 define DOWNLOAD_INNER
215         $(Q)if test -n "$(call qstrip,$(BR2_PRIMARY_SITE))" ; then \
216                 case "$(call geturischeme,$(BR2_PRIMARY_SITE))" in \
217                         scp) $(call $(3)_SCP,$(BR2_PRIMARY_SITE)/$(2),$(2)) && exit ;; \
218                         *) $(call $(3)_WGET,$(BR2_PRIMARY_SITE)/$(2),$(2)) && exit ;; \
219                 esac ; \
220         fi ; \
221         if test "$(BR2_PRIMARY_SITE_ONLY)" = "y" ; then \
222                 exit 1 ; \
223         fi ; \
224         if test -n "$(1)" ; then \
225                 if test -z "$($(PKG)_SITE_METHOD)" ; then \
226                         scheme="$(call geturischeme,$(1))" ; \
227                 else \
228                         scheme="$($(PKG)_SITE_METHOD)" ; \
229                 fi ; \
230                 case "$$scheme" in \
231                         git) $($(3)_GIT) && exit ;; \
232                         svn) $($(3)_SVN) && exit ;; \
233                         cvs) $($(3)_CVS) && exit ;; \
234                         bzr) $($(3)_BZR) && exit ;; \
235                         file) $($(3)_LOCALFILES) && exit ;; \
236                         scp) $($(3)_SCP) && exit ;; \
237                         hg) $($(3)_HG) && exit ;; \
238                         *) $(call $(3)_WGET,$(1),$(2)) && exit ;; \
239                 esac ; \
240         fi ; \
241         if test -n "$(call qstrip,$(BR2_BACKUP_SITE))" ; then \
242                 $(call $(3)_WGET,$(BR2_BACKUP_SITE)/$(2),$(2)) && exit ; \
243         fi ; \
244         exit 1
245 endef