download.mk 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. #
  2. # Copyright (C) 2006-2012 OpenWrt.org
  3. #
  4. # This is free software, licensed under the GNU General Public License v2.
  5. # See /LICENSE for more information.
  6. #
  7. DOWNLOAD_RDEP=$(STAMP_PREPARED) $(HOST_STAMP_PREPARED)
  8. # Try to guess the download method from the URL
  9. define dl_method
  10. $(strip \
  11. $(if $(2),$(2), \
  12. $(if $(filter @GNOME/% @GNU/% @KERNEL/% @SF/% ftp://% http://% https://% file://%,$(1)),default, \
  13. $(if $(filter git://%,$(1)),git, \
  14. $(if $(filter svn://%,$(1)),svn, \
  15. $(if $(filter cvs://%,$(1)),cvs, \
  16. $(if $(filter hg://%,$(1)),hg, \
  17. $(if $(filter sftp://%,$(1)),bzr, \
  18. unknown \
  19. ) \
  20. ) \
  21. ) \
  22. ) \
  23. ) \
  24. ) \
  25. ) \
  26. )
  27. endef
  28. # code for creating tarballs from cvs/svn/git/bzr/hg/darcs checkouts - useful for mirror support
  29. dl_pack/bz2=$(TAR) cjf $(1) $(2)
  30. dl_pack/gz=$(TAR) czf $(1) $(2)
  31. dl_pack/unknown=echo "ERROR: Unknown pack format for file $(1)"; false
  32. define dl_pack
  33. $(if $(dl_pack/$(call ext,$(1))),$(dl_pack/$(call ext,$(1))),$(dl_pack/unknown))
  34. endef
  35. define DownloadMethod/unknown
  36. @echo "ERROR: No download method available"; false
  37. endef
  38. define DownloadMethod/default
  39. $(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(FILE)" "$(MD5SUM)" $(foreach url,$(URL),"$(url)")
  40. endef
  41. define wrap_mirror
  42. $(if $(if $(MIRROR),$(filter-out x,$(MIRROR_MD5SUM))),@$(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(FILE)" "$(MIRROR_MD5SUM)" || ( $(1) ),$(1))
  43. endef
  44. define DownloadMethod/cvs
  45. $(call wrap_mirror, \
  46. echo "Checking out files from the cvs repository..."; \
  47. mkdir -p $(TMP_DIR)/dl && \
  48. cd $(TMP_DIR)/dl && \
  49. rm -rf $(SUBDIR) && \
  50. [ \! -d $(SUBDIR) ] && \
  51. cvs -d $(URL) export $(VERSION) $(SUBDIR) && \
  52. echo "Packing checkout..." && \
  53. $(call dl_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
  54. mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
  55. rm -rf $(SUBDIR); \
  56. )
  57. endef
  58. define DownloadMethod/svn
  59. $(call wrap_mirror, \
  60. echo "Checking out files from the svn repository..."; \
  61. mkdir -p $(TMP_DIR)/dl && \
  62. cd $(TMP_DIR)/dl && \
  63. rm -rf $(SUBDIR) && \
  64. [ \! -d $(SUBDIR) ] && \
  65. ( svn help export | grep -q trust-server-cert && \
  66. svn export --non-interactive --trust-server-cert -r$(VERSION) $(URL) $(SUBDIR) || \
  67. svn export --non-interactive -r$(VERSION) $(URL) $(SUBDIR) ) && \
  68. echo "Packing checkout..." && \
  69. $(call dl_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
  70. mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
  71. rm -rf $(SUBDIR); \
  72. )
  73. endef
  74. define DownloadMethod/git
  75. $(call wrap_mirror, \
  76. echo "Checking out files from the git repository..."; \
  77. mkdir -p $(TMP_DIR)/dl && \
  78. cd $(TMP_DIR)/dl && \
  79. rm -rf $(SUBDIR) && \
  80. [ \! -d $(SUBDIR) ] && \
  81. git clone $(URL) $(SUBDIR) --recursive && \
  82. (cd $(SUBDIR) && git checkout $(VERSION) && git submodule update) && \
  83. echo "Packing checkout..." && \
  84. rm -rf $(SUBDIR)/.git && \
  85. $(call dl_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
  86. mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
  87. rm -rf $(SUBDIR); \
  88. )
  89. endef
  90. define DownloadMethod/bzr
  91. $(call wrap_mirror, \
  92. echo "Checking out files from the bzr repository..."; \
  93. mkdir -p $(TMP_DIR)/dl && \
  94. cd $(TMP_DIR)/dl && \
  95. rm -rf $(SUBDIR) && \
  96. [ \! -d $(SUBDIR) ] && \
  97. bzr export -r$(VERSION) $(SUBDIR) $(URL) && \
  98. echo "Packing checkout..." && \
  99. $(call dl_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
  100. mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
  101. rm -rf $(SUBDIR); \
  102. )
  103. endef
  104. define DownloadMethod/hg
  105. $(call wrap_mirror, \
  106. echo "Checking out files from the hg repository..."; \
  107. mkdir -p $(TMP_DIR)/dl && \
  108. cd $(TMP_DIR)/dl && \
  109. rm -rf $(SUBDIR) && \
  110. [ \! -d $(SUBDIR) ] && \
  111. hg clone -r $(VERSION) $(URL) $(SUBDIR) && \
  112. find $(SUBDIR) -name .hg | xargs rm -rf && \
  113. echo "Packing checkout..." && \
  114. $(call dl_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
  115. mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
  116. rm -rf $(SUBDIR); \
  117. )
  118. endef
  119. define DownloadMethod/darcs
  120. $(call wrap_mirror, \
  121. echo "Checking out files from the darcs repository..."; \
  122. mkdir -p $(TMP_DIR)/dl && \
  123. cd $(TMP_DIR)/dl && \
  124. rm -rf $(SUBDIR) && \
  125. [ \! -d $(SUBDIR) ] && \
  126. darcs get -t $(VERSION) $(URL) $(SUBDIR) && \
  127. find $(SUBDIR) -name _darcs | xargs rm -rf && \
  128. echo "Packing checkout..." && \
  129. $(call dl_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
  130. mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
  131. rm -rf $(SUBDIR); \
  132. )
  133. endef
  134. Validate/cvs=VERSION SUBDIR
  135. Validate/svn=VERSION SUBDIR
  136. Validate/git=VERSION SUBDIR
  137. Validate/bzr=VERSION SUBDIR
  138. Validate/hg=VERSION SUBDIR
  139. Validate/darcs=VERSION SUBDIR
  140. define Download/Defaults
  141. URL:=
  142. FILE:=
  143. PROTO:=
  144. MD5SUM:=
  145. SUBDIR:=
  146. MIRROR:=1
  147. MIRROR_MD5SUM:=x
  148. VERSION:=
  149. endef
  150. define Download
  151. $(eval $(Download/Defaults))
  152. $(eval $(Download/$(1)))
  153. $(foreach FIELD,URL FILE $(Validate/$(call dl_method,$(URL),$(PROTO))),
  154. ifeq ($($(FIELD)),)
  155. $$(error Download/$(1) is missing the $(FIELD) field.)
  156. endif
  157. )
  158. $(foreach dep,$(DOWNLOAD_RDEP),
  159. $(dep): $(DL_DIR)/$(FILE)
  160. )
  161. download: $(DL_DIR)/$(FILE)
  162. $(DL_DIR)/$(FILE):
  163. mkdir -p $(DL_DIR)
  164. $(if $(DownloadMethod/$(call dl_method,$(URL),$(PROTO))),$(DownloadMethod/$(call dl_method,$(URL),$(PROTO))),$(DownloadMethod/unknown))
  165. endef