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
=$(TAR
) --owner
=0 --group
=0 --sort=name
$$$${TAR_TIMESTAMP
:+--mtime
="$$$$TAR_TIMESTAMP"} -cjf
$(1) $(2)
37 dl_pack
/gz
=$(TAR
) --owner
=0 --group
=0 --sort=name
$$$${TAR_TIMESTAMP
:+--mtime
="$$$$TAR_TIMESTAMP"} -c
$(2) | gzip
-nc
> $(1)
38 dl_pack
/xz
=$(TAR
) --owner
=0 --group
=0 --sort=name
$$$${TAR_TIMESTAMP
:+--mtime
="$$$$TAR_TIMESTAMP"} -c
$(2) | xz
-zc
-7e
> $(1)
39 dl_pack
/unknown
=echo
"ERROR: Unknown pack format for file $(1)"; false
41 $(if
$(dl_pack
/$(call ext
,$(1))),$(dl_pack
/$(call ext
,$(1))),$(dl_pack
/unknown
))
44 define DownloadMethod
/unknown
45 @echo
"ERROR: No download method available"; false
48 define DownloadMethod
/default
49 $(SCRIPT_DIR
)/download.pl
"$(DL_DIR)" "$(FILE)" "$(MD5SUM)" "$(URL_FILE)" $(foreach url
,$(URL
),"$(url)")
53 $(if
$(if
$(MIRROR
),$(filter-out x
,$(MIRROR_MD5SUM
))),$(SCRIPT_DIR
)/download.pl
"$(DL_DIR)" "$(FILE)" "$(MIRROR_MD5SUM)" "" ||
( $(1) ),$(1))
56 define DownloadMethod
/cvs
58 echo
"Checking out files from the cvs repository..."; \
59 mkdir
-p
$(TMP_DIR
)/dl
&& \
62 [ \
! -d
$(SUBDIR
) ] && \
63 cvs
-d
$(URL
) export $(VERSION
) $(SUBDIR
) && \
64 echo
"Packing checkout..." && \
65 $(call dl_pack
,$(TMP_DIR
)/dl
/$(FILE
),$(SUBDIR
)) && \
66 mv
$(TMP_DIR
)/dl
/$(FILE
) $(DL_DIR
)/ && \
71 define DownloadMethod
/svn
73 echo
"Checking out files from the svn repository..."; \
74 mkdir
-p
$(TMP_DIR
)/dl
&& \
77 [ \
! -d
$(SUBDIR
) ] && \
78 ( svn help
export | grep
-q trust-server-cert
&& \
79 svn
export --non-interactive
--trust-server-cert
-r
$(VERSION
) $(URL
) $(SUBDIR
) || \
80 svn
export --non-interactive
-r
$(VERSION
) $(URL
) $(SUBDIR
) ) && \
81 echo
"Packing checkout..." && \
82 export TAR_TIMESTAMP
="" && \
83 $(call dl_pack
,$(TMP_DIR
)/dl
/$(FILE
),$(SUBDIR
)) && \
84 mv
$(TMP_DIR
)/dl
/$(FILE
) $(DL_DIR
)/ && \
89 define DownloadMethod
/git
91 echo
"Checking out files from the git repository..."; \
92 mkdir
-p
$(TMP_DIR
)/dl
&& \
95 [ \
! -d
$(SUBDIR
) ] && \
96 git clone
$(URL
) $(SUBDIR
) && \
97 (cd
$(SUBDIR
) && git checkout
$(VERSION
) && \
98 git submodule update
--init
--recursive
) && \
99 echo
"Packing checkout..." && \
100 export TAR_TIMESTAMP
=`cd $(SUBDIR) && git log -1 --format='@%ct'` && \
101 rm -rf
$(SUBDIR
)/.git
&& \
102 $(call dl_pack
,$(TMP_DIR
)/dl
/$(FILE
),$(SUBDIR
)) && \
103 mv
$(TMP_DIR
)/dl
/$(FILE
) $(DL_DIR
)/ && \
108 define DownloadMethod
/bzr
109 $(call wrap_mirror
, \
110 echo
"Checking out files from the bzr repository..."; \
111 mkdir
-p
$(TMP_DIR
)/dl
&& \
112 cd
$(TMP_DIR
)/dl
&& \
113 rm -rf
$(SUBDIR
) && \
114 [ \
! -d
$(SUBDIR
) ] && \
115 bzr
export --per-file-timestamps
-r
$(VERSION
) $(SUBDIR
) $(URL
) && \
116 echo
"Packing checkout..." && \
117 export TAR_TIMESTAMP
="" && \
118 $(call dl_pack
,$(TMP_DIR
)/dl
/$(FILE
),$(SUBDIR
)) && \
119 mv
$(TMP_DIR
)/dl
/$(FILE
) $(DL_DIR
)/ && \
124 define DownloadMethod
/hg
125 $(call wrap_mirror
, \
126 echo
"Checking out files from the hg repository..."; \
127 mkdir
-p
$(TMP_DIR
)/dl
&& \
128 cd
$(TMP_DIR
)/dl
&& \
129 rm -rf
$(SUBDIR
) && \
130 [ \
! -d
$(SUBDIR
) ] && \
131 hg clone
-r
$(VERSION
) $(URL
) $(SUBDIR
) && \
132 export TAR_TIMESTAMP
=`cd $(SUBDIR) && hg log --template '@{date}' -l 1` && \
133 find
$(SUBDIR
) -name .hg | xargs
rm -rf
&& \
134 echo
"Packing checkout..." && \
135 $(call dl_pack
,$(TMP_DIR
)/dl
/$(FILE
),$(SUBDIR
)) && \
136 mv
$(TMP_DIR
)/dl
/$(FILE
) $(DL_DIR
)/ && \
141 define DownloadMethod
/darcs
142 $(call wrap_mirror
, \
143 echo
"Checking out files from the darcs repository..."; \
144 mkdir
-p
$(TMP_DIR
)/dl
&& \
145 cd
$(TMP_DIR
)/dl
&& \
146 rm -rf
$(SUBDIR
) && \
147 [ \
! -d
$(SUBDIR
) ] && \
148 darcs
get -t
$(VERSION
) $(URL
) $(SUBDIR
) && \
149 export TAR_TIMESTAMP
=`cd $(SUBDIR) && LC_ALL=C darcs log --last 1 | sed -ne 's!^Date: \+!!p'` && \
150 find
$(SUBDIR
) -name _darcs | xargs
rm -rf
&& \
151 echo
"Packing checkout..." && \
152 $(call dl_pack
,$(TMP_DIR
)/dl
/$(FILE
),$(SUBDIR
)) && \
153 mv
$(TMP_DIR
)/dl
/$(FILE
) $(DL_DIR
)/ && \
158 Validate
/cvs
=VERSION SUBDIR
159 Validate
/svn
=VERSION SUBDIR
160 Validate
/git
=VERSION SUBDIR
161 Validate
/bzr
=VERSION SUBDIR
162 Validate
/hg
=VERSION SUBDIR
163 Validate
/darcs
=VERSION SUBDIR
165 define Download
/Defaults
178 $(eval
$(Download
/Defaults
))
179 $(eval
$(Download
/$(1)))
180 $(foreach FIELD
,URL FILE
$(Validate
/$(call dl_method
,$(URL
),$(PROTO
))),
182 $$(error Download
/$(1) is missing the
$(FIELD
) field.
)
186 $(foreach dep
,$(DOWNLOAD_RDEP
),
187 $(dep
): $(DL_DIR
)/$(FILE
)
189 download
: $(DL_DIR
)/$(FILE
)
193 $(call locked
,$(if
$(DownloadMethod
/$(call dl_method
,$(URL
),$(PROTO
))),$(DownloadMethod
/$(call dl_method
,$(URL
),$(PROTO
))),$(DownloadMethod
/unknown
)),$(FILE
))