kernel: remove stray 4.4 references
[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 # Try to guess the download method from the URL
23 define dl_method
24 $(strip \
25 $(if $(2),$(2), \
26 $(if $(filter @APACHE/% @GITHUB/% @GNOME/% @GNU/% @KERNEL/% @SF/% @SAVANNAH/% ftp://% http://% https://% file://%,$(1)),default, \
27 $(if $(filter git://%,$(1)),git, \
28 $(if $(filter svn://%,$(1)),svn, \
29 $(if $(filter cvs://%,$(1)),cvs, \
30 $(if $(filter hg://%,$(1)),hg, \
31 $(if $(filter sftp://%,$(1)),bzr, \
32 unknown \
33 ) \
34 ) \
35 ) \
36 ) \
37 ) \
38 ) \
39 ) \
40 )
41 endef
42
43 # code for creating tarballs from cvs/svn/git/bzr/hg/darcs checkouts - useful for mirror support
44 dl_pack/bz2=bzip2 -c > $(1)
45 dl_pack/gz=gzip -nc > $(1)
46 dl_pack/xz=xz -zc -7e > $(1)
47 dl_pack/unknown=$(error ERROR: Unknown pack format for file $(1))
48 define dl_pack
49 $(if $(dl_pack/$(call ext,$(1))),$(dl_pack/$(call ext,$(1))),$(dl_pack/unknown))
50 endef
51 define dl_tar_pack
52 $(TAR) --numeric-owner --owner=0 --group=0 --sort=name $$$${TAR_TIMESTAMP:+--mtime="$$$$TAR_TIMESTAMP"} -c $(2) | $(call dl_pack,$(1))
53 endef
54
55 ifdef CHECK
56 check_escape=$(subst ','\'',$(1))
57 #')
58
59 check_warn_nofix = $(info $(shell printf "$(_R)WARNING: %s$(_N)" '$(call check_escape,$(call C_$(1),$(2),$(3),$(4)))'))
60 ifndef FIXUP
61 check_warn = $(check_warn_nofix)
62 else
63 check_warn = $(if $(filter-out undefined,$(origin F_$(1))),$(filter ,$(shell $(call F_$(1),$(2),$(3),$(4)) >&2)),$(check_warn_nofix))
64 endif
65
66 gen_sha256sum = $(shell mkhash sha256 $(DL_DIR)/$(1))
67
68 ifdef FIXUP
69 F_hash_deprecated = $(SCRIPT_DIR)/fixup-makefile.pl $(CURDIR)/Makefile fix-hash $(3) $(call gen_sha256sum,$(1)) $(2)
70 F_hash_mismatch = $(F_hash_deprecated)
71 F_hash_missing = $(SCRIPT_DIR)/fixup-makefile.pl $(CURDIR)/Makefile add-hash $(3) $(call gen_sha256sum,$(1))
72 endif
73
74 C_download_missing = $(1) is missing, please run make download before re-running this check
75 C_hash_mismatch = $(3) does not match $(1) hash $(call gen_sha256sum,$(1))
76 C_hash_deprecated = $(3) uses deprecated hash, set to $(call gen_sha256sum,$(1))
77 C_hash_missing = $(3) is missing, set to $(call gen_sha256sum,$(1))
78
79 check_hash = \
80 $(if $(wildcard $(DL_DIR)/$(1)), \
81 $(if $(filter-out x,$(2)), \
82 $(if $(filter 64,$(shell printf '%s' '$(2)' | wc -c)), \
83 $(if $(filter $(2),$(call gen_sha256sum,$(1))),, \
84 $(call check_warn,hash_mismatch,$(1),$(2),$(3)) \
85 ), \
86 $(call check_warn,hash_deprecated,$(1),$(2),$(3)), \
87 ), \
88 $(call check_warn,hash_missing,$(1),$(2),$(3)) \
89 ), \
90 $(call check_warn,download_missing,$(1),$(2),$(3)) \
91 )
92
93 ifdef FIXUP
94 F_md5_deprecated = $(SCRIPT_DIR)/fixup-makefile.pl $(CURDIR)/Makefile rename-var $(2) $(3)
95 endif
96
97 C_md5_deprecated = Use of $(2) is deprecated, switch to $(3)
98
99 check_md5 = \
100 $(if $(filter-out x,$(1)), \
101 $(call check_warn,md5_deprecated,$(1),$(2),$(3)) \
102 )
103
104 hash_var = $(if $(filter-out x,$(1)),MD5SUM,HASH)
105 endif
106
107 define DownloadMethod/unknown
108 echo "ERROR: No download method available"; false
109 endef
110
111 define DownloadMethod/default
112 $(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(FILE)" "$(HASH)" "$(URL_FILE)" $(foreach url,$(URL),"$(url)") \
113 $(if $(filter check,$(1)), \
114 $(call check_hash,$(FILE),$(HASH),$(2)$(call hash_var,$(MD5SUM))) \
115 $(call check_md5,$(MD5SUM),$(2)MD5SUM,$(2)HASH) \
116 )
117 endef
118
119 define wrap_mirror
120 $(if $(if $(MIRROR),$(filter-out x,$(MIRROR_HASH))),$(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(FILE)" "$(MIRROR_HASH)" "" || ( $(3) ),$(3)) \
121 $(if $(filter check,$(1)), \
122 $(call check_hash,$(FILE),$(MIRROR_HASH),$(2)MIRROR_$(call hash_var,$(MIRROR_MD5SUM))) \
123 $(call check_md5,$(MIRROR_MD5SUM),$(2)MIRROR_MD5SUM,$(2)MIRROR_HASH) \
124 )
125 endef
126
127 define DownloadMethod/cvs
128 $(call wrap_mirror,$(1),$(2), \
129 echo "Checking out files from the cvs repository..."; \
130 mkdir -p $(TMP_DIR)/dl && \
131 cd $(TMP_DIR)/dl && \
132 rm -rf $(SUBDIR) && \
133 [ \! -d $(SUBDIR) ] && \
134 cvs -d $(URL) export $(VERSION) $(SUBDIR) && \
135 echo "Packing checkout..." && \
136 $(call dl_tar_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
137 mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
138 rm -rf $(SUBDIR); \
139 )
140 endef
141
142 define DownloadMethod/svn
143 $(call wrap_mirror,$(1),$(2), \
144 echo "Checking out files from the svn repository..."; \
145 mkdir -p $(TMP_DIR)/dl && \
146 cd $(TMP_DIR)/dl && \
147 rm -rf $(SUBDIR) && \
148 [ \! -d $(SUBDIR) ] && \
149 ( svn help export | grep -q trust-server-cert && \
150 svn export --non-interactive --trust-server-cert -r$(VERSION) $(URL) $(SUBDIR) || \
151 svn export --non-interactive -r$(VERSION) $(URL) $(SUBDIR) ) && \
152 echo "Packing checkout..." && \
153 export TAR_TIMESTAMP="" && \
154 $(call dl_tar_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
155 mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
156 rm -rf $(SUBDIR); \
157 )
158 endef
159
160 define DownloadMethod/git
161 $(call wrap_mirror,$(1),$(2), \
162 echo "Checking out files from the git repository..."; \
163 mkdir -p $(TMP_DIR)/dl && \
164 cd $(TMP_DIR)/dl && \
165 rm -rf $(SUBDIR) && \
166 [ \! -d $(SUBDIR) ] && \
167 git clone $(OPTS) $(URL) $(SUBDIR) && \
168 (cd $(SUBDIR) && git checkout $(VERSION) && \
169 git submodule update --init --recursive) && \
170 echo "Packing checkout..." && \
171 export TAR_TIMESTAMP=`cd $(SUBDIR) && git log -1 --format='@%ct'` && \
172 rm -rf $(SUBDIR)/.git && \
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/bzr
180 $(call wrap_mirror,$(1),$(2), \
181 echo "Checking out files from the bzr repository..."; \
182 mkdir -p $(TMP_DIR)/dl && \
183 cd $(TMP_DIR)/dl && \
184 rm -rf $(SUBDIR) && \
185 [ \! -d $(SUBDIR) ] && \
186 bzr export --per-file-timestamps -r$(VERSION) $(SUBDIR) $(URL) && \
187 echo "Packing checkout..." && \
188 export TAR_TIMESTAMP="" && \
189 $(call dl_tar_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
190 mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
191 rm -rf $(SUBDIR); \
192 )
193 endef
194
195 define DownloadMethod/hg
196 $(call wrap_mirror,$(1),$(2), \
197 echo "Checking out files from the hg repository..."; \
198 mkdir -p $(TMP_DIR)/dl && \
199 cd $(TMP_DIR)/dl && \
200 rm -rf $(SUBDIR) && \
201 [ \! -d $(SUBDIR) ] && \
202 hg clone -r $(VERSION) $(URL) $(SUBDIR) && \
203 export TAR_TIMESTAMP=`cd $(SUBDIR) && hg log --template '@{date}' -l 1` && \
204 find $(SUBDIR) -name .hg | xargs rm -rf && \
205 echo "Packing checkout..." && \
206 $(call dl_tar_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
207 mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
208 rm -rf $(SUBDIR); \
209 )
210 endef
211
212 define DownloadMethod/darcs
213 $(call wrap_mirror, $(1), $(2), \
214 echo "Checking out files from the darcs repository..."; \
215 mkdir -p $(TMP_DIR)/dl && \
216 cd $(TMP_DIR)/dl && \
217 rm -rf $(SUBDIR) && \
218 [ \! -d $(SUBDIR) ] && \
219 darcs get -t $(VERSION) $(URL) $(SUBDIR) && \
220 export TAR_TIMESTAMP=`cd $(SUBDIR) && LC_ALL=C darcs log --last 1 | sed -ne 's!^Date: \+!!p'` && \
221 find $(SUBDIR) -name _darcs | xargs rm -rf && \
222 echo "Packing checkout..." && \
223 $(call dl_tar_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
224 mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
225 rm -rf $(SUBDIR); \
226 )
227 endef
228
229 Validate/cvs=VERSION SUBDIR
230 Validate/svn=VERSION SUBDIR
231 Validate/git=VERSION SUBDIR
232 Validate/bzr=VERSION SUBDIR
233 Validate/hg=VERSION SUBDIR
234 Validate/darcs=VERSION SUBDIR
235
236 define Download/Defaults
237 URL:=
238 FILE:=
239 URL_FILE:=
240 PROTO:=
241 HASH=$$(MD5SUM)
242 MD5SUM:=x
243 SUBDIR:=
244 MIRROR:=1
245 MIRROR_HASH=$$(MIRROR_MD5SUM)
246 MIRROR_MD5SUM:=x
247 VERSION:=
248 OPTS:=
249 endef
250
251 define Download/default
252 FILE:=$(PKG_SOURCE)
253 URL:=$(PKG_SOURCE_URL)
254 SUBDIR:=$(PKG_SOURCE_SUBDIR)
255 PROTO:=$(PKG_SOURCE_PROTO)
256 $(if $(PKG_SOURCE_MIRROR),MIRROR:=$(filter 1,$(PKG_MIRROR)))
257 $(if $(PKG_MIRROR_MD5SUM),MIRROR_MD5SUM:=$(PKG_MIRROR_MD5SUM))
258 $(if $(PKG_MIRROR_HASH),MIRROR_HASH:=$(PKG_MIRROR_HASH))
259 VERSION:=$(PKG_SOURCE_VERSION)
260 $(if $(PKG_MD5SUM),MD5SUM:=$(PKG_MD5SUM))
261 $(if $(PKG_HASH),HASH:=$(PKG_HASH))
262 endef
263
264 define Download
265 $(eval $(Download/Defaults))
266 $(eval $(Download/$(1)))
267 $(foreach FIELD,URL FILE $(Validate/$(call dl_method,$(URL),$(PROTO))),
268 ifeq ($($(FIELD)),)
269 $$(error Download/$(1) is missing the $(FIELD) field.)
270 endif
271 )
272
273 $(foreach dep,$(DOWNLOAD_RDEP),
274 $(dep): $(DL_DIR)/$(FILE)
275 )
276 download: $(DL_DIR)/$(FILE)
277
278 $(DL_DIR)/$(FILE):
279 mkdir -p $(DL_DIR)
280 $(call locked, \
281 $(if $(DownloadMethod/$(call dl_method,$(URL),$(PROTO))), \
282 $(call DownloadMethod/$(call dl_method,$(URL),$(PROTO)),check,$(if $(filter default,$(1)),PKG_,Download/$(1):)), \
283 $(DownloadMethod/unknown) \
284 ),\
285 $(FILE))
286
287 endef