download.mk 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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/% @SAVANNAH/% 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/xz=$(TAR) c $(2) | xz -zc > $(1)
  32. dl_pack/unknown=echo "ERROR: Unknown pack format for file $(1)"; false
  33. define dl_pack
  34. $(if $(dl_pack/$(call ext,$(1))),$(dl_pack/$(call ext,$(1))),$(dl_pack/unknown))
  35. endef
  36. define DownloadMethod/unknown
  37. @echo "ERROR: No download method available"; false
  38. endef
  39. define DownloadMethod/default
  40. $(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(FILE)" "$(MD5SUM)" $(foreach url,$(URL),"$(url)")
  41. endef
  42. define wrap_mirror
  43. $(if $(if $(MIRROR),$(filter-out x,$(MIRROR_MD5SUM))),@$(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(FILE)" "$(MIRROR_MD5SUM)" || ( $(1) ),$(1))
  44. endef
  45. define DownloadMethod/cvs
  46. $(call wrap_mirror, \
  47. echo "Checking out files from the cvs repository..."; \
  48. mkdir -p $(TMP_DIR)/dl && \
  49. cd $(TMP_DIR)/dl && \
  50. rm -rf $(SUBDIR) && \
  51. [ \! -d $(SUBDIR) ] && \
  52. cvs -d $(URL) export $(VERSION) $(SUBDIR) && \
  53. echo "Packing checkout..." && \
  54. $(call dl_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
  55. mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
  56. rm -rf $(SUBDIR); \
  57. )
  58. endef
  59. define DownloadMethod/svn
  60. $(call wrap_mirror, \
  61. echo "Checking out files from the svn repository..."; \
  62. mkdir -p $(TMP_DIR)/dl && \
  63. cd $(TMP_DIR)/dl && \
  64. rm -rf $(SUBDIR) && \
  65. [ \! -d $(SUBDIR) ] && \
  66. ( svn help export | grep -q trust-server-cert && \
  67. svn export --non-interactive --trust-server-cert -r$(VERSION) $(URL) $(SUBDIR) || \
  68. svn export --non-interactive -r$(VERSION) $(URL) $(SUBDIR) ) && \
  69. echo "Packing checkout..." && \
  70. $(call dl_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
  71. mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
  72. rm -rf $(SUBDIR); \
  73. )
  74. endef
  75. define DownloadMethod/git
  76. $(call wrap_mirror, \
  77. echo "Checking out files from the git repository..."; \
  78. mkdir -p $(TMP_DIR)/dl && \
  79. cd $(TMP_DIR)/dl && \
  80. rm -rf $(SUBDIR) && \
  81. [ \! -d $(SUBDIR) ] && \
  82. git clone $(URL) $(SUBDIR) --recursive && \
  83. (cd $(SUBDIR) && git checkout $(VERSION) && git submodule update) && \
  84. echo "Packing checkout..." && \
  85. rm -rf $(SUBDIR)/.git && \
  86. $(call dl_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
  87. mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
  88. rm -rf $(SUBDIR); \
  89. )
  90. endef
  91. define DownloadMethod/bzr
  92. $(call wrap_mirror, \
  93. echo "Checking out files from the bzr repository..."; \
  94. mkdir -p $(TMP_DIR)/dl && \
  95. cd $(TMP_DIR)/dl && \
  96. rm -rf $(SUBDIR) && \
  97. [ \! -d $(SUBDIR) ] && \
  98. bzr export -r$(VERSION) $(SUBDIR) $(URL) && \
  99. echo "Packing checkout..." && \
  100. $(call dl_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
  101. mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
  102. rm -rf $(SUBDIR); \
  103. )
  104. endef
  105. define DownloadMethod/hg
  106. $(call wrap_mirror, \
  107. echo "Checking out files from the hg repository..."; \
  108. mkdir -p $(TMP_DIR)/dl && \
  109. cd $(TMP_DIR)/dl && \
  110. rm -rf $(SUBDIR) && \
  111. [ \! -d $(SUBDIR) ] && \
  112. hg clone -r $(VERSION) $(URL) $(SUBDIR) && \
  113. find $(SUBDIR) -name .hg | xargs rm -rf && \
  114. echo "Packing checkout..." && \
  115. $(call dl_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
  116. mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
  117. rm -rf $(SUBDIR); \
  118. )
  119. endef
  120. define DownloadMethod/darcs
  121. $(call wrap_mirror, \
  122. echo "Checking out files from the darcs repository..."; \
  123. mkdir -p $(TMP_DIR)/dl && \
  124. cd $(TMP_DIR)/dl && \
  125. rm -rf $(SUBDIR) && \
  126. [ \! -d $(SUBDIR) ] && \
  127. darcs get -t $(VERSION) $(URL) $(SUBDIR) && \
  128. find $(SUBDIR) -name _darcs | xargs rm -rf && \
  129. echo "Packing checkout..." && \
  130. $(call dl_pack,$(TMP_DIR)/dl/$(FILE),$(SUBDIR)) && \
  131. mv $(TMP_DIR)/dl/$(FILE) $(DL_DIR)/ && \
  132. rm -rf $(SUBDIR); \
  133. )
  134. endef
  135. Validate/cvs=VERSION SUBDIR
  136. Validate/svn=VERSION SUBDIR
  137. Validate/git=VERSION SUBDIR
  138. Validate/bzr=VERSION SUBDIR
  139. Validate/hg=VERSION SUBDIR
  140. Validate/darcs=VERSION SUBDIR
  141. define Download/Defaults
  142. URL:=
  143. FILE:=
  144. PROTO:=
  145. MD5SUM:=
  146. SUBDIR:=
  147. MIRROR:=1
  148. MIRROR_MD5SUM:=x
  149. VERSION:=
  150. endef
  151. define Download
  152. $(eval $(Download/Defaults))
  153. $(eval $(Download/$(1)))
  154. $(foreach FIELD,URL FILE $(Validate/$(call dl_method,$(URL),$(PROTO))),
  155. ifeq ($($(FIELD)),)
  156. $$(error Download/$(1) is missing the $(FIELD) field.)
  157. endif
  158. )
  159. $(foreach dep,$(DOWNLOAD_RDEP),
  160. $(dep): $(DL_DIR)/$(FILE)
  161. )
  162. download: $(DL_DIR)/$(FILE)
  163. $(DL_DIR)/$(FILE):
  164. mkdir -p $(DL_DIR)
  165. $(if $(DownloadMethod/$(call dl_method,$(URL),$(PROTO))),$(DownloadMethod/$(call dl_method,$(URL),$(PROTO))),$(DownloadMethod/unknown))
  166. endef