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 PROJECT_GIT
= https
://git.openwrt.org
11 OPENWRT_GIT
= $(PROJECT_GIT
)
12 LEDE_GIT
= $(PROJECT_GIT
)
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
20 DOWNLOAD_RDEP
=$(STAMP_PREPARED
) $(HOST_STAMP_PREPARED
)
23 $(if
$(filter https
://github.com
/% git
://github.com
/%,$(1)),github_archive
,git
)
26 # Try to guess the download method from the URL
29 $(if
$(filter git
,$(2)),$(call dl_method_git
,$(1),$(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
, \
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))
55 $(if
$(dl_pack
/$(call ext
,$(1))),$(dl_pack
/$(call ext
,$(1))),$(dl_pack
/unknown
))
58 $(TAR
) --numeric-owner
--owner
=0 --group
=0 --sort=name
$$$${TAR_TIMESTAMP
:+--mtime
="$$$$TAR_TIMESTAMP"} -c
$(2) |
$(call dl_pack
,$(1))
62 check_escape
=$(subst ','\'',$(1))
65 # $(1): suffix of the F_, C_ variables, e.g. hash_deprecated, hash_mismatch, etc.
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)))'))
71 check_warn
= $(check_warn_nofix
)
73 check_warn
= $(if
$(filter-out undefined
,$(origin F_
$(1))),$(filter ,$(shell $(call F_
$(1),$(2),$(3),$(4)) >&2)),$(check_warn_nofix
))
76 gen_sha256sum
= $(shell mkhash sha256
$(DL_DIR
)/$(1))
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))
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))
93 # $(2): expected hash value
94 # $(3): var name of the the form: {PKG_,Download/<name>:}{,MIRROR_}{HASH,MIRROR_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)) \
102 $(call check_warn
,hash_deprecated
,$(1),$(2),$(3)), \
104 $(call check_warn
,hash_missing
,$(1),$(2),$(3)) \
106 $(call check_warn
,download_missing
,$(1),$(2),$(3)) \
110 F_md5_deprecated
= $(SCRIPT_DIR
)/fixup-makefile.pl
$(CURDIR
)/Makefile rename-var
$(2) $(3)
113 C_md5_deprecated
= Use of
$(2) is deprecated
, switch to
$(3)
116 $(if
$(filter-out x
,$(1)), \
117 $(call check_warn
,md5_deprecated
,$(1),$(2),$(3)) \
120 hash_var
= $(if
$(filter-out x
,$(1)),MD5SUM
,HASH
)
123 define DownloadMethod
/unknown
124 echo
"ERROR: No download method available"; false
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
) \
136 # $(2): "PKG_" if <name> as in Download/<name> is "default", otherwise "Download/<name>:"
137 # $(3): shell command sequence to do the download
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
) \
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
)/ && \
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
)/ && \
179 define DownloadMethod
/git
180 $(call wrap_mirror
,$(1),$(2), \
181 $(call DownloadMethod
/rawgit
) \
185 define DownloadMethod
/github_archive
186 $(call wrap_mirror
,$(1),$(2), \
187 $(SCRIPT_DIR
)/dl_github_archive.py \
188 --dl-dir
="$(DL_DIR)" \
190 --version
="$(VERSION)" \
191 --subdir
="$(SUBDIR)" \
193 --hash
="$(MIRROR_HASH)" \
194 ||
( $(call DownloadMethod
/rawgit
) ); \
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
)/ && \
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
)/ && \
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
)/ && \
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
)/ && \
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
273 define Download
/Defaults
282 MIRROR_HASH
=$$(MIRROR_MD5SUM
)
288 define Download
/default
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
))
302 $(eval
$(Download
/Defaults
))
303 $(eval
$(Download
/$(1)))
304 $(foreach FIELD
,URL FILE
$(Validate
/$(call dl_method
,$(URL
),$(PROTO
))),
306 $$(error Download
/$(1) is missing the
$(FIELD
) field.
)
310 $(foreach dep
,$(DOWNLOAD_RDEP
),
311 $(dep
): $(DL_DIR
)/$(FILE
)
313 download
: $(DL_DIR
)/$(FILE
)
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
) \