Root/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
8DOWNLOAD_RDEP=$(STAMP_PREPARED) $(HOST_STAMP_PREPARED)
9
10# Try to guess the download method from the URL
11define dl_method
12$(strip \
13  $(if $(2),$(2), \
14    $(if $(filter @GNOME/% @GNU/% @KERNEL/% @SF/% 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)
29endef
30
31# code for creating tarballs from cvs/svn/git/bzr/hg/darcs checkouts - useful for mirror support
32dl_pack/bz2=$(TAR) cfj $(1) $(2)
33dl_pack/gz=$(TAR) cfz $(1) $(2)
34dl_pack/unknown=echo "ERROR: Unknown pack format for file $(1)"; false
35define dl_pack
36    $(if $(dl_pack/$(call ext,$(1))),$(dl_pack/$(call ext,$(1))),$(dl_pack/unknown))
37endef
38
39define DownloadMethod/unknown
40    @echo "ERROR: No download method available"; false
41endef
42
43define DownloadMethod/default
44    $(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(FILE)" "$(MD5SUM)" $(foreach url,$(URL),"$(url)")
45endef
46
47define wrap_mirror
48    $(if $(MIRROR),@$(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(FILE)" "$(MIRROR_MD5SUM)" || ( $(1) ),$(1))
49endef
50
51define 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    )
64endef
65
66define 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    )
81endef
82
83define 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    )
98endef
99
100define 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    )
113endef
114
115define 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    )
129endef
130
131define DownloadMethod/darcs
132    $(call wrap_mirror, \
133        echo "Checking out files from the darcs repository..."; \
134        mkdir -p $(TMP_DIR)/dl && \
135        cd $(TMP_DIR)/dl && \
136        rm -rf $(SUBDIR) && \
137        [ \! -d $(SUBDIR) ] && \
138        darcs get -t $(VERSION) $(URL) $(SUBDIR) && \
139        find $(SUBDIR) -name _darcs | xargs rm -rf && \
140        echo "Packing checkout..." && \
141        $(call dl_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
142        mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
143        rm -rf $(SUBDIR); \
144    )
145endef
146
147Validate/cvs=VERSION SUBDIR
148Validate/svn=VERSION SUBDIR
149Validate/git=VERSION SUBDIR
150Validate/bzr=VERSION SUBDIR
151Validate/hg=VERSION SUBDIR
152Validate/darcs=VERSION SUBDIR
153
154define Download/Defaults
155  URL:=
156  FILE:=
157  PROTO:=
158  MD5SUM:=
159  SUBDIR:=
160  MIRROR:=1
161  MIRROR_MD5SUM:=x
162  VERSION:=
163endef
164
165define Download
166  $(eval $(Download/Defaults))
167  $(eval $(Download/$(1)))
168  $(foreach FIELD,URL FILE $(Validate/$(call dl_method,$(URL),$(PROTO))),
169    ifeq ($($(FIELD)),)
170      $$(error Download/$(1) is missing the $(FIELD) field.)
171    endif
172  )
173
174  $(foreach dep,$(DOWNLOAD_RDEP),
175    $(dep): $(DL_DIR)/$(FILE)
176  )
177  download: $(DL_DIR)/$(FILE)
178
179  $(DL_DIR)/$(FILE):
180    mkdir -p $(DL_DIR)
181    $(if $(DownloadMethod/$(call dl_method,$(URL),$(PROTO))),$(DownloadMethod/$(call dl_method,$(URL),$(PROTO))),$(DownloadMethod/unknown))
182
183endef
184

Archive Download this file



interactive