1 ################################################################################
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.
8 ################################################################################
10 # Download method commands
11 WGET := $(call qstrip,$(BR2_WGET)) $(QUIET)
12 SVN := $(call qstrip,$(BR2_SVN))
13 CVS := $(call qstrip,$(BR2_CVS))
14 BZR := $(call qstrip,$(BR2_BZR))
15 GIT := $(call qstrip,$(BR2_GIT))
16 HG := $(call qstrip,$(BR2_HG)) $(QUIET)
17 SCP := $(call qstrip,$(BR2_SCP)) $(QUIET)
18 SSH := $(call qstrip,$(BR2_SSH)) $(QUIET)
19 LOCALFILES := $(call qstrip,$(BR2_LOCALFILES))
21 # Default spider mode is 'DOWNLOAD'. Other possible values are 'SOURCE_CHECK'
22 # used by the _source-check target and 'SHOW_EXTERNAL_DEPS', used by the
23 # external-deps target.
26 # DL_DIR may have been set already from the environment
27 DL_DIR ?= $(call qstrip,$(BR2_DL_DIR))
29 DL_DIR := $(TOPDIR)/dl
32 # ensure it exists and a absolute path
33 DL_DIR := $(shell mkdir -p $(DL_DIR) && cd $(DL_DIR) >/dev/null && pwd)
36 # URI scheme helper functions
38 # * http://www.example.com/dir/file
39 # * scp://www.example.com:dir/file (with domainseparator :)
42 geturischeme=$(firstword $(subst ://, ,$(call qstrip,$(1))))
43 # stripurischeme: www.example.com/dir/file
44 stripurischeme=$(lastword $(subst ://, ,$(call qstrip,$(1))))
45 # domain: www.example.com
46 domain=$(firstword $(subst $(call domainseparator,$(2)), ,$(call stripurischeme,$(1))))
48 notdomain=$(patsubst $(call domain,$(1),$(2))$(call domainseparator,$(2))%,%,$(call stripurischeme,$(1)))
50 # default domainseparator is /, specify alternative value as first argument
51 domainseparator=$(if $(1),$(1),/)
53 # github(user,package,version): returns site of github repository
54 github = https://github.com/$(1)/$(2)/tarball/$(3)
56 ################################################################################
57 # The DOWNLOAD_* helpers are in charge of getting a working copy
58 # of the source repository for their corresponding SCM,
59 # checking out the requested version / commit / tag, and create an
60 # archive out of it. DOWNLOAD_SCP uses scp to obtain a remote file with
61 # ssh authentication. DOWNLOAD_WGET is the normal wget-based download
64 # The SOURCE_CHECK_* helpers are in charge of simply checking that the source
65 # is available for download. This can be used to make sure one will be able
66 # to get all the sources needed for one's build configuration.
68 # The SHOW_EXTERNAL_DEPS_* helpers simply output to the console the names
69 # of the files that will be downloaded, or path and revision of the
70 # source repositories, producing a list of all the "external dependencies"
71 # of a given build configuration.
72 ################################################################################
74 # Try a shallow clone - but that only works if the version is a ref (tag or
75 # branch). Before trying to do a shallow clone we check if $($(PKG)_DL_VERSION)
76 # is in the list provided by git ls-remote. If not we fall back on a full clone.
78 # Messages for the type of clone used are provided to ease debugging in case of
81 test -e $(DL_DIR)/$($(PKG)_SOURCE) || \
82 (pushd $(DL_DIR) > /dev/null && \
83 ((test "`git ls-remote $($(PKG)_SITE) $($(PKG)_DL_VERSION)`" && \
84 echo "Doing shallow clone" && \
85 $(GIT) clone --depth 1 -b $($(PKG)_DL_VERSION) --bare $($(PKG)_SITE) $($(PKG)_BASE_NAME)) || \
86 (echo "Doing full clone" && \
87 $(GIT) clone --bare $($(PKG)_SITE) $($(PKG)_BASE_NAME))) && \
88 pushd $($(PKG)_BASE_NAME) > /dev/null && \
89 $(GIT) archive --format=tar --prefix=$($(PKG)_BASE_NAME)/ -o $(DL_DIR)/.$($(PKG)_SOURCE).tmp $($(PKG)_DL_VERSION) && \
90 gzip -c $(DL_DIR)/.$($(PKG)_SOURCE).tmp > $(DL_DIR)/$($(PKG)_SOURCE) && \
91 rm -f $(DL_DIR)/.$($(PKG)_SOURCE).tmp && \
93 rm -rf $($(PKG)_DL_DIR) && \
97 # TODO: improve to check that the given PKG_DL_VERSION exists on the remote
99 define SOURCE_CHECK_GIT
100 $(GIT) ls-remote --heads $($(PKG)_SITE) > /dev/null
103 define SHOW_EXTERNAL_DEPS_GIT
104 echo $($(PKG)_SOURCE)
109 test -e $(DL_DIR)/$($(PKG)_SOURCE) || \
110 $(BZR) export $(DL_DIR)/$($(PKG)_SOURCE) $($(PKG)_SITE) -r $($(PKG)_DL_VERSION)
113 define SOURCE_CHECK_BZR
114 $(BZR) ls --quiet $($(PKG)_SITE) > /dev/null
117 define SHOW_EXTERNAL_DEPS_BZR
118 echo $($(PKG)_SOURCE)
122 test -e $(DL_DIR)/$($(PKG)_SOURCE) || \
123 (pushd $(DL_DIR) > /dev/null && \
124 $(CVS) -z3 -d:pserver:anonymous@$(call stripurischeme,$(call qstrip,$($(PKG)_SITE))) \
125 co -d $($(PKG)_BASE_NAME) -r :$($(PKG)_DL_VERSION) -P $($(PKG)_RAWNAME) && \
126 $(TAR) czf $($(PKG)_SOURCE) $($(PKG)_BASE_NAME)/ && \
127 rm -rf $($(PKG)_DL_DIR) && \
131 # Not all CVS servers support ls/rls, use login to see if we can connect
132 define SOURCE_CHECK_CVS
133 $(CVS) -d:pserver:anonymous:@$(call stripurischeme,$(call qstrip,$($(PKG)_SITE))) login
136 define SHOW_EXTERNAL_DEPS_CVS
137 echo $($(PKG)_SOURCE)
141 test -e $(DL_DIR)/$($(PKG)_SOURCE) || \
142 (pushd $(DL_DIR) > /dev/null && \
143 $(SVN) export -r $($(PKG)_DL_VERSION) $($(PKG)_SITE) $($(PKG)_DL_DIR) && \
144 $(TAR) czf $($(PKG)_SOURCE) $($(PKG)_BASE_NAME)/ && \
145 rm -rf $($(PKG)_DL_DIR) && \
149 define SOURCE_CHECK_SVN
150 $(SVN) ls $($(PKG)_SITE) > /dev/null
153 define SHOW_EXTERNAL_DEPS_SVN
154 echo $($(PKG)_SOURCE)
157 # SCP URIs should be of the form scp://[user@]host:filepath
158 # Note that filepath is relative to the user's home directory, so you may want
159 # to prepend the path with a slash: scp://[user@]host:/absolutepath
161 test -e $(DL_DIR)/$(2) || \
162 $(SCP) '$(call stripurischeme,$(call qstrip,$(1)))' $(DL_DIR)/$(2)
165 define SOURCE_CHECK_SCP
166 $(SSH) $(call domain,$(1),:) ls '$(call notdomain,$(1),:)' > /dev/null
169 define SHOW_EXTERNAL_DEPS_SCP
175 test -e $(DL_DIR)/$($(PKG)_SOURCE) || \
176 (pushd $(DL_DIR) > /dev/null && \
177 rm -rf $($(PKG)_BASE_NAME) && \
178 $(HG) clone --noupdate --rev $($(PKG)_DL_VERSION) $($(PKG)_SITE) $($(PKG)_BASE_NAME) && \
179 $(HG) archive --repository $($(PKG)_BASE_NAME) --type tgz --prefix $($(PKG)_BASE_NAME)/ \
180 --rev $($(PKG)_DL_VERSION) $(DL_DIR)/$($(PKG)_SOURCE) && \
181 rm -rf $($(PKG)_DL_DIR) && \
185 # TODO: improve to check that the given PKG_DL_VERSION exists on the remote
187 define SOURCE_CHECK_HG
188 $(HG) incoming --force -l1 $($(PKG)_SITE) > /dev/null
191 define SHOW_EXTERNAL_DEPS_HG
192 echo $($(PKG)_SOURCE)
195 # Download a file using wget. Only download the file if it doesn't
196 # already exist in the download directory. If the download fails,
197 # remove the file (because wget -O creates a 0-byte file even if the
198 # download fails). To handle an interrupted download as well, download
199 # to a temporary file first. The temporary file will be overwritten
200 # the next time the download is tried.
202 test -e $(DL_DIR)/$(2) || \
203 ($(WGET) -O $(DL_DIR)/$(2).tmp '$(call qstrip,$(1))' && \
204 mv $(DL_DIR)/$(2).tmp $(DL_DIR)/$(2)) || \
205 (rm -f $(DL_DIR)/$(2).tmp ; exit 1)
208 define SOURCE_CHECK_WGET
209 $(WGET) --spider '$(call qstrip,$(1))'
212 define SHOW_EXTERNAL_DEPS_WGET
216 define DOWNLOAD_LOCALFILES
217 test -e $(DL_DIR)/$(2) || \
218 $(LOCALFILES) $(call stripurischeme,$(call qstrip,$(1))) $(DL_DIR)
221 define SOURCE_CHECK_LOCALFILES
222 test -e $(call stripurischeme,$(call qstrip,$(1)))
225 define SHOW_EXTERNAL_DEPS_LOCALFILES
229 ################################################################################
230 # DOWNLOAD -- Download helper. Will try to download source from:
231 # 1) BR2_PRIMARY_SITE if enabled
232 # 2) Download site, unless BR2_PRIMARY_SITE_ONLY is set
233 # 3) BR2_BACKUP_SITE if enabled, unless BR2_PRIMARY_SITE_ONLY is set
235 # Argument 1 is the source location
236 # Argument 2 is the source filename
238 # E.G. use like this:
239 # $(call DOWNLOAD,$(FOO_SITE),$(FOO_SOURCE))
240 ################################################################################
243 $(call DOWNLOAD_INNER,$(1),$(if $(2),$(2),$(notdir $(1))))
246 define DOWNLOAD_INNER
247 $(Q)if test -n "$(call qstrip,$(BR2_PRIMARY_SITE))" ; then \
248 case "$(call geturischeme,$(BR2_PRIMARY_SITE))" in \
249 scp) $(call $(DL_MODE)_SCP,$(BR2_PRIMARY_SITE)/$(2),$(2)) && exit ;; \
250 *) $(call $(DL_MODE)_WGET,$(BR2_PRIMARY_SITE)/$(2),$(2)) && exit ;; \
253 if test "$(BR2_PRIMARY_SITE_ONLY)" = "y" ; then \
256 if test -n "$(1)" ; then \
257 if test -z "$($(PKG)_SITE_METHOD)" ; then \
258 scheme="$(call geturischeme,$(1))" ; \
260 scheme="$($(PKG)_SITE_METHOD)" ; \
263 git) $($(DL_MODE)_GIT) && exit ;; \
264 svn) $($(DL_MODE)_SVN) && exit ;; \
265 cvs) $($(DL_MODE)_CVS) && exit ;; \
266 bzr) $($(DL_MODE)_BZR) && exit ;; \
267 file) $($(DL_MODE)_LOCALFILES) && exit ;; \
268 scp) $($(DL_MODE)_SCP) && exit ;; \
269 hg) $($(DL_MODE)_HG) && exit ;; \
270 *) $(call $(DL_MODE)_WGET,$(1),$(2)) && exit ;; \
273 if test -n "$(call qstrip,$(BR2_BACKUP_SITE))" ; then \
274 $(call $(DL_MODE)_WGET,$(BR2_BACKUP_SITE)/$(2),$(2)) && exit ; \