pkg-download.mk 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 SFTP := $(call qstrip,$(BR2_SFTP))
  18. export LOCALFILES := $(call qstrip,$(BR2_LOCALFILES))
  19. # Version of the format of the archives we generate in the corresponding
  20. # download backend:
  21. BR_FMT_VERSION_git = -br1
  22. BR_FMT_VERSION_svn = -br3
  23. DL_WRAPPER = support/download/dl-wrapper
  24. # DL_DIR may have been set already from the environment
  25. ifeq ($(origin DL_DIR),undefined)
  26. DL_DIR ?= $(call qstrip,$(BR2_DL_DIR))
  27. ifeq ($(DL_DIR),)
  28. DL_DIR := $(TOPDIR)/dl
  29. endif
  30. else
  31. # Restore the BR2_DL_DIR that was overridden by the .config file
  32. BR2_DL_DIR = $(DL_DIR)
  33. endif
  34. # ensure it exists and a absolute path, derefrecing symlinks
  35. DL_DIR := $(shell mkdir -p $(DL_DIR) && cd $(DL_DIR) >/dev/null && pwd -P)
  36. #
  37. # URI scheme helper functions
  38. # Example URIs:
  39. # * http://www.example.com/dir/file
  40. # * scp://www.example.com:dir/file (with domainseparator :)
  41. #
  42. # geturischeme: http
  43. geturischeme = $(firstword $(subst ://, ,$(call qstrip,$(1))))
  44. # getschemeplusuri: git|parameter+http://example.com
  45. getschemeplusuri = $(call geturischeme,$(1))$(if $(2),\|$(2))+$(1)
  46. # stripurischeme: www.example.com/dir/file
  47. stripurischeme = $(lastword $(subst ://, ,$(call qstrip,$(1))))
  48. # domain: www.example.com
  49. domain = $(firstword $(subst $(call domainseparator,$(2)), ,$(call stripurischeme,$(1))))
  50. # notdomain: dir/file
  51. notdomain = $(patsubst $(call domain,$(1),$(2))$(call domainseparator,$(2))%,%,$(call stripurischeme,$(1)))
  52. #
  53. # default domainseparator is /, specify alternative value as first argument
  54. domainseparator = $(if $(1),$(1),/)
  55. # github(user,package,version): returns site of GitHub repository
  56. github = https://github.com/$(1)/$(2)/archive/$(3)
  57. # gitlab(user,package,version): returns site of Gitlab-generated tarball
  58. gitlab = https://gitlab.com/$(1)/$(2)/-/archive/$(3)
  59. # Expressly do not check hashes for those files
  60. BR_NO_CHECK_HASH_FOR =
  61. ################################################################################
  62. # DOWNLOAD_URIS - List the candidates URIs where to get the package from:
  63. # 1) BR2_PRIMARY_SITE if enabled
  64. # 2) Download site, unless BR2_PRIMARY_SITE_ONLY is set
  65. # 3) BR2_BACKUP_SITE if enabled, unless BR2_PRIMARY_SITE_ONLY is set
  66. #
  67. # Argument 1 is the source location
  68. # Argument 2 is the upper-case package name
  69. #
  70. ################################################################################
  71. ifneq ($(call qstrip,$(BR2_PRIMARY_SITE)),)
  72. DOWNLOAD_URIS += \
  73. $(call getschemeplusuri,$(call qstrip,$(BR2_PRIMARY_SITE)/$($(2)_DL_SUBDIR)),urlencode) \
  74. $(call getschemeplusuri,$(call qstrip,$(BR2_PRIMARY_SITE)),urlencode)
  75. endif
  76. ifeq ($(BR2_PRIMARY_SITE_ONLY),)
  77. DOWNLOAD_URIS += \
  78. $(patsubst %/,%,$(dir $(call qstrip,$(1))))
  79. ifneq ($(call qstrip,$(BR2_BACKUP_SITE)),)
  80. DOWNLOAD_URIS += \
  81. $(call getschemeplusuri,$(call qstrip,$(BR2_BACKUP_SITE)/$($(2)_DL_SUBDIR)),urlencode) \
  82. $(call getschemeplusuri,$(call qstrip,$(BR2_BACKUP_SITE)),urlencode)
  83. endif
  84. endif
  85. ################################################################################
  86. # DOWNLOAD -- Download helper. Will call DL_WRAPPER which will try to download
  87. # source from the list returned by DOWNLOAD_URIS.
  88. #
  89. # Argument 1 is the source location
  90. # Argument 2 is the upper-case package name
  91. # Argument 3 is a space-separated list of optional arguments
  92. #
  93. ################################################################################
  94. define DOWNLOAD
  95. $(Q)mkdir -p $($(2)_DL_DIR)
  96. $(Q)$(EXTRA_ENV) \
  97. $($(2)_DL_ENV) \
  98. TAR="$(TAR)" \
  99. BR_NO_CHECK_HASH_FOR="$(if $(BR2_DOWNLOAD_FORCE_CHECK_HASHES),,$(BR_NO_CHECK_HASH_FOR))" \
  100. flock $($(2)_DL_DIR)/.lock $(DL_WRAPPER) \
  101. -c '$($(2)_DL_VERSION)' \
  102. -d '$($(2)_DL_DIR)' \
  103. -D '$(DL_DIR)' \
  104. -f '$(notdir $(1))' \
  105. $(foreach f,$($(2)_HASH_FILES),-H '$(f)') \
  106. -n '$($(2)_DL_SUBDIR)-$($(2)_VERSION)' \
  107. -N '$($(2)_RAWNAME)' \
  108. -o '$($(2)_DL_DIR)/$(notdir $(1))' \
  109. $(if $(filter YES,$($(2)_SVN_EXTERNALS)),-r) \
  110. $(if $($(2)_GIT_SUBMODULES),-r) \
  111. $(if $($(2)_GIT_LFS),-l) \
  112. $(foreach uri,$(call DOWNLOAD_URIS,$(1),$(2)),-u $(uri)) \
  113. $(3) \
  114. $(QUIET) \
  115. -- \
  116. $($(2)_DL_OPTS)
  117. endef