imx6: image: Remove custom mkfs targz override as base should be fine now
[openwrt/openwrt.git] / include / download.mk
1 #
2 # Copyright (C) 2006-2012 OpenWrt.org
3 #
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
6 #
7
8 DOWNLOAD_RDEP=$(STAMP_PREPARED) $(HOST_STAMP_PREPARED)
9
10 # Try to guess the download method from the URL
11 define dl_method
12 $(strip \
13 $(if $(2),$(2), \
14 $(if $(filter @GNOME/% @GNU/% @KERNEL/% @SF/% @SAVANNAH/% ftp://% http://% https://% file://%,$(1)),default, \
15 $(if $(filter git://%,$(1)),git, \
16 $(if $(filter svn://%,$(1)),svn, \
17 $(if $(filter cvs://%,$(1)),cvs, \
18 $(if $(filter hg://%,$(1)),hg, \
19 $(if $(filter sftp://%,$(1)),bzr, \
20 unknown \
21 ) \
22 ) \
23 ) \
24 ) \
25 ) \
26 ) \
27 ) \
28 )
29 endef
30
31 # code for creating tarballs from cvs/svn/git/bzr/hg/darcs checkouts - useful for mirror support
32 dl_pack/bz2=$(TAR) cjf $(1) $(2)
33 dl_pack/gz=$(TAR) czf $(1) $(2)
34 dl_pack/xz=$(TAR) c $(2) | xz -zc > $(1)
35 dl_pack/unknown=echo "ERROR: Unknown pack format for file $(1)"; false
36 define dl_pack
37 $(if $(dl_pack/$(call ext,$(1))),$(dl_pack/$(call ext,$(1))),$(dl_pack/unknown))
38 endef
39
40 define DownloadMethod/unknown
41 @echo "ERROR: No download method available"; false
42 endef
43
44 define DownloadMethod/default
45 $(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(FILE)" "$(MD5SUM)" $(foreach url,$(URL),"$(url)")
46 endef
47
48 define wrap_mirror
49 $(if $(if $(MIRROR),$(filter-out x,$(MIRROR_MD5SUM))),@$(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(FILE)" "$(MIRROR_MD5SUM)" || ( $(1) ),$(1))
50 endef
51
52 define DownloadMethod/cvs
53 $(call wrap_mirror, \
54 echo "Checking out files from the cvs repository..."; \
55 mkdir -p $(TMP_DIR)/dl && \
56 cd $(TMP_DIR)/dl && \
57 rm -rf $(SUBDIR) && \
58 [ \! -d $(SUBDIR) ] && \
59 cvs -d $(URL) export $(VERSION) $(SUBDIR) && \
60 echo "Packing checkout..." && \
61 $(call dl_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
62 mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
63 rm -rf $(SUBDIR); \
64 )
65 endef
66
67 define DownloadMethod/svn
68 $(call wrap_mirror, \
69 echo "Checking out files from the svn repository..."; \
70 mkdir -p $(TMP_DIR)/dl && \
71 cd $(TMP_DIR)/dl && \
72 rm -rf $(SUBDIR) && \
73 [ \! -d $(SUBDIR) ] && \
74 ( svn help export | grep -q trust-server-cert && \
75 svn export --non-interactive --trust-server-cert -r$(VERSION) $(URL) $(SUBDIR) || \
76 svn export --non-interactive -r$(VERSION) $(URL) $(SUBDIR) ) && \
77 echo "Packing checkout..." && \
78 $(call dl_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
79 mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
80 rm -rf $(SUBDIR); \
81 )
82 endef
83
84 define DownloadMethod/git
85 $(call wrap_mirror, \
86 echo "Checking out files from the git repository..."; \
87 mkdir -p $(TMP_DIR)/dl && \
88 cd $(TMP_DIR)/dl && \
89 rm -rf $(SUBDIR) && \
90 [ \! -d $(SUBDIR) ] && \
91 git clone $(URL) $(SUBDIR) --recursive && \
92 (cd $(SUBDIR) && git checkout $(VERSION) && git submodule update) && \
93 echo "Packing checkout..." && \
94 rm -rf $(SUBDIR)/.git && \
95 $(call dl_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
96 mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
97 rm -rf $(SUBDIR); \
98 )
99 endef
100
101 define DownloadMethod/bzr
102 $(call wrap_mirror, \
103 echo "Checking out files from the bzr repository..."; \
104 mkdir -p $(TMP_DIR)/dl && \
105 cd $(TMP_DIR)/dl && \
106 rm -rf $(SUBDIR) && \
107 [ \! -d $(SUBDIR) ] && \
108 bzr export -r$(VERSION) $(SUBDIR) $(URL) && \
109 echo "Packing checkout..." && \
110 $(call dl_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
111 mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
112 rm -rf $(SUBDIR); \
113 )
114 endef
115
116 define DownloadMethod/hg
117 $(call wrap_mirror, \
118 echo "Checking out files from the hg repository..."; \
119 mkdir -p $(TMP_DIR)/dl && \
120 cd $(TMP_DIR)/dl && \
121 rm -rf $(SUBDIR) && \
122 [ \! -d $(SUBDIR) ] && \
123 hg clone -r $(VERSION) $(URL) $(SUBDIR) && \
124 find $(SUBDIR) -name .hg | xargs rm -rf && \
125 echo "Packing checkout..." && \
126 $(call dl_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
127 mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
128 rm -rf $(SUBDIR); \
129 )
130 endef
131
132 define DownloadMethod/darcs
133 $(call wrap_mirror, \
134 echo "Checking out files from the darcs repository..."; \
135 mkdir -p $(TMP_DIR)/dl && \
136 cd $(TMP_DIR)/dl && \
137 rm -rf $(SUBDIR) && \
138 [ \! -d $(SUBDIR) ] && \
139 darcs get -t $(VERSION) $(URL) $(SUBDIR) && \
140 find $(SUBDIR) -name _darcs | xargs rm -rf && \
141 echo "Packing checkout..." && \
142 $(call dl_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
143 mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
144 rm -rf $(SUBDIR); \
145 )
146 endef
147
148 Validate/cvs=VERSION SUBDIR
149 Validate/svn=VERSION SUBDIR
150 Validate/git=VERSION SUBDIR
151 Validate/bzr=VERSION SUBDIR
152 Validate/hg=VERSION SUBDIR
153 Validate/darcs=VERSION SUBDIR
154
155 define Download/Defaults
156 URL:=
157 FILE:=
158 PROTO:=
159 MD5SUM:=
160 SUBDIR:=
161 MIRROR:=1
162 MIRROR_MD5SUM:=x
163 VERSION:=
164 endef
165
166 define Download
167 $(eval $(Download/Defaults))
168 $(eval $(Download/$(1)))
169 $(foreach FIELD,URL FILE $(Validate/$(call dl_method,$(URL),$(PROTO))),
170 ifeq ($($(FIELD)),)
171 $$(error Download/$(1) is missing the $(FIELD) field.)
172 endif
173 )
174
175 $(foreach dep,$(DOWNLOAD_RDEP),
176 $(dep): $(DL_DIR)/$(FILE)
177 )
178 download: $(DL_DIR)/$(FILE)
179
180 $(DL_DIR)/$(FILE):
181 mkdir -p $(DL_DIR)
182 $(if $(DownloadMethod/$(call dl_method,$(URL),$(PROTO))),$(DownloadMethod/$(call dl_method,$(URL),$(PROTO))),$(DownloadMethod/unknown))
183
184 endef