2 # Copyright (C) 2006-2012 OpenWrt.org
3 # Copyright (C) 2016 LEDE project
5 # This is free software, licensed under the GNU General Public License v2.
6 # See /LICENSE for more information.
9 OPENWRT_GIT = http://git.openwrt.org
10 LEDE_GIT = http://git.lede-project.org
12 DOWNLOAD_RDEP=$(STAMP_PREPARED) $(HOST_STAMP_PREPARED)
14 # Try to guess the download method from the URL
18 $(if $(filter @APACHE/% @GITHUB/% @GNOME/% @GNU/% @KERNEL/% @SF/% @SAVANNAH/% ftp://% http://% https://% file://%,$(1)),default, \
19 $(if $(filter git://%,$(1)),git, \
20 $(if $(filter svn://%,$(1)),svn, \
21 $(if $(filter cvs://%,$(1)),cvs, \
22 $(if $(filter hg://%,$(1)),hg, \
23 $(if $(filter sftp://%,$(1)),bzr, \
35 # code for creating tarballs from cvs/svn/git/bzr/hg/darcs checkouts - useful for mirror support
36 dl_pack/bz2=$(TAR) cjf $(1) $(2)
37 dl_pack/gz=$(TAR) czf $(1) $(2)
38 dl_pack/xz=$(TAR) c $(2) | xz -zc > $(1)
39 dl_pack/unknown=echo "ERROR: Unknown pack format for file $(1)"; false
41 $(if $(dl_pack/$(call ext,$(1))),$(dl_pack/$(call ext,$(1))),$(dl_pack/unknown))
44 define DownloadMethod/unknown
45 @echo "ERROR: No download method available"; false
48 define DownloadMethod/default
49 $(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(FILE)" "$(MD5SUM)" "$(URL_FILE)" $(foreach url,$(URL),"$(url)")
53 $(if $(if $(MIRROR),$(filter-out x,$(MIRROR_MD5SUM))),$(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(FILE)" "$(MIRROR_MD5SUM)" "" || ( $(1) ),$(1))
56 define DownloadMethod/cvs
58 echo "Checking out files from the cvs repository..."; \
59 mkdir -p $(TMP_DIR)/dl && \
62 [ \! -d $(SUBDIR) ] && \
63 cvs -d $(URL) export $(VERSION) $(SUBDIR) && \
64 echo "Packing checkout..." && \
65 $(call dl_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
66 mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
71 define DownloadMethod/svn
73 echo "Checking out files from the svn repository..."; \
74 mkdir -p $(TMP_DIR)/dl && \
77 [ \! -d $(SUBDIR) ] && \
78 ( svn help export | grep -q trust-server-cert && \
79 svn export --non-interactive --trust-server-cert -r$(VERSION) $(URL) $(SUBDIR) || \
80 svn export --non-interactive -r$(VERSION) $(URL) $(SUBDIR) ) && \
81 echo "Packing checkout..." && \
82 $(call dl_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
83 mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
88 define DownloadMethod/git
90 echo "Checking out files from the git repository..."; \
91 mkdir -p $(TMP_DIR)/dl && \
94 [ \! -d $(SUBDIR) ] && \
95 git clone $(URL) $(SUBDIR) && \
96 (cd $(SUBDIR) && git checkout $(VERSION) && \
97 git submodule update --init --recursive) && \
98 echo "Packing checkout..." && \
99 rm -rf $(SUBDIR)/.git && \
100 $(call dl_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
101 mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
106 define DownloadMethod/bzr
107 $(call wrap_mirror, \
108 echo "Checking out files from the bzr repository..."; \
109 mkdir -p $(TMP_DIR)/dl && \
110 cd $(TMP_DIR)/dl && \
111 rm -rf $(SUBDIR) && \
112 [ \! -d $(SUBDIR) ] && \
113 bzr export -r$(VERSION) $(SUBDIR) $(URL) && \
114 echo "Packing checkout..." && \
115 $(call dl_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
116 mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
121 define DownloadMethod/hg
122 $(call wrap_mirror, \
123 echo "Checking out files from the hg repository..."; \
124 mkdir -p $(TMP_DIR)/dl && \
125 cd $(TMP_DIR)/dl && \
126 rm -rf $(SUBDIR) && \
127 [ \! -d $(SUBDIR) ] && \
128 hg clone -r $(VERSION) $(URL) $(SUBDIR) && \
129 find $(SUBDIR) -name .hg | xargs rm -rf && \
130 echo "Packing checkout..." && \
131 $(call dl_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
132 mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
137 define DownloadMethod/darcs
138 $(call wrap_mirror, \
139 echo "Checking out files from the darcs repository..."; \
140 mkdir -p $(TMP_DIR)/dl && \
141 cd $(TMP_DIR)/dl && \
142 rm -rf $(SUBDIR) && \
143 [ \! -d $(SUBDIR) ] && \
144 darcs get -t $(VERSION) $(URL) $(SUBDIR) && \
145 find $(SUBDIR) -name _darcs | xargs rm -rf && \
146 echo "Packing checkout..." && \
147 $(call dl_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
148 mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
153 Validate/cvs=VERSION SUBDIR
154 Validate/svn=VERSION SUBDIR
155 Validate/git=VERSION SUBDIR
156 Validate/bzr=VERSION SUBDIR
157 Validate/hg=VERSION SUBDIR
158 Validate/darcs=VERSION SUBDIR
160 define Download/Defaults
173 $(eval $(Download/Defaults))
174 $(eval $(Download/$(1)))
175 $(foreach FIELD,URL FILE $(Validate/$(call dl_method,$(URL),$(PROTO))),
177 $$(error Download/$(1) is missing the $(FIELD) field.)
181 $(foreach dep,$(DOWNLOAD_RDEP),
182 $(dep): $(DL_DIR)/$(FILE)
184 download: $(DL_DIR)/$(FILE)
188 $(call locked,$(if $(DownloadMethod/$(call dl_method,$(URL),$(PROTO))),$(DownloadMethod/$(call dl_method,$(URL),$(PROTO))),$(DownloadMethod/unknown)),$(FILE))