PageRenderTime 27ms CodeModel.GetById 37ms RepoModel.GetById 1ms app.codeStats 0ms

/package/pkg-download.mk

https://gitlab.com/cronmod-dev/buildroot
Makefile | 129 lines | 64 code | 14 blank | 51 comment | 2 complexity | ac3712768534150e45ba47b920da9edb MD5 | raw file
  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 = -br2
  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. # Exported variables default to immediately expanded in some versions of
  61. # make, but we need it to be recursively-epxanded, so explicitly assign it.
  62. export BR_NO_CHECK_HASH_FOR =
  63. ################################################################################
  64. # DOWNLOAD_URIS - List the candidates URIs where to get the package from:
  65. # 1) BR2_PRIMARY_SITE if enabled
  66. # 2) Download site, unless BR2_PRIMARY_SITE_ONLY is set
  67. # 3) BR2_BACKUP_SITE if enabled, unless BR2_PRIMARY_SITE_ONLY is set
  68. #
  69. # Argument 1 is the source location
  70. # Argument 2 is the upper-case package name
  71. #
  72. ################################################################################
  73. ifneq ($(call qstrip,$(BR2_PRIMARY_SITE)),)
  74. DOWNLOAD_URIS += \
  75. $(call getschemeplusuri,$(call qstrip,$(BR2_PRIMARY_SITE)/$($(2)_DL_SUBDIR)),urlencode) \
  76. $(call getschemeplusuri,$(call qstrip,$(BR2_PRIMARY_SITE)),urlencode)
  77. endif
  78. ifeq ($(BR2_PRIMARY_SITE_ONLY),)
  79. DOWNLOAD_URIS += \
  80. $(patsubst %/,%,$(dir $(call qstrip,$(1))))
  81. ifneq ($(call qstrip,$(BR2_BACKUP_SITE)),)
  82. DOWNLOAD_URIS += \
  83. $(call getschemeplusuri,$(call qstrip,$(BR2_BACKUP_SITE)/$($(2)_DL_SUBDIR)),urlencode) \
  84. $(call getschemeplusuri,$(call qstrip,$(BR2_BACKUP_SITE)),urlencode)
  85. endif
  86. endif
  87. ################################################################################
  88. # DOWNLOAD -- Download helper. Will call DL_WRAPPER which will try to download
  89. # source from the list returned by DOWNLOAD_URIS.
  90. #
  91. # Argument 1 is the source location
  92. # Argument 2 is the upper-case package name
  93. # Argument 3 is a space-separated list of optional arguments
  94. #
  95. ################################################################################
  96. define DOWNLOAD
  97. $(Q)mkdir -p $($(2)_DL_DIR)
  98. $(Q)$(EXTRA_ENV) $($(2)_DL_ENV) \
  99. flock $($(2)_DL_DIR)/.lock $(DL_WRAPPER) \
  100. -c '$($(2)_DL_VERSION)' \
  101. -d '$($(2)_DL_DIR)' \
  102. -D '$(DL_DIR)' \
  103. -f '$(notdir $(1))' \
  104. -H '$($(2)_HASH_FILE)' \
  105. -n '$($(2)_BASENAME_RAW)' \
  106. -N '$($(2)_RAWNAME)' \
  107. -o '$($(2)_DL_DIR)/$(notdir $(1))' \
  108. $(if $($(2)_GIT_SUBMODULES),-r) \
  109. $(if $($(2)_GIT_LFS),-l) \
  110. $(foreach uri,$(call DOWNLOAD_URIS,$(1),$(2)),-u $(uri)) \
  111. $(3) \
  112. $(QUIET) \
  113. -- \
  114. $($(2)_DL_OPTS)
  115. endef