download.mk 5.2 KB

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