pkg-download.mk 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. ################################################################################
  2. #
  3. # This file contains the download helpers for the various package
  4. # infrastructures. It is used to handle downloads from HTTP servers,
  5. # FTP servers, Git repositories, Subversion repositories, Mercurial
  6. # repositories, Bazaar repositories, and SCP servers.
  7. #
  8. ################################################################################
  9. # Download method commands
  10. export WGET := $(call qstrip,$(BR2_WGET))
  11. export SVN := $(call qstrip,$(BR2_SVN))
  12. export CVS := $(call qstrip,$(BR2_CVS))
  13. export BZR := $(call qstrip,$(BR2_BZR))
  14. export GIT := $(call qstrip,$(BR2_GIT))
  15. export HG := $(call qstrip,$(BR2_HG))
  16. export SCP := $(call qstrip,$(BR2_SCP))
  17. export LOCALFILES := $(call qstrip,$(BR2_LOCALFILES))
  18. DL_WRAPPER = support/download/dl-wrapper
  19. FLOCK = flock $($(PKG)_DL_DIR)/
  20. # DL_DIR may have been set already from the environment
  21. ifeq ($(origin DL_DIR),undefined)
  22. DL_DIR ?= $(call qstrip,$(BR2_DL_DIR))
  23. ifeq ($(DL_DIR),)
  24. DL_DIR := $(TOPDIR)/dl
  25. endif
  26. else
  27. # Restore the BR2_DL_DIR that was overridden by the .config file
  28. BR2_DL_DIR = $(DL_DIR)
  29. endif
  30. # ensure it exists and a absolute path
  31. DL_DIR := $(shell mkdir -p $(DL_DIR) && cd $(DL_DIR) >/dev/null && pwd)
  32. #
  33. # URI scheme helper functions
  34. # Example URIs:
  35. # * http://www.example.com/dir/file
  36. # * scp://www.example.com:dir/file (with domainseparator :)
  37. #
  38. # geturischeme: http
  39. geturischeme = $(firstword $(subst ://, ,$(call qstrip,$(1))))
  40. # getschemeplusuri: git|parameter+http://example.com
  41. getschemeplusuri = $(call geturischeme,$(1))$(if $(2),\|$(2))+$(1)
  42. # stripurischeme: www.example.com/dir/file
  43. stripurischeme = $(lastword $(subst ://, ,$(call qstrip,$(1))))
  44. # domain: www.example.com
  45. domain = $(firstword $(subst $(call domainseparator,$(2)), ,$(call stripurischeme,$(1))))
  46. # notdomain: dir/file
  47. notdomain = $(patsubst $(call domain,$(1),$(2))$(call domainseparator,$(2))%,%,$(call stripurischeme,$(1)))
  48. #
  49. # default domainseparator is /, specify alternative value as first argument
  50. domainseparator = $(if $(1),$(1),/)
  51. # github(user,package,version): returns site of GitHub repository
  52. github = https://github.com/$(1)/$(2)/archive/$(3)
  53. # Expressly do not check hashes for those files
  54. # Exported variables default to immediately expanded in some versions of
  55. # make, but we need it to be recursively-epxanded, so explicitly assign it.
  56. export BR_NO_CHECK_HASH_FOR =
  57. ################################################################################
  58. # DOWNLOAD -- Download helper. Will call DL_WRAPPER which will try to download
  59. # source from:
  60. # 1) BR2_PRIMARY_SITE if enabled
  61. # 2) Download site, unless BR2_PRIMARY_SITE_ONLY is set
  62. # 3) BR2_BACKUP_SITE if enabled, unless BR2_PRIMARY_SITE_ONLY is set
  63. #
  64. # Argument 1 is the source location
  65. #
  66. ################################################################################
  67. ifneq ($(call qstrip,$(BR2_PRIMARY_SITE)),)
  68. DOWNLOAD_URIS += \
  69. -u $(call getschemeplusuri,$(call qstrip,$(BR2_PRIMARY_SITE)/$($(PKG)_DL_SUBDIR)),urlencode) \
  70. -u $(call getschemeplusuri,$(call qstrip,$(BR2_PRIMARY_SITE)),urlencode)
  71. endif
  72. ifeq ($(BR2_PRIMARY_SITE_ONLY),)
  73. DOWNLOAD_URIS += \
  74. -u $(patsubst %/,%,$(dir $(call qstrip,$(1))))
  75. ifneq ($(call qstrip,$(BR2_BACKUP_SITE)),)
  76. DOWNLOAD_URIS += \
  77. -u $(call getschemeplusuri,$(call qstrip,$(BR2_BACKUP_SITE)/$($(PKG)_DL_SUBDIR)),urlencode) \
  78. -u $(call getschemeplusuri,$(call qstrip,$(BR2_BACKUP_SITE)),urlencode)
  79. endif
  80. endif
  81. define DOWNLOAD
  82. $(Q)mkdir -p $($(PKG)_DL_DIR)
  83. $(Q)$(EXTRA_ENV) $(FLOCK) $(DL_WRAPPER) \
  84. -c '$($(PKG)_DL_VERSION)' \
  85. -d '$($(PKG)_DL_DIR)' \
  86. -D '$(DL_DIR)' \
  87. -f '$(notdir $(1))' \
  88. -H '$($(PKG)_HASH_FILE)' \
  89. -n '$($(PKG)_BASENAME_RAW)' \
  90. -N '$($(PKG)_RAWNAME)' \
  91. -o '$($(PKG)_DL_DIR)/$(notdir $(1))' \
  92. $(if $($(PKG)_GIT_SUBMODULES),-r) \
  93. $(DOWNLOAD_URIS) \
  94. $(QUIET) \
  95. -- \
  96. $($(PKG)_DL_OPTS)
  97. endef