pkg-download.mk 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. # DL_DIR may have been set already from the environment
  20. ifeq ($(origin DL_DIR),undefined)
  21. DL_DIR ?= $(call qstrip,$(BR2_DL_DIR))
  22. ifeq ($(DL_DIR),)
  23. DL_DIR := $(TOPDIR)/dl
  24. endif
  25. else
  26. # Restore the BR2_DL_DIR that was overridden by the .config file
  27. BR2_DL_DIR = $(DL_DIR)
  28. endif
  29. # ensure it exists and a absolute path, derefrecing symlinks
  30. DL_DIR := $(shell mkdir -p $(DL_DIR) && cd $(DL_DIR) >/dev/null && pwd -P)
  31. #
  32. # URI scheme helper functions
  33. # Example URIs:
  34. # * http://www.example.com/dir/file
  35. # * scp://www.example.com:dir/file (with domainseparator :)
  36. #
  37. # geturischeme: http
  38. geturischeme = $(firstword $(subst ://, ,$(call qstrip,$(1))))
  39. # getschemeplusuri: git|parameter+http://example.com
  40. getschemeplusuri = $(call geturischeme,$(1))$(if $(2),\|$(2))+$(1)
  41. # stripurischeme: www.example.com/dir/file
  42. stripurischeme = $(lastword $(subst ://, ,$(call qstrip,$(1))))
  43. # domain: www.example.com
  44. domain = $(firstword $(subst $(call domainseparator,$(2)), ,$(call stripurischeme,$(1))))
  45. # notdomain: dir/file
  46. notdomain = $(patsubst $(call domain,$(1),$(2))$(call domainseparator,$(2))%,%,$(call stripurischeme,$(1)))
  47. #
  48. # default domainseparator is /, specify alternative value as first argument
  49. domainseparator = $(if $(1),$(1),/)
  50. # github(user,package,version): returns site of GitHub repository
  51. github = https://github.com/$(1)/$(2)/archive/$(3)
  52. # Expressly do not check hashes for those files
  53. # Exported variables default to immediately expanded in some versions of
  54. # make, but we need it to be recursively-epxanded, so explicitly assign it.
  55. export BR_NO_CHECK_HASH_FOR =
  56. ################################################################################
  57. # DOWNLOAD_URIS - List the candidates URIs where to get the package from:
  58. # 1) BR2_PRIMARY_SITE if enabled
  59. # 2) Download site, unless BR2_PRIMARY_SITE_ONLY is set
  60. # 3) BR2_BACKUP_SITE if enabled, unless BR2_PRIMARY_SITE_ONLY is set
  61. #
  62. # Argument 1 is the source location
  63. # Argument 2 is the upper-case package name
  64. #
  65. ################################################################################
  66. ifneq ($(call qstrip,$(BR2_PRIMARY_SITE)),)
  67. DOWNLOAD_URIS += \
  68. $(call getschemeplusuri,$(call qstrip,$(BR2_PRIMARY_SITE)/$($(2)_DL_SUBDIR)),urlencode) \
  69. $(call getschemeplusuri,$(call qstrip,$(BR2_PRIMARY_SITE)),urlencode)
  70. endif
  71. ifeq ($(BR2_PRIMARY_SITE_ONLY),)
  72. DOWNLOAD_URIS += \
  73. $(patsubst %/,%,$(dir $(call qstrip,$(1))))
  74. ifneq ($(call qstrip,$(BR2_BACKUP_SITE)),)
  75. DOWNLOAD_URIS += \
  76. $(call getschemeplusuri,$(call qstrip,$(BR2_BACKUP_SITE)/$($(2)_DL_SUBDIR)),urlencode) \
  77. $(call getschemeplusuri,$(call qstrip,$(BR2_BACKUP_SITE)),urlencode)
  78. endif
  79. endif
  80. ################################################################################
  81. # DOWNLOAD -- Download helper. Will call DL_WRAPPER which will try to download
  82. # source from the list returned by DOWNLOAD_URIS.
  83. #
  84. # Argument 1 is the source location
  85. # Argument 2 is the upper-case package name
  86. #
  87. ################################################################################
  88. define DOWNLOAD
  89. $(Q)mkdir -p $($(2)_DL_DIR)
  90. $(Q)$(EXTRA_ENV) flock $($(2)_DL_DIR)/.lock $(DL_WRAPPER) \
  91. -c '$($(2)_DL_VERSION)' \
  92. -d '$($(2)_DL_DIR)' \
  93. -D '$(DL_DIR)' \
  94. -f '$(notdir $(1))' \
  95. -H '$($(2)_HASH_FILE)' \
  96. -n '$($(2)_BASENAME_RAW)' \
  97. -N '$($(2)_RAWNAME)' \
  98. -o '$($(2)_DL_DIR)/$(notdir $(1))' \
  99. $(if $($(2)_GIT_SUBMODULES),-r) \
  100. $(foreach uri,$(call DOWNLOAD_URIS,$(1),$(2)),-u $(uri)) \
  101. $(QUIET) \
  102. -- \
  103. $($(2)_DL_OPTS)
  104. endef