[ar7] add Titan MTD partitionning support (#6632)
[openwrt.git] / include / download.mk
1 #
2 # Copyright (C) 2006-2010 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/% ftp://% http://% 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 checkouts - useful for mirror support
32 dl_pack/bz2=$(TAR) cfj $(1) $(2)
33 dl_pack/gz=$(TAR) cfz $(1) $(2)
34 dl_pack/unknown=echo "ERROR: Unknown pack format for file $(1)"; false
35 define dl_pack
36 $(if $(dl_pack/$(call ext,$(1))),$(dl_pack/$(call ext,$(1))),$(dl_pack/unknown))
37 endef
38
39 define DownloadMethod/unknown
40 @echo "ERROR: No download method available"; false
41 endef
42
43 define DownloadMethod/default
44 $(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(FILE)" "$(MD5SUM)" $(URL)
45 endef
46
47 define wrap_mirror
48 $(if $(MIRROR),@$(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(FILE)" "x" || ( $(1) ),$(1))
49 endef
50
51 define DownloadMethod/cvs
52 $(call wrap_mirror, \
53 echo "Checking out files from the cvs repository..."; \
54 mkdir -p $(TMP_DIR)/dl && \
55 cd $(TMP_DIR)/dl && \
56 rm -rf $(SUBDIR) && \
57 [ \! -d $(SUBDIR) ] && \
58 cvs -d $(URL) export $(VERSION) $(SUBDIR) && \
59 echo "Packing checkout..." && \
60 $(call dl_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
61 mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
62 rm -rf $(SUBDIR); \
63 )
64 endef
65
66 define DownloadMethod/svn
67 $(call wrap_mirror, \
68 echo "Checking out files from the svn repository..."; \
69 mkdir -p $(TMP_DIR)/dl && \
70 cd $(TMP_DIR)/dl && \
71 rm -rf $(SUBDIR) && \
72 [ \! -d $(SUBDIR) ] && \
73 ( svn help export | grep -q trust-server-cert && \
74 svn export --non-interactive --trust-server-cert -r$(VERSION) $(URL) $(SUBDIR) || \
75 svn export --non-interactive -r$(VERSION) $(URL) $(SUBDIR) ) && \
76 echo "Packing checkout..." && \
77 $(call dl_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
78 mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
79 rm -rf $(SUBDIR); \
80 )
81 endef
82
83 define DownloadMethod/git
84 $(call wrap_mirror, \
85 echo "Checking out files from the git repository..."; \
86 mkdir -p $(TMP_DIR)/dl && \
87 cd $(TMP_DIR)/dl && \
88 rm -rf $(SUBDIR) && \
89 [ \! -d $(SUBDIR) ] && \
90 git clone $(URL) $(SUBDIR) && \
91 (cd $(SUBDIR) && git checkout $(VERSION)) && \
92 echo "Packing checkout..." && \
93 rm -rf $(SUBDIR)/.git && \
94 $(call dl_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
95 mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
96 rm -rf $(SUBDIR); \
97 )
98 endef
99
100 define DownloadMethod/bzr
101 $(call wrap_mirror, \
102 echo "Checking out files from the bzr repository..."; \
103 mkdir -p $(TMP_DIR)/dl && \
104 cd $(TMP_DIR)/dl && \
105 rm -rf $(SUBDIR) && \
106 [ \! -d $(SUBDIR) ] && \
107 bzr export -r$(VERSION) $(SUBDIR) $(URL) && \
108 echo "Packing checkout..." && \
109 $(call dl_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
110 mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
111 rm -rf $(SUBDIR); \
112 )
113 endef
114
115 define DownloadMethod/hg
116 $(call wrap_mirror, \
117 echo "Checking out files from the hg repository..."; \
118 mkdir -p $(TMP_DIR)/dl && \
119 cd $(TMP_DIR)/dl && \
120 rm -rf $(SUBDIR) && \
121 [ \! -d $(SUBDIR) ] && \
122 hg clone -r $(VERSION) $(URL) $(SUBDIR) && \
123 find $(SUBDIR) -name .hg | xargs rm -rf && \
124 echo "Packing checkout..." && \
125 $(call dl_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
126 mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
127 rm -rf $(SUBDIR); \
128 )
129 endef
130
131 Validate/cvs=VERSION SUBDIR
132 Validate/svn=VERSION SUBDIR
133 Validate/git=VERSION SUBDIR
134 Validate/bzr=VERSION SUBDIR
135 Validate/hg=VERSION SUBDIR
136
137 define Download/Defaults
138 URL:=
139 FILE:=
140 PROTO:=
141 MD5SUM:=
142 SUBDIR:=
143 MIRROR:=1
144 VERSION:=
145 endef
146
147 define Download
148 $(eval $(Download/Defaults))
149 $(eval $(Download/$(1)))
150 $(foreach FIELD,URL FILE $(Validate/$(call dl_method,$(URL),$(PROTO))),
151 ifeq ($($(FIELD)),)
152 $$(error Download/$(1) is missing the $(FIELD) field.)
153 endif
154 )
155
156 $(foreach dep,$(DOWNLOAD_RDEP),
157 $(dep): $(DL_DIR)/$(FILE)
158 )
159 download: $(DL_DIR)/$(FILE)
160
161 $(DL_DIR)/$(FILE):
162 mkdir -p $(DL_DIR)
163 $(if $(DownloadMethod/$(call dl_method,$(URL),$(PROTO))),$(DownloadMethod/$(call dl_method,$(URL),$(PROTO))),$(DownloadMethod/unknown))
164
165 endef
This page took 0.045121 seconds and 5 git commands to generate.