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 = https://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=bzip2 -c > $(1)
37 dl_pack/gz=gzip -nc > $(1)
38 dl_pack/xz=xz -zc -7e > $(1)
39 dl_pack/unknown=$(error ERROR: Unknown pack format for file $(1))
41 $(if $(dl_pack/$(call ext,$(1))),$(dl_pack/$(call ext,$(1))),$(dl_pack/unknown))
44 $(TAR) --numeric-owner --owner=0 --group=0 --sort=name $$$${TAR_TIMESTAMP:+--mtime="$$$$TAR_TIMESTAMP"} -c $(2) | $(call dl_pack,$(1))
48 check_escape=$(subst ','\'',$(1))
51 check_warn_nofix = $(info $(shell printf "$(_R)WARNING: %s$(_N)" '$(call check_escape,$(call C_$(1),$(2),$(3),$(4)))'))
53 check_warn = $(check_warn_nofix)
55 check_warn = $(if $(filter-out undefined,$(origin F_$(1))),$(filter ,$(shell $(call F_$(1),$(2),$(3),$(4)) >&2)),$(check_warn_nofix))
58 gen_sha256sum = $(shell openssl dgst -sha256 $(DL_DIR)/$(1) | awk '{print $$2}')
61 F_hash_deprecated = $(SCRIPT_DIR)/fixup-makefile.pl $(CURDIR)/Makefile fix-hash $(3) $(call gen_sha256sum,$(1)) $(2)
62 F_hash_mismatch = $(F_hash_deprecated)
63 F_hash_missing = $(SCRIPT_DIR)/fixup-makefile.pl $(CURDIR)/Makefile add-hash $(3) $(call gen_sha256sum,$(1))
66 C_download_missing = $(1) is missing, please run make download before re-running this check
67 C_hash_mismatch = $(3) does not match $(1) hash $(call gen_sha256sum,$(1))
68 C_hash_deprecated = $(3) uses deprecated hash, set to $(call gen_sha256sum,$(1))
69 C_hash_missing = $(3) is missing, set to $(call gen_sha256sum,$(1))
72 $(if $(wildcard $(DL_DIR)/$(1)), \
73 $(if $(filter-out x,$(2)), \
74 $(if $(filter 64,$(shell printf '%s' '$(2)' | wc -c)), \
75 $(if $(filter $(2),$(call gen_sha256sum,$(1))),, \
76 $(call check_warn,hash_mismatch,$(1),$(2),$(3)) \
78 $(call check_warn,hash_deprecated,$(1),$(2),$(3)), \
80 $(call check_warn,hash_missing,$(1),$(2),$(3)) \
82 $(call check_warn,download_missing,$(1),$(2),$(3)) \
86 F_md5_deprecated = $(SCRIPT_DIR)/fixup-makefile.pl $(CURDIR)/Makefile rename-var $(2) $(3)
89 C_md5_deprecated = Use of $(2) is deprecated, switch to $(3)
91 # Skip MD5SUM check in feeds until OpenWrt is updated
92 ifneq ($(filter $(foreach dir,package tools toolchain, $(TOPDIR)/$(dir)/%),$(CURDIR)),)
94 $(if $(filter-out x,$(1)), \
95 $(call check_warn,md5_deprecated,$(1),$(2),$(3)) \
99 hash_var = $(if $(filter-out x,$(1)),MD5SUM,HASH)
102 define DownloadMethod/unknown
103 @echo "ERROR: No download method available"; false
106 define DownloadMethod/default
107 $(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(FILE)" "$(HASH)" "$(URL_FILE)" $(foreach url,$(URL),"$(url)") \
108 $(if $(filter check,$(1)), \
109 $(call check_hash,$(FILE),$(HASH),$(2)$(call hash_var,$(MD5SUM))) \
110 $(call check_md5,$(MD5SUM),$(2)MD5SUM,$(2)HASH) \
115 $(if $(if $(MIRROR),$(filter-out x,$(MIRROR_HASH))),$(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(FILE)" "$(MIRROR_HASH)" "" || ( $(3) ),$(3)) \
116 $(if $(filter check,$(1)), \
117 $(call check_hash,$(FILE),$(MIRROR_HASH),$(2)MIRROR_$(call hash_var,$(MIRROR_MD5SUM))) \
118 $(call check_md5,$(MIRROR_MD5SUM),$(2)MIRROR_MD5SUM,$(2)MIRROR_HASH) \
122 define DownloadMethod/cvs
123 $(call wrap_mirror,$(1),$(2), \
124 echo "Checking out files from the cvs repository..."; \
125 mkdir -p $(TMP_DIR)/dl && \
126 cd $(TMP_DIR)/dl && \
127 rm -rf $(SUBDIR) && \
128 [ \! -d $(SUBDIR) ] && \
129 cvs -d $(URL) export $(VERSION) $(SUBDIR) && \
130 echo "Packing checkout..." && \
131 $(call dl_tar_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
132 mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
137 define DownloadMethod/svn
138 $(call wrap_mirror,$(1),$(2), \
139 echo "Checking out files from the svn repository..."; \
140 mkdir -p $(TMP_DIR)/dl && \
141 cd $(TMP_DIR)/dl && \
142 rm -rf $(SUBDIR) && \
143 [ \! -d $(SUBDIR) ] && \
144 ( svn help export | grep -q trust-server-cert && \
145 svn export --non-interactive --trust-server-cert -r$(VERSION) $(URL) $(SUBDIR) || \
146 svn export --non-interactive -r$(VERSION) $(URL) $(SUBDIR) ) && \
147 echo "Packing checkout..." && \
148 export TAR_TIMESTAMP="" && \
149 $(call dl_tar_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
150 mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
155 define DownloadMethod/git
156 $(call wrap_mirror,$(1),$(2), \
157 echo "Checking out files from the git repository..."; \
158 mkdir -p $(TMP_DIR)/dl && \
159 cd $(TMP_DIR)/dl && \
160 rm -rf $(SUBDIR) && \
161 [ \! -d $(SUBDIR) ] && \
162 git clone $(OPTS) $(URL) $(SUBDIR) && \
163 (cd $(SUBDIR) && git checkout $(VERSION) && \
164 git submodule update --init --recursive) && \
165 echo "Packing checkout..." && \
166 export TAR_TIMESTAMP=`cd $(SUBDIR) && git log -1 --format='@%ct'` && \
167 rm -rf $(SUBDIR)/.git && \
168 $(call dl_tar_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
169 mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
174 define DownloadMethod/bzr
175 $(call wrap_mirror,$(1),$(2), \
176 echo "Checking out files from the bzr repository..."; \
177 mkdir -p $(TMP_DIR)/dl && \
178 cd $(TMP_DIR)/dl && \
179 rm -rf $(SUBDIR) && \
180 [ \! -d $(SUBDIR) ] && \
181 bzr export --per-file-timestamps -r$(VERSION) $(SUBDIR) $(URL) && \
182 echo "Packing checkout..." && \
183 export TAR_TIMESTAMP="" && \
184 $(call dl_tar_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
185 mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
190 define DownloadMethod/hg
191 $(call wrap_mirror,$(1),$(2), \
192 echo "Checking out files from the hg repository..."; \
193 mkdir -p $(TMP_DIR)/dl && \
194 cd $(TMP_DIR)/dl && \
195 rm -rf $(SUBDIR) && \
196 [ \! -d $(SUBDIR) ] && \
197 hg clone -r $(VERSION) $(URL) $(SUBDIR) && \
198 export TAR_TIMESTAMP=`cd $(SUBDIR) && hg log --template '@{date}' -l 1` && \
199 find $(SUBDIR) -name .hg | xargs rm -rf && \
200 echo "Packing checkout..." && \
201 $(call dl_tar_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
202 mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
207 define DownloadMethod/darcs
208 $(call wrap_mirror, $(1), $(2), \
209 echo "Checking out files from the darcs repository..."; \
210 mkdir -p $(TMP_DIR)/dl && \
211 cd $(TMP_DIR)/dl && \
212 rm -rf $(SUBDIR) && \
213 [ \! -d $(SUBDIR) ] && \
214 darcs get -t $(VERSION) $(URL) $(SUBDIR) && \
215 export TAR_TIMESTAMP=`cd $(SUBDIR) && LC_ALL=C darcs log --last 1 | sed -ne 's!^Date: \+!!p'` && \
216 find $(SUBDIR) -name _darcs | xargs rm -rf && \
217 echo "Packing checkout..." && \
218 $(call dl_tar_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
219 mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
224 Validate/cvs=VERSION SUBDIR
225 Validate/svn=VERSION SUBDIR
226 Validate/git=VERSION SUBDIR
227 Validate/bzr=VERSION SUBDIR
228 Validate/hg=VERSION SUBDIR
229 Validate/darcs=VERSION SUBDIR
231 define Download/Defaults
240 MIRROR_HASH=$$(MIRROR_MD5SUM)
246 define Download/default
248 URL:=$(PKG_SOURCE_URL)
249 SUBDIR:=$(PKG_SOURCE_SUBDIR)
250 PROTO:=$(PKG_SOURCE_PROTO)
251 $(if $(PKG_SOURCE_MIRROR),MIRROR:=$(filter 1,$(PKG_MIRROR)))
252 $(if $(PKG_MIRROR_MD5SUM),MIRROR_MD5SUM:=$(PKG_MIRROR_MD5SUM))
253 $(if $(PKG_MIRROR_HASH),MIRROR_HASH:=$(PKG_MIRROR_HASH))
254 VERSION:=$(PKG_SOURCE_VERSION)
255 $(if $(PKG_MD5SUM),MD5SUM:=$(PKG_MD5SUM))
256 $(if $(PKG_HASH),HASH:=$(PKG_HASH))
260 $(eval $(Download/Defaults))
261 $(eval $(Download/$(1)))
262 $(foreach FIELD,URL FILE $(Validate/$(call dl_method,$(URL),$(PROTO))),
264 $$(error Download/$(1) is missing the $(FIELD) field.)
268 $(foreach dep,$(DOWNLOAD_RDEP),
269 $(dep): $(DL_DIR)/$(FILE)
271 download: $(DL_DIR)/$(FILE)
276 $(if $(DownloadMethod/$(call dl_method,$(URL),$(PROTO))), \
277 $(call DownloadMethod/$(call dl_method,$(URL),$(PROTO)),check,$(if $(filter default,$(1)),PKG_,Download/$(1):)), \
278 $(DownloadMethod/unknown) \