dnsmasq: bump to v2.88
[openwrt/staging/hauke.git] / include / download.mk
1 # SPDX-License-Identifier: GPL-2.0-only
2 #
3 # Copyright (C) 2006-2012 OpenWrt.org
4 # Copyright (C) 2016 LEDE project
5
6 PROJECT_GIT = https://git.openwrt.org
7
8 OPENWRT_GIT = $(PROJECT_GIT)
9 LEDE_GIT = $(PROJECT_GIT)
10
11 ifdef PKG_SOURCE_VERSION
12 ifndef PKG_VERSION
13 PKG_VERSION := $(if $(PKG_SOURCE_DATE),$(PKG_SOURCE_DATE)-)$(call version_abbrev,$(PKG_SOURCE_VERSION))
14 endif
15 PKG_SOURCE_SUBDIR ?= $(PKG_NAME)-$(PKG_VERSION)
16 PKG_SOURCE ?= $(PKG_SOURCE_SUBDIR).tar.xz
17 endif
18
19 DOWNLOAD_RDEP=$(STAMP_PREPARED) $(HOST_STAMP_PREPARED)
20
21 # Export options for download.pl
22 export DOWNLOAD_CHECK_CERTIFICATE:=$(CONFIG_DOWNLOAD_CHECK_CERTIFICATE)
23 export DOWNLOAD_TOOL_CUSTOM:=$(CONFIG_DOWNLOAD_TOOL_CUSTOM)
24
25 define dl_method_git
26 $(if $(filter https://github.com/% git://github.com/%,$(1)),github_archive,git)
27 endef
28
29 # Try to guess the download method from the URL
30 define dl_method
31 $(strip \
32 $(if $(filter git,$(2)),$(call dl_method_git,$(1),$(2)),
33 $(if $(2),$(2), \
34 $(if $(filter @OPENWRT @APACHE/% @DEBIAN/% @GITHUB/% @GNOME/% @GNU/% @KERNEL/% @SF/% @SAVANNAH/% ftp://% http://% https://% file://%,$(1)),default, \
35 $(if $(filter git://%,$(1)),$(call dl_method_git,$(1),$(2)), \
36 $(if $(filter svn://%,$(1)),svn, \
37 $(if $(filter cvs://%,$(1)),cvs, \
38 $(if $(filter hg://%,$(1)),hg, \
39 $(if $(filter sftp://%,$(1)),bzr, \
40 unknown \
41 ) \
42 ) \
43 ) \
44 ) \
45 ) \
46 ) \
47 ) \
48 ) \
49 )
50 endef
51
52 # code for creating tarballs from cvs/svn/git/bzr/hg/darcs checkouts - useful for mirror support
53 dl_pack/bz2=bzip2 -c > $(1)
54 dl_pack/gz=gzip -nc > $(1)
55 dl_pack/xz=xz -zc -7e > $(1)
56 dl_pack/zst=zstd -T0 --ultra -20 -c > $(1)
57 dl_pack/unknown=$(error ERROR: Unknown pack format for file $(1))
58 define dl_pack
59 $(if $(dl_pack/$(call ext,$(1))),$(dl_pack/$(call ext,$(1))),$(dl_pack/unknown))
60 endef
61 define dl_tar_pack
62 $(TAR) --numeric-owner --owner=0 --group=0 --mode=a-s --sort=name \
63 $$$${TAR_TIMESTAMP:+--mtime="$$$$TAR_TIMESTAMP"} -c $(2) | $(call dl_pack,$(1))
64 endef
65
66 gen_sha256sum = $(shell $(MKHASH) sha256 $(DL_DIR)/$(1))
67
68 # Used in Build/CoreTargets and HostBuild/Core as an integrity check for
69 # downloaded files. It will add a FORCE rule if the sha256 hash does not
70 # match, so that the download can be more thoroughly handled by download.pl.
71 define check_download_integrity
72 expected_hash:=$(strip $(if $(filter-out x,$(HASH)),$(HASH),$(MIRROR_HASH)))
73 $$(if $$(and $(FILE),$$(wildcard $(DL_DIR)/$(FILE)), \
74 $$(filter undefined,$$(flavor DownloadChecked/$(FILE)))), \
75 $$(eval DownloadChecked/$(FILE):=1) \
76 $$(if $$(filter-out $$(call gen_sha256sum,$(FILE)),$$(expected_hash)), \
77 $(DL_DIR)/$(FILE): FORCE) \
78 )
79 endef
80
81 ifdef CHECK
82 check_escape=$(subst ','\'',$(1))
83 #')
84
85 # $(1): suffix of the F_, C_ variables, e.g. hash_deprecated, hash_mismatch, etc.
86 # $(2): filename
87 # $(3): expected hash value
88 # $(4): var name of the the form: {PKG_,Download/<name>:}{,MIRROR_}{HASH,MIRROR_HASH}
89 check_warn_nofix = $(info $(shell printf "$(_R)WARNING: %s$(_N)" '$(call check_escape,$(call C_$(1),$(2),$(3),$(4)))'))
90 ifndef FIXUP
91 check_warn = $(check_warn_nofix)
92 else
93 check_warn = $(if $(filter-out undefined,$(origin F_$(1))),$(filter ,$(shell $(call F_$(1),$(2),$(3),$(4)) >&2)),$(check_warn_nofix))
94 endif
95
96 ifdef FIXUP
97 F_hash_deprecated = $(SCRIPT_DIR)/fixup-makefile.pl $(CURDIR)/Makefile fix-hash $(3) $(call gen_sha256sum,$(1)) $(2)
98 F_hash_mismatch = $(F_hash_deprecated)
99 F_hash_missing = $(SCRIPT_DIR)/fixup-makefile.pl $(CURDIR)/Makefile add-hash $(3) $(call gen_sha256sum,$(1))
100 endif
101
102 # $(1): filename
103 # $(2): expected hash value
104 # $(3): var name of the the form: {PKG_,Download/<name>:}{,MIRROR_}{HASH,MIRROR_HASH}
105 C_download_missing = $(1) is missing, please run make download before re-running this check
106 C_hash_mismatch = $(3) does not match $(1) hash $(call gen_sha256sum,$(1))
107 C_hash_deprecated = $(3) uses deprecated hash, set to $(call gen_sha256sum,$(1))
108 C_hash_missing = $(3) is missing, set to $(call gen_sha256sum,$(1))
109
110 # $(1): filename
111 # $(2): expected hash value
112 # $(3): var name of the the form: {PKG_,Download/<name>:}{,MIRROR_}{HASH,MIRROR_HASH}
113 check_hash = \
114 $(if $(wildcard $(DL_DIR)/$(1)), \
115 $(if $(filter-out x,$(2)), \
116 $(if $(filter 64,$(shell printf '%s' '$(2)' | wc -c)), \
117 $(if $(filter $(2),$(call gen_sha256sum,$(1))),, \
118 $(call check_warn,hash_mismatch,$(1),$(2),$(3)) \
119 ), \
120 $(call check_warn,hash_deprecated,$(1),$(2),$(3)), \
121 ), \
122 $(call check_warn,hash_missing,$(1),$(2),$(3)) \
123 ), \
124 $(call check_warn,download_missing,$(1),$(2),$(3)) \
125 )
126
127 ifdef FIXUP
128 F_md5_deprecated = $(SCRIPT_DIR)/fixup-makefile.pl $(CURDIR)/Makefile rename-var $(2) $(3)
129 endif
130
131 C_md5_deprecated = Use of $(2) is deprecated, switch to $(3)
132
133 check_md5 = \
134 $(if $(filter-out x,$(1)), \
135 $(call check_warn,md5_deprecated,$(1),$(2),$(3)) \
136 )
137
138 hash_var = $(if $(filter-out x,$(1)),MD5SUM,HASH)
139 endif
140
141 define DownloadMethod/unknown
142 echo "ERROR: No download method available"; false
143 endef
144
145 define DownloadMethod/default
146 $(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(FILE)" "$(HASH)" "$(URL_FILE)" $(foreach url,$(URL),"$(url)") \
147 $(if $(filter check,$(1)), \
148 $(call check_hash,$(FILE),$(HASH),$(2)$(call hash_var,$(MD5SUM))) \
149 $(call check_md5,$(MD5SUM),$(2)MD5SUM,$(2)HASH) \
150 )
151 endef
152
153 # $(1): "check"
154 # $(2): "PKG_" if <name> as in Download/<name> is "default", otherwise "Download/<name>:"
155 # $(3): shell command sequence to do the download
156 define wrap_mirror
157 $(if $(if $(MIRROR),$(filter-out x,$(MIRROR_HASH))),$(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(FILE)" "$(MIRROR_HASH)" "" || ( $(3) ),$(3)) \
158 $(if $(filter check,$(1)), \
159 $(call check_hash,$(FILE),$(MIRROR_HASH),$(2)MIRROR_$(call hash_var,$(MIRROR_MD5SUM))) \
160 $(call check_md5,$(MIRROR_MD5SUM),$(2)MIRROR_MD5SUM,$(2)MIRROR_HASH) \
161 )
162 endef
163
164 define DownloadMethod/cvs
165 $(call wrap_mirror,$(1),$(2), \
166 echo "Checking out files from the cvs repository..."; \
167 mkdir -p $(TMP_DIR)/dl && \
168 cd $(TMP_DIR)/dl && \
169 rm -rf $(SUBDIR) && \
170 [ \! -d $(SUBDIR) ] && \
171 cvs -d $(URL) export $(VERSION) $(SUBDIR) && \
172 echo "Packing checkout..." && \
173 $(call dl_tar_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
174 mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
175 rm -rf $(SUBDIR); \
176 )
177 endef
178
179 define DownloadMethod/svn
180 $(call wrap_mirror,$(1),$(2), \
181 echo "Checking out files from the svn repository..."; \
182 mkdir -p $(TMP_DIR)/dl && \
183 cd $(TMP_DIR)/dl && \
184 rm -rf $(SUBDIR) && \
185 [ \! -d $(SUBDIR) ] && \
186 ( svn help export | grep -q trust-server-cert && \
187 svn export --non-interactive --trust-server-cert -r$(VERSION) $(URL) $(SUBDIR) || \
188 svn export --non-interactive -r$(VERSION) $(URL) $(SUBDIR) ) && \
189 echo "Packing checkout..." && \
190 export TAR_TIMESTAMP="" && \
191 $(call dl_tar_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
192 mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
193 rm -rf $(SUBDIR); \
194 )
195 endef
196
197 define DownloadMethod/git
198 $(call wrap_mirror,$(1),$(2), \
199 $(call DownloadMethod/rawgit) \
200 )
201 endef
202
203 define DownloadMethod/github_archive
204 $(call wrap_mirror,$(1),$(2), \
205 $(SCRIPT_DIR)/dl_github_archive.py \
206 --dl-dir="$(DL_DIR)" \
207 --url="$(URL)" \
208 --version="$(VERSION)" \
209 --subdir="$(SUBDIR)" \
210 --source="$(FILE)" \
211 --hash="$(MIRROR_HASH)" \
212 || ( $(call DownloadMethod/rawgit) ); \
213 )
214 endef
215
216 # Only intends to be called as a submethod from other DownloadMethod
217 define DownloadMethod/rawgit
218 echo "Checking out files from the git repository..."; \
219 mkdir -p $(TMP_DIR)/dl && \
220 cd $(TMP_DIR)/dl && \
221 rm -rf $(SUBDIR) && \
222 [ \! -d $(SUBDIR) ] && \
223 git clone $(OPTS) $(URL) $(SUBDIR) && \
224 (cd $(SUBDIR) && git checkout $(VERSION) && \
225 git submodule update --init --recursive) && \
226 echo "Packing checkout..." && \
227 export TAR_TIMESTAMP=`cd $(SUBDIR) && git log -1 --format='@%ct'` && \
228 rm -rf $(SUBDIR)/.git && \
229 $(call dl_tar_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
230 mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
231 rm -rf $(SUBDIR);
232 endef
233
234 define DownloadMethod/bzr
235 $(call wrap_mirror,$(1),$(2), \
236 echo "Checking out files from the bzr repository..."; \
237 mkdir -p $(TMP_DIR)/dl && \
238 cd $(TMP_DIR)/dl && \
239 rm -rf $(SUBDIR) && \
240 [ \! -d $(SUBDIR) ] && \
241 bzr export --per-file-timestamps -r$(VERSION) $(SUBDIR) $(URL) && \
242 echo "Packing checkout..." && \
243 export TAR_TIMESTAMP="" && \
244 $(call dl_tar_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
245 mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
246 rm -rf $(SUBDIR); \
247 )
248 endef
249
250 define DownloadMethod/hg
251 $(call wrap_mirror,$(1),$(2), \
252 echo "Checking out files from the hg repository..."; \
253 mkdir -p $(TMP_DIR)/dl && \
254 cd $(TMP_DIR)/dl && \
255 rm -rf $(SUBDIR) && \
256 [ \! -d $(SUBDIR) ] && \
257 hg clone -r $(VERSION) $(URL) $(SUBDIR) && \
258 export TAR_TIMESTAMP=`cd $(SUBDIR) && hg log --template '@{date}' -l 1` && \
259 find $(SUBDIR) -name .hg | xargs rm -rf && \
260 echo "Packing checkout..." && \
261 $(call dl_tar_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
262 mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
263 rm -rf $(SUBDIR); \
264 )
265 endef
266
267 define DownloadMethod/darcs
268 $(call wrap_mirror, $(1), $(2), \
269 echo "Checking out files from the darcs repository..."; \
270 mkdir -p $(TMP_DIR)/dl && \
271 cd $(TMP_DIR)/dl && \
272 rm -rf $(SUBDIR) && \
273 [ \! -d $(SUBDIR) ] && \
274 darcs get -t $(VERSION) $(URL) $(SUBDIR) && \
275 export TAR_TIMESTAMP=`cd $(SUBDIR) && LC_ALL=C darcs log --last 1 | sed -ne 's!^Date: \+!!p'` && \
276 find $(SUBDIR) -name _darcs | xargs rm -rf && \
277 echo "Packing checkout..." && \
278 $(call dl_tar_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
279 mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
280 rm -rf $(SUBDIR); \
281 )
282 endef
283
284 Validate/cvs=VERSION SUBDIR
285 Validate/svn=VERSION SUBDIR
286 Validate/git=VERSION SUBDIR
287 Validate/bzr=VERSION SUBDIR
288 Validate/hg=VERSION SUBDIR
289 Validate/darcs=VERSION SUBDIR
290
291 define Download/Defaults
292 URL:=
293 FILE:=
294 URL_FILE:=
295 PROTO:=
296 HASH=$$(MD5SUM)
297 MD5SUM:=x
298 SUBDIR:=
299 MIRROR:=1
300 MIRROR_HASH=$$(MIRROR_MD5SUM)
301 MIRROR_MD5SUM:=x
302 VERSION:=
303 OPTS:=
304 endef
305
306 define Download/default
307 FILE:=$(PKG_SOURCE)
308 URL:=$(PKG_SOURCE_URL)
309 URL_FILE:=$(PKG_SOURCE_URL_FILE)
310 SUBDIR:=$(PKG_SOURCE_SUBDIR)
311 PROTO:=$(PKG_SOURCE_PROTO)
312 $(if $(PKG_SOURCE_MIRROR),MIRROR:=$(filter 1,$(PKG_MIRROR)))
313 $(if $(PKG_MIRROR_MD5SUM),MIRROR_MD5SUM:=$(PKG_MIRROR_MD5SUM))
314 $(if $(PKG_MIRROR_HASH),MIRROR_HASH:=$(PKG_MIRROR_HASH))
315 VERSION:=$(PKG_SOURCE_VERSION)
316 $(if $(PKG_MD5SUM),MD5SUM:=$(PKG_MD5SUM))
317 $(if $(PKG_HASH),HASH:=$(PKG_HASH))
318 endef
319
320 define Download
321 $(eval $(Download/Defaults))
322 $(eval $(Download/$(1)))
323 $(foreach FIELD,URL FILE $(Validate/$(call dl_method,$(URL),$(PROTO))),
324 ifeq ($($(FIELD)),)
325 $$(error Download/$(1) is missing the $(FIELD) field.)
326 endif
327 )
328
329 $(foreach dep,$(DOWNLOAD_RDEP),
330 $(dep): $(DL_DIR)/$(FILE)
331 )
332 download: $(DL_DIR)/$(FILE)
333
334 $(DL_DIR)/$(FILE):
335 mkdir -p $(DL_DIR)
336 $(call locked, \
337 $(if $(DownloadMethod/$(call dl_method,$(URL),$(PROTO))), \
338 $(call DownloadMethod/$(call dl_method,$(URL),$(PROTO)),check,$(if $(filter default,$(1)),PKG_,Download/$(1):)), \
339 $(DownloadMethod/unknown) \
340 ),\
341 $(FILE))
342
343 endef