package/utils/e2fsprogs: Update to 1.43.3
[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 OPENWRT_GIT = http://git.openwrt.org
10 LEDE_GIT = https://git.lede-project.org
11
12 DOWNLOAD_RDEP=$(STAMP_PREPARED) $(HOST_STAMP_PREPARED)
13
14 # Try to guess the download method from the URL
15 define dl_method
16 $(strip \
17 $(if $(2),$(2), \
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, \
24 unknown \
25 ) \
26 ) \
27 ) \
28 ) \
29 ) \
30 ) \
31 ) \
32 )
33 endef
34
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
40 define dl_pack
41 $(if $(dl_pack/$(call ext,$(1))),$(dl_pack/$(call ext,$(1))),$(dl_pack/unknown))
42 endef
43
44 define DownloadMethod/unknown
45 @echo "ERROR: No download method available"; false
46 endef
47
48 define DownloadMethod/default
49 $(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(FILE)" "$(MD5SUM)" "$(URL_FILE)" $(foreach url,$(URL),"$(url)")
50 endef
51
52 define wrap_mirror
53 $(if $(if $(MIRROR),$(filter-out x,$(MIRROR_MD5SUM))),$(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(FILE)" "$(MIRROR_MD5SUM)" "" || ( $(1) ),$(1))
54 endef
55
56 define DownloadMethod/cvs
57 $(call wrap_mirror, \
58 echo "Checking out files from the cvs repository..."; \
59 mkdir -p $(TMP_DIR)/dl && \
60 cd $(TMP_DIR)/dl && \
61 rm -rf $(SUBDIR) && \
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)/ && \
67 rm -rf $(SUBDIR); \
68 )
69 endef
70
71 define DownloadMethod/svn
72 $(call wrap_mirror, \
73 echo "Checking out files from the svn repository..."; \
74 mkdir -p $(TMP_DIR)/dl && \
75 cd $(TMP_DIR)/dl && \
76 rm -rf $(SUBDIR) && \
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)/ && \
85 rm -rf $(SUBDIR); \
86 )
87 endef
88
89 define DownloadMethod/git
90 $(call wrap_mirror, \
91 echo "Checking out files from the git repository..."; \
92 mkdir -p $(TMP_DIR)/dl && \
93 cd $(TMP_DIR)/dl && \
94 rm -rf $(SUBDIR) && \
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)/ && \
104 rm -rf $(SUBDIR); \
105 )
106 endef
107
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)/ && \
120 rm -rf $(SUBDIR); \
121 )
122 endef
123
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)/ && \
137 rm -rf $(SUBDIR); \
138 )
139 endef
140
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)/ && \
154 rm -rf $(SUBDIR); \
155 )
156 endef
157
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
164
165 define Download/Defaults
166 URL:=
167 FILE:=
168 URL_FILE:=
169 PROTO:=
170 MD5SUM:=
171 SUBDIR:=
172 MIRROR:=1
173 MIRROR_MD5SUM:=x
174 VERSION:=
175 endef
176
177 define Download
178 $(eval $(Download/Defaults))
179 $(eval $(Download/$(1)))
180 $(foreach FIELD,URL FILE $(Validate/$(call dl_method,$(URL),$(PROTO))),
181 ifeq ($($(FIELD)),)
182 $$(error Download/$(1) is missing the $(FIELD) field.)
183 endif
184 )
185
186 $(foreach dep,$(DOWNLOAD_RDEP),
187 $(dep): $(DL_DIR)/$(FILE)
188 )
189 download: $(DL_DIR)/$(FILE)
190
191 $(DL_DIR)/$(FILE):
192 mkdir -p $(DL_DIR)
193 $(call locked,$(if $(DownloadMethod/$(call dl_method,$(URL),$(PROTO))),$(DownloadMethod/$(call dl_method,$(URL),$(PROTO))),$(DownloadMethod/unknown)),$(FILE))
194
195 endef