atheros: config-2.6.33, optimize for size
[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 SVN_VERSION=$(shell svn --version | head -1 | awk '{ print $3 }' | cut -d. -f2)
67 ifeq ($(SVN_VERSION),5)
68 else
69 SVN_OPTS:=--trust-server-cert
70 endif
71
72 define DownloadMethod/svn
73 $(call wrap_mirror, \
74 echo "Checking out files from the svn repository..."; \
75 mkdir -p $(TMP_DIR)/dl && \
76 cd $(TMP_DIR)/dl && \
77 rm -rf $(SUBDIR) && \
78 [ \! -d $(SUBDIR) ] && \
79 svn export --non-interactive $(SVN_OPTS) -r$(VERSION) $(URL) $(SUBDIR) && \
80 echo "Packing checkout..." && \
81 $(call dl_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
82 mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
83 rm -rf $(SUBDIR); \
84 )
85 endef
86
87 define DownloadMethod/git
88 $(call wrap_mirror, \
89 echo "Checking out files from the git repository..."; \
90 mkdir -p $(TMP_DIR)/dl && \
91 cd $(TMP_DIR)/dl && \
92 rm -rf $(SUBDIR) && \
93 [ \! -d $(SUBDIR) ] && \
94 git clone $(URL) $(SUBDIR) && \
95 (cd $(SUBDIR) && git checkout $(VERSION)) && \
96 echo "Packing checkout..." && \
97 rm -rf $(SUBDIR)/.git && \
98 $(call dl_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
99 mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
100 rm -rf $(SUBDIR); \
101 )
102 endef
103
104 define DownloadMethod/bzr
105 $(call wrap_mirror, \
106 echo "Checking out files from the bzr repository..."; \
107 mkdir -p $(TMP_DIR)/dl && \
108 cd $(TMP_DIR)/dl && \
109 rm -rf $(SUBDIR) && \
110 [ \! -d $(SUBDIR) ] && \
111 bzr export -r$(VERSION) $(URL) $(SUBDIR) && \
112 echo "Packing checkout..." && \
113 $(call dl_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
114 mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ &&
115 rm -rf $(SUBDIR); \
116 )
117 endef
118
119 define DownloadMethod/hg
120 $(call wrap_mirror, \
121 echo "Checking out files from the hg repository..."; \
122 mkdir -p $(TMP_DIR)/dl && \
123 cd $(TMP_DIR)/dl && \
124 rm -rf $(SUBDIR) && \
125 [ \! -d $(SUBDIR) ] && \
126 hg clone -r $(VERSION) $(URL) $(SUBDIR) && \
127 find $(SUBDIR) -name .hg | xargs rm -rf && \
128 echo "Packing checkout..." && \
129 $(call dl_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
130 mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
131 rm -rf $(SUBDIR); \
132 )
133 endef
134
135 Validate/cvs=VERSION SUBDIR
136 Validate/svn=VERSION SUBDIR
137 Validate/git=VERSION SUBDIR
138 Validate/bzr=VERSION SUBDIR
139 Validate/hg=VERSION SUBDIR
140
141 define Download/Defaults
142 URL:=
143 FILE:=
144 PROTO:=
145 MD5SUM:=
146 SUBDIR:=
147 MIRROR:=1
148 VERSION:=
149 endef
150
151 define Download
152 $(eval $(Download/Defaults))
153 $(eval $(Download/$(1)))
154 $(foreach FIELD,URL FILE $(Validate/$(call dl_method,$(URL),$(PROTO))),
155 ifeq ($($(FIELD)),)
156 $$(error Download/$(1) is missing the $(FIELD) field.)
157 endif
158 )
159
160 $(foreach dep,$(DOWNLOAD_RDEP),
161 $(dep): $(DL_DIR)/$(FILE)
162 )
163 download: $(DL_DIR)/$(FILE)
164
165 $(DL_DIR)/$(FILE):
166 mkdir -p $(DL_DIR)
167 $(if $(DownloadMethod/$(call dl_method,$(URL),$(PROTO))),$(DownloadMethod/$(call dl_method,$(URL),$(PROTO))),$(DownloadMethod/unknown))
168
169 endef
This page took 0.049564 seconds and 5 git commands to generate.