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://% 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 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)" $(URL)
45endef
46
47define wrap_mirror
48    $(if $(MIRROR),@$(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(FILE)" "x" || ( $(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
131Validate/cvs=VERSION SUBDIR
132Validate/svn=VERSION SUBDIR
133Validate/git=VERSION SUBDIR
134Validate/bzr=VERSION SUBDIR
135Validate/hg=VERSION SUBDIR
136
137define Download/Defaults
138  URL:=
139  FILE:=
140  PROTO:=
141  MD5SUM:=
142  SUBDIR:=
143  MIRROR:=1
144  VERSION:=
145endef
146
147define 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
165endef
166

Archive Download this file



interactive