3c7cb7e77b96d4b4cee813ea8e6ae3ade877ab90
[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 unknown \
18 ) \
19 ) \
20 ) \
21 ) \
22 )
23 endef
24
25 # code for creating tarballs from svn/git checkouts - useful for mirror support
26 dl_pack/bz2=$(TAR) cfj $(1) $(2)
27 dl_pack/gz=$(TAR) cfz $(1) $(2)
28 dl_pack/unknown=echo "ERROR: Unknown pack format for file $(1)"; false
29 define dl_pack
30 $(if $(dl_pack/$(call ext,$(1))),$(dl_pack/$(call ext,$(1))),$(dl_pack/unknown))
31 endef
32
33 define DownloadMethod/unknown
34 @echo "ERROR: No download method available"; false
35 endef
36
37 define DownloadMethod/default
38 $(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(FILE)" "$(MD5SUM)" $(URL)
39 endef
40
41 define wrap_mirror
42 @$(if $(CONFIG_LOCALMIRROR),$(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(FILE)" "x" || ) \
43 ( $(1) ) \
44 $(if $(CONFIG_LOCALMIRROR),, || $(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(FILE)" "x")
45 endef
46
47 define DownloadMethod/svn
48 $(call wrap_mirror, \
49 echo "Checking out files from the svn repository..."; \
50 mkdir -p $(TMP_DIR)/dl && \
51 cd $(TMP_DIR)/dl && \
52 rm -rf $(SUBDIR) && \
53 [ \! -d $(SUBDIR) ] && \
54 svn co -r$(VERSION) $(URL) $(SUBDIR) && \
55 find $(SUBDIR) -name .svn | 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 define DownloadMethod/git
63 $(call wrap_mirror, \
64 echo "Checking out files from the git repository..."; \
65 mkdir -p $(TMP_DIR)/dl && \
66 cd $(TMP_DIR)/dl && \
67 rm -rf $(SUBDIR) && \
68 [ \! -d $(SUBDIR) ] && \
69 git-clone $(URL) $(SUBDIR) && \
70 (cd $(SUBDIR) && git-checkout $(VERSION)) && \
71 echo "Packing checkout..." && \
72 rm -rf $(SUBDIR)/.git && \
73 $(call dl_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
74 mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/; \
75 )
76 endef
77
78 Validate/svn=VERSION SUBDIR
79 Validate/git=VERSION SUBDIR
80
81 define Download/Defaults
82 URL:=
83 FILE:=
84 PROTO:=
85 MD5SUM:=
86 SUBDIR:=
87 VERSION:=
88 endef
89
90 define Download
91 $(eval $(Download/Defaults))
92 $(eval $(Download/$(1)))
93 $(foreach FIELD,URL FILE $(Validate/$(call dl_method,$(URL),$(PROTO))),
94 ifeq ($($(FIELD)),)
95 $$(error Download/$(1) is missing the $(FIELD) field.)
96 endif
97 )
98
99 $(if $(DOWNLOAD_RDEP),$(DOWNLOAD_RDEP): $(DL_DIR)/$(FILE))
100 download: $(DL_DIR)/$(FILE)
101
102 $(DL_DIR)/$(FILE):
103 mkdir -p $(DL_DIR)
104 $(if $(DownloadMethod/$(call dl_method,$(URL),$(PROTO))),$(DownloadMethod/$(call dl_method,$(URL),$(PROTO))),$(DownloadMethod/unknown))
105
106 endef
This page took 0.043089 seconds and 3 git commands to generate.