move lua from packages/ to trunk in anticipation of upcoming stuff ;)
[openwrt.git] / include / download.mk
1 #
2 # Copyright (C) 2007 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)
9
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 ) \
24 )
25 endef
26
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
34
35 define DownloadMethod/unknown
36 @echo "ERROR: No download method available"; false
37 endef
38
39 define DownloadMethod/default
40 $(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(FILE)" "$(MD5SUM)" $(URL)
41 endef
42
43 define wrap_mirror
44 @$(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(FILE)" "x" || ( $(1) )
45 endef
46
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)/; \
59 )
60 endef
61
62
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)/; \
75 )
76 endef
77
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)/; \
91 )
92 endef
93
94 Validate/cvs=VERSION SUBDIR
95 Validate/svn=VERSION SUBDIR
96 Validate/git=VERSION SUBDIR
97
98 define Download/Defaults
99 URL:=
100 FILE:=
101 PROTO:=
102 MD5SUM:=
103 SUBDIR:=
104 VERSION:=
105 endef
106
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
114 )
115
116 $(if $(DOWNLOAD_RDEP),$(DOWNLOAD_RDEP): $(DL_DIR)/$(FILE))
117 download: $(DL_DIR)/$(FILE)
118
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))
122
123 endef
This page took 0.044827 seconds and 5 git commands to generate.