2 # Copyright (C) 2006-2012 OpenWrt.org
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
8 OPENWRT_GIT = http://git.openwrt.org
10 DOWNLOAD_RDEP=$(STAMP_PREPARED) $(HOST_STAMP_PREPARED)
12 # Try to guess the download method from the URL
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, \
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
39 $(if $(dl_pack/$(call ext,$(1))),$(dl_pack/$(call ext,$(1))),$(dl_pack/unknown))
42 define DownloadMethod/unknown
43 @echo "ERROR: No download method available"; false
46 define DownloadMethod/default
47 $(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(FILE)" "$(MD5SUM)" "$(URL_FILE)" $(foreach url,$(URL),"$(url)")
51 $(if $(if $(MIRROR),$(filter-out x,$(MIRROR_MD5SUM))),@$(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(FILE)" "$(MIRROR_MD5SUM)" "" || ( $(1) ),$(1))
54 define DownloadMethod/cvs
56 echo "Checking out files from the cvs repository..."; \
57 mkdir -p $(TMP_DIR)/dl && \
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)/ && \
69 define DownloadMethod/svn
71 echo "Checking out files from the svn repository..."; \
72 mkdir -p $(TMP_DIR)/dl && \
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)/ && \
86 define DownloadMethod/git
88 echo "Checking out files from the git repository..."; \
89 mkdir -p $(TMP_DIR)/dl && \
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)/ && \
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)/ && \
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)/ && \
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)/ && \
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
157 define Download/Defaults
170 $(eval $(Download/Defaults))
171 $(eval $(Download/$(1)))
172 $(foreach FIELD,URL FILE $(Validate/$(call dl_method,$(URL),$(PROTO))),
174 $$(error Download/$(1) is missing the $(FIELD) field.)
178 $(foreach dep,$(DOWNLOAD_RDEP),
179 $(dep): $(DL_DIR)/$(FILE)
181 download: $(DL_DIR)/$(FILE)
185 $(if $(DownloadMethod/$(call dl_method,$(URL),$(PROTO))),$(DownloadMethod/$(call dl_method,$(URL),$(PROTO))),$(DownloadMethod/unknown))