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