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