PPTPD: Fix compilation when PPTP is not included
[tomato.git] / toolchain / include / download.mk
blob0558d4979ec8a562b7f9184894d93606c31e6594
1 #
2 # Copyright (C) 2007 OpenWrt.org
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
8 DOWNLOAD_RDEP:=$(STAMP_PREPARED)
10 # Try to guess the download method from the URL
11 define dl_method
12 $(strip \
13 $(if $(2),$(2), \
14 $(if $(filter @GNU/% @KERNEL/% @SF/% ftp://% http://%,$(1)),default, \
15 $(if $(filter git://%,$(1)),git, \
16 $(if $(filter svn://%,$(1)),svn, \
17 $(if $(filter cvs://%,$(1)),cvs, \
18 unknown \
19 ) \
20 ) \
21 ) \
22 ) \
23 ) \
25 endef
27 # code for creating tarballs from cvs/svn/git checkouts - useful for mirror support
28 dl_pack/bz2=$(TAR) cfj $(1) $(2)
29 dl_pack/gz=$(TAR) cfz $(1) $(2)
30 dl_pack/unknown=echo "ERROR: Unknown pack format for file $(1)"; false
31 define dl_pack
32 $(if $(dl_pack/$(call ext,$(1))),$(dl_pack/$(call ext,$(1))),$(dl_pack/unknown))
33 endef
35 define DownloadMethod/unknown
36 @echo "ERROR: No download method available"; false
37 endef
39 define DownloadMethod/default
40 $(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(FILE)" "$(MD5SUM)" $(URL)
41 endef
43 define wrap_mirror
44 @$(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(FILE)" "x" || ( $(1) )
45 endef
47 define DownloadMethod/cvs
48 $(call wrap_mirror, \
49 echo "Checking out files from the cvs repository..."; \
50 mkdir -p $(TMP_DIR)/dl && \
51 cd $(TMP_DIR)/dl && \
52 rm -rf $(SUBDIR) && \
53 [ \! -d $(SUBDIR) ] && \
54 cvs co -r$(VERSION) $(URL) $(SUBDIR) && \
55 find $(SUBDIR) -name CVS | xargs rm -rf && \
56 echo "Packing checkout..." && \
57 $(call dl_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
58 mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/; \
60 endef
63 define DownloadMethod/svn
64 $(call wrap_mirror, \
65 echo "Checking out files from the svn repository..."; \
66 mkdir -p $(TMP_DIR)/dl && \
67 cd $(TMP_DIR)/dl && \
68 rm -rf $(SUBDIR) && \
69 [ \! -d $(SUBDIR) ] && \
70 svn co -r$(VERSION) $(URL) $(SUBDIR) && \
71 find $(SUBDIR) -name .svn | xargs rm -rf && \
72 echo "Packing checkout..." && \
73 $(call dl_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
74 mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/; \
76 endef
78 define DownloadMethod/git
79 $(call wrap_mirror, \
80 echo "Checking out files from the git repository..."; \
81 mkdir -p $(TMP_DIR)/dl && \
82 cd $(TMP_DIR)/dl && \
83 rm -rf $(SUBDIR) && \
84 [ \! -d $(SUBDIR) ] && \
85 git-clone $(URL) $(SUBDIR) && \
86 (cd $(SUBDIR) && git-checkout $(VERSION)) && \
87 echo "Packing checkout..." && \
88 rm -rf $(SUBDIR)/.git && \
89 $(call dl_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
90 mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/; \
92 endef
94 Validate/cvs=VERSION SUBDIR
95 Validate/svn=VERSION SUBDIR
96 Validate/git=VERSION SUBDIR
98 define Download/Defaults
99 URL:=
100 FILE:=
101 PROTO:=
102 MD5SUM:=
103 SUBDIR:=
104 VERSION:=
105 endef
107 define Download
108 $(eval $(Download/Defaults))
109 $(eval $(Download/$(1)))
110 $(foreach FIELD,URL FILE $(Validate/$(call dl_method,$(URL),$(PROTO))),
111 ifeq ($($(FIELD)),)
112 $$(error Download/$(1) is missing the $(FIELD) field.)
113 endif
116 $(if $(DOWNLOAD_RDEP),$(DOWNLOAD_RDEP): $(DL_DIR)/$(FILE))
117 download: $(DL_DIR)/$(FILE)
119 $(DL_DIR)/$(FILE):
120 mkdir -p $(DL_DIR)
121 $(if $(DownloadMethod/$(call dl_method,$(URL),$(PROTO))),$(DownloadMethod/$(call dl_method,$(URL),$(PROTO))),$(DownloadMethod/unknown))
123 endef