pkg-download.mk 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. SSH := $(call qstrip,$(BR2_SSH))
  18. export LOCALFILES := $(call qstrip,$(BR2_LOCALFILES))
  19. DL_WRAPPER = support/download/dl-wrapper
  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,$(BR2_PRIMARY_SITE),urlencode)
  70. endif
  71. ifeq ($(BR2_PRIMARY_SITE_ONLY),)
  72. DOWNLOAD_URIS += \
  73. -u $($(PKG)_SITE_METHOD)+$(dir $(1))
  74. ifneq ($(call qstrip,$(BR2_BACKUP_SITE)),)
  75. DOWNLOAD_URIS += \
  76. -u $(call getschemeplusuri,$(BR2_BACKUP_SITE),urlencode)
  77. endif
  78. endif
  79. define DOWNLOAD
  80. $(Q)$(if $(filter bzr cvs hg svn,$($(PKG)_SITE_METHOD)),BR_NO_CHECK_HASH_FOR=$(notdir $(1))) \
  81. $(EXTRA_ENV) $(DL_WRAPPER) \
  82. -c $($(PKG)_DL_VERSION) \
  83. -f $(notdir $(1)) \
  84. -H $(PKGDIR)/$($(PKG)_RAWNAME).hash \
  85. -n $($(PKG)_BASENAME_RAW) \
  86. -N $($(PKG)_RAWNAME) \
  87. -o $(DL_DIR)/$(notdir $(1)) \
  88. $(if $($(PKG)_GIT_SUBMODULES),-r) \
  89. $(DOWNLOAD_URIS) \
  90. $(QUIET) \
  91. -- \
  92. $($(PKG)_DL_OPTS)
  93. endef