Alexandre Belloni | 8dfd59d | 2013-06-05 23:53:30 +0000 | [diff] [blame] | 1 | ################################################################################ |
Thomas Petazzoni | c0e6b52 | 2012-04-17 16:45:20 +0200 | [diff] [blame] | 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 | # |
Alexandre Belloni | 8dfd59d | 2013-06-05 23:53:30 +0000 | [diff] [blame] | 8 | ################################################################################ |
Thomas Petazzoni | c0e6b52 | 2012-04-17 16:45:20 +0200 | [diff] [blame] | 9 | |
Thomas Petazzoni | 6e6b99a | 2012-04-17 16:45:19 +0200 | [diff] [blame] | 10 | # Download method commands |
Yann E. MORIN | afece24 | 2024-06-02 20:23:07 +0200 | [diff] [blame] | 11 | export CURL := $(call qstrip,$(BR2_CURL)) |
Yann E. MORIN | 4dc54da | 2015-01-02 16:53:41 +0100 | [diff] [blame] | 12 | export WGET := $(call qstrip,$(BR2_WGET)) |
Yann E. MORIN | daf034f | 2014-07-02 23:11:20 +0200 | [diff] [blame] | 13 | export SVN := $(call qstrip,$(BR2_SVN)) |
Yann E. MORIN | f4526c0 | 2014-07-02 23:11:21 +0200 | [diff] [blame] | 14 | export CVS := $(call qstrip,$(BR2_CVS)) |
Yann E. MORIN | 45261f1 | 2014-07-02 23:11:24 +0200 | [diff] [blame] | 15 | export BZR := $(call qstrip,$(BR2_BZR)) |
Yann E. MORIN | 95a5722 | 2014-07-02 23:11:19 +0200 | [diff] [blame] | 16 | export GIT := $(call qstrip,$(BR2_GIT)) |
Yann E. MORIN | 4dc54da | 2015-01-02 16:53:41 +0100 | [diff] [blame] | 17 | export HG := $(call qstrip,$(BR2_HG)) |
| 18 | export SCP := $(call qstrip,$(BR2_SCP)) |
Thomas Preston | 16f660f | 2020-04-15 17:48:45 +0100 | [diff] [blame] | 19 | export SFTP := $(call qstrip,$(BR2_SFTP)) |
Yann E. MORIN | 283b8b7 | 2014-07-02 23:11:26 +0200 | [diff] [blame] | 20 | export LOCALFILES := $(call qstrip,$(BR2_LOCALFILES)) |
Thomas Petazzoni | 6e6b99a | 2012-04-17 16:45:19 +0200 | [diff] [blame] | 21 | |
Yann E. MORIN | 5b95a5d | 2019-03-25 22:48:12 +0100 | [diff] [blame] | 22 | # Version of the format of the archives we generate in the corresponding |
Yann E. MORIN | 3035fc2 | 2024-05-04 23:40:12 +0200 | [diff] [blame] | 23 | # download backend and post-process: |
Yann E. MORIN | b11956f | 2024-05-04 23:40:18 +0200 | [diff] [blame] | 24 | BR_FMT_VERSION_git = -git4 |
| 25 | BR_FMT_VERSION_svn = -svn5 |
| 26 | BR_FMT_VERSION_go = -go2 |
| 27 | BR_FMT_VERSION_cargo = -cargo2 |
Yann E. MORIN | 5b95a5d | 2019-03-25 22:48:12 +0100 | [diff] [blame] | 28 | |
Yann E. MORIN | 78b92e5 | 2014-12-11 23:52:05 +0100 | [diff] [blame] | 29 | DL_WRAPPER = support/download/dl-wrapper |
| 30 | |
Arnout Vandecappelle | 6768021 | 2014-02-04 16:18:51 +0100 | [diff] [blame] | 31 | # DL_DIR may have been set already from the environment |
Arnout Vandecappelle | af97c94 | 2014-02-10 22:48:55 +0100 | [diff] [blame] | 32 | ifeq ($(origin DL_DIR),undefined) |
Arnout Vandecappelle | 6768021 | 2014-02-04 16:18:51 +0100 | [diff] [blame] | 33 | DL_DIR ?= $(call qstrip,$(BR2_DL_DIR)) |
Thomas Petazzoni | 6e6b99a | 2012-04-17 16:45:19 +0200 | [diff] [blame] | 34 | ifeq ($(DL_DIR),) |
Jerzy Grzegorek | e0d9d33 | 2013-07-20 08:52:43 +0200 | [diff] [blame] | 35 | DL_DIR := $(TOPDIR)/dl |
Thomas Petazzoni | 6e6b99a | 2012-04-17 16:45:19 +0200 | [diff] [blame] | 36 | endif |
Arnout Vandecappelle | af97c94 | 2014-02-10 22:48:55 +0100 | [diff] [blame] | 37 | else |
| 38 | # Restore the BR2_DL_DIR that was overridden by the .config file |
| 39 | BR2_DL_DIR = $(DL_DIR) |
| 40 | endif |
Thomas Petazzoni | 6e6b99a | 2012-04-17 16:45:19 +0200 | [diff] [blame] | 41 | |
Yann E. MORIN | 632e164 | 2018-11-15 18:03:48 +0100 | [diff] [blame] | 42 | # ensure it exists and a absolute path, derefrecing symlinks |
| 43 | DL_DIR := $(shell mkdir -p $(DL_DIR) && cd $(DL_DIR) >/dev/null && pwd -P) |
Peter Korsgaard | a77ee7f | 2012-09-10 12:38:29 +0200 | [diff] [blame] | 44 | |
Thomas Petazzoni | 6e6b99a | 2012-04-17 16:45:19 +0200 | [diff] [blame] | 45 | # |
| 46 | # URI scheme helper functions |
| 47 | # Example URIs: |
| 48 | # * http://www.example.com/dir/file |
| 49 | # * scp://www.example.com:dir/file (with domainseparator :) |
| 50 | # |
| 51 | # geturischeme: http |
Thomas De Schampheleire | f268f71 | 2014-10-07 09:06:03 +0200 | [diff] [blame] | 52 | geturischeme = $(firstword $(subst ://, ,$(call qstrip,$(1)))) |
Maxime Hadjinlian | c8ef0c0 | 2018-04-02 10:14:23 +0200 | [diff] [blame] | 53 | # getschemeplusuri: git|parameter+http://example.com |
| 54 | getschemeplusuri = $(call geturischeme,$(1))$(if $(2),\|$(2))+$(1) |
Thomas Petazzoni | 6e6b99a | 2012-04-17 16:45:19 +0200 | [diff] [blame] | 55 | # stripurischeme: www.example.com/dir/file |
Thomas De Schampheleire | f268f71 | 2014-10-07 09:06:03 +0200 | [diff] [blame] | 56 | stripurischeme = $(lastword $(subst ://, ,$(call qstrip,$(1)))) |
Thomas Petazzoni | 6e6b99a | 2012-04-17 16:45:19 +0200 | [diff] [blame] | 57 | # domain: www.example.com |
Thomas De Schampheleire | f268f71 | 2014-10-07 09:06:03 +0200 | [diff] [blame] | 58 | domain = $(firstword $(subst $(call domainseparator,$(2)), ,$(call stripurischeme,$(1)))) |
Thomas Petazzoni | 6e6b99a | 2012-04-17 16:45:19 +0200 | [diff] [blame] | 59 | # notdomain: dir/file |
Thomas De Schampheleire | f268f71 | 2014-10-07 09:06:03 +0200 | [diff] [blame] | 60 | notdomain = $(patsubst $(call domain,$(1),$(2))$(call domainseparator,$(2))%,%,$(call stripurischeme,$(1))) |
Thomas Petazzoni | 6e6b99a | 2012-04-17 16:45:19 +0200 | [diff] [blame] | 61 | # |
| 62 | # default domainseparator is /, specify alternative value as first argument |
Thomas De Schampheleire | f268f71 | 2014-10-07 09:06:03 +0200 | [diff] [blame] | 63 | domainseparator = $(if $(1),$(1),/) |
Thomas Petazzoni | 6e6b99a | 2012-04-17 16:45:19 +0200 | [diff] [blame] | 64 | |
Yann E. MORIN | 2114c29 | 2017-11-13 23:00:09 +0100 | [diff] [blame] | 65 | # github(user,package,version): returns site of GitHub repository |
| 66 | github = https://github.com/$(1)/$(2)/archive/$(3) |
Mischa Jonker | bb083e9 | 2013-12-05 18:20:44 +0100 | [diff] [blame] | 67 | |
Thomas Petazzoni | f83826c | 2021-03-28 21:13:49 +0200 | [diff] [blame] | 68 | # gitlab(user,package,version): returns site of Gitlab-generated tarball |
| 69 | gitlab = https://gitlab.com/$(1)/$(2)/-/archive/$(3) |
| 70 | |
Yann E. MORIN | 8d2f4e6 | 2015-04-23 00:08:38 +0200 | [diff] [blame] | 71 | # Expressly do not check hashes for those files |
Yann E. MORIN | e091e31 | 2023-11-06 20:09:14 +0100 | [diff] [blame] | 72 | BR_NO_CHECK_HASH_FOR = |
Yann E. MORIN | 8d2f4e6 | 2015-04-23 00:08:38 +0200 | [diff] [blame] | 73 | |
Thomas Petazzoni | 6e6b99a | 2012-04-17 16:45:19 +0200 | [diff] [blame] | 74 | ################################################################################ |
Yann E. MORIN | 06426e1 | 2019-04-15 21:47:24 +0200 | [diff] [blame] | 75 | # DOWNLOAD_URIS - List the candidates URIs where to get the package from: |
Thomas Petazzoni | 6e6b99a | 2012-04-17 16:45:19 +0200 | [diff] [blame] | 76 | # 1) BR2_PRIMARY_SITE if enabled |
Thomas De Schampheleire | 5a83e08 | 2012-06-22 07:37:03 +0200 | [diff] [blame] | 77 | # 2) Download site, unless BR2_PRIMARY_SITE_ONLY is set |
| 78 | # 3) BR2_BACKUP_SITE if enabled, unless BR2_PRIMARY_SITE_ONLY is set |
Thomas Petazzoni | 6e6b99a | 2012-04-17 16:45:19 +0200 | [diff] [blame] | 79 | # |
| 80 | # Argument 1 is the source location |
Yann E. MORIN | 06426e1 | 2019-04-15 21:47:24 +0200 | [diff] [blame] | 81 | # Argument 2 is the upper-case package name |
Thomas Petazzoni | 6e6b99a | 2012-04-17 16:45:19 +0200 | [diff] [blame] | 82 | # |
Thomas Petazzoni | 6e6b99a | 2012-04-17 16:45:19 +0200 | [diff] [blame] | 83 | ################################################################################ |
| 84 | |
Maxime Hadjinlian | c8ef0c0 | 2018-04-02 10:14:23 +0200 | [diff] [blame] | 85 | ifneq ($(call qstrip,$(BR2_PRIMARY_SITE)),) |
| 86 | DOWNLOAD_URIS += \ |
Yann E. MORIN | 06426e1 | 2019-04-15 21:47:24 +0200 | [diff] [blame] | 87 | $(call getschemeplusuri,$(call qstrip,$(BR2_PRIMARY_SITE)/$($(2)_DL_SUBDIR)),urlencode) \ |
Yann E. MORIN | 813b94e | 2019-04-15 21:47:23 +0200 | [diff] [blame] | 88 | $(call getschemeplusuri,$(call qstrip,$(BR2_PRIMARY_SITE)),urlencode) |
Maxime Hadjinlian | c8ef0c0 | 2018-04-02 10:14:23 +0200 | [diff] [blame] | 89 | endif |
Thomas Petazzoni | 224a591 | 2015-04-26 11:51:04 +0200 | [diff] [blame] | 90 | |
Maxime Hadjinlian | c8ef0c0 | 2018-04-02 10:14:23 +0200 | [diff] [blame] | 91 | ifeq ($(BR2_PRIMARY_SITE_ONLY),) |
| 92 | DOWNLOAD_URIS += \ |
Yann E. MORIN | 813b94e | 2019-04-15 21:47:23 +0200 | [diff] [blame] | 93 | $(patsubst %/,%,$(dir $(call qstrip,$(1)))) |
Maxime Hadjinlian | c8ef0c0 | 2018-04-02 10:14:23 +0200 | [diff] [blame] | 94 | ifneq ($(call qstrip,$(BR2_BACKUP_SITE)),) |
| 95 | DOWNLOAD_URIS += \ |
Yann E. MORIN | 06426e1 | 2019-04-15 21:47:24 +0200 | [diff] [blame] | 96 | $(call getschemeplusuri,$(call qstrip,$(BR2_BACKUP_SITE)/$($(2)_DL_SUBDIR)),urlencode) \ |
Yann E. MORIN | 813b94e | 2019-04-15 21:47:23 +0200 | [diff] [blame] | 97 | $(call getschemeplusuri,$(call qstrip,$(BR2_BACKUP_SITE)),urlencode) |
Maxime Hadjinlian | c8ef0c0 | 2018-04-02 10:14:23 +0200 | [diff] [blame] | 98 | endif |
| 99 | endif |
| 100 | |
Yann E. MORIN | 06426e1 | 2019-04-15 21:47:24 +0200 | [diff] [blame] | 101 | ################################################################################ |
| 102 | # DOWNLOAD -- Download helper. Will call DL_WRAPPER which will try to download |
| 103 | # source from the list returned by DOWNLOAD_URIS. |
| 104 | # |
| 105 | # Argument 1 is the source location |
Yann E. MORIN | d2dd96f | 2024-06-07 19:05:42 +0200 | [diff] [blame] | 106 | # Argument 2 is a space-separated list of optional arguments |
Yann E. MORIN | 06426e1 | 2019-04-15 21:47:24 +0200 | [diff] [blame] | 107 | # |
| 108 | ################################################################################ |
| 109 | |
Luca Pesce | e996026 | 2022-12-06 11:41:23 +0100 | [diff] [blame] | 110 | # Restore the user's original umask during the whole download, in case he has |
| 111 | # provisions set to share the download directory with his group (or others). |
| 112 | ifneq ($(BR_ORIG_UMASK),) |
| 113 | DOWNLOAD_SET_UMASK = umask $(BR_ORIG_UMASK); |
| 114 | endif |
| 115 | |
Maxime Hadjinlian | c8ef0c0 | 2018-04-02 10:14:23 +0200 | [diff] [blame] | 116 | define DOWNLOAD |
Luca Pesce | e996026 | 2022-12-06 11:41:23 +0100 | [diff] [blame] | 117 | $(Q)$(DOWNLOAD_SET_UMASK) mkdir -p $($(PKG)_DL_DIR) |
| 118 | $(Q)$(DOWNLOAD_SET_UMASK) $(EXTRA_ENV) \ |
Yann E. MORIN | d2dd96f | 2024-06-07 19:05:42 +0200 | [diff] [blame] | 119 | $($(PKG)_DL_ENV) \ |
Yann E. MORIN | ce6b48c | 2024-06-05 19:53:17 +0200 | [diff] [blame] | 120 | TAR="$(TAR)" \ |
Yann E. MORIN | e091e31 | 2023-11-06 20:09:14 +0100 | [diff] [blame] | 121 | BR_NO_CHECK_HASH_FOR="$(if $(BR2_DOWNLOAD_FORCE_CHECK_HASHES),,$(BR_NO_CHECK_HASH_FOR))" \ |
Yann E. MORIN | d2dd96f | 2024-06-07 19:05:42 +0200 | [diff] [blame] | 122 | flock $($(PKG)_DL_DIR)/.lock $(DL_WRAPPER) \ |
| 123 | -c '$($(PKG)_DL_VERSION)' \ |
| 124 | -d '$($(PKG)_DL_DIR)' \ |
Yann E. MORIN | e80d1d0 | 2018-04-02 17:13:58 +0200 | [diff] [blame] | 125 | -D '$(DL_DIR)' \ |
Maxime Hadjinlian | 765e94e | 2018-04-02 15:33:53 +0200 | [diff] [blame] | 126 | -f '$(notdir $(1))' \ |
Yann E. MORIN | d2dd96f | 2024-06-07 19:05:42 +0200 | [diff] [blame] | 127 | $(foreach f,$($(PKG)_HASH_FILES),-H '$(f)') \ |
| 128 | -n '$($(PKG)_DL_SUBDIR)-$($(PKG)_VERSION)' \ |
| 129 | -N '$($(PKG)_RAWNAME)' \ |
| 130 | -o '$($(PKG)_DL_DIR)/$(notdir $(1))' \ |
| 131 | $(if $(filter YES,$($(PKG)_SVN_EXTERNALS)),-r) \ |
| 132 | $(if $($(PKG)_GIT_SUBMODULES),-r) \ |
| 133 | $(if $($(PKG)_GIT_LFS),-l) \ |
| 134 | $(foreach uri,$(call DOWNLOAD_URIS,$(1),$(PKG)),-u $(uri)) \ |
| 135 | $(2) \ |
Maxime Hadjinlian | c8ef0c0 | 2018-04-02 10:14:23 +0200 | [diff] [blame] | 136 | $(QUIET) \ |
| 137 | -- \ |
Yann E. MORIN | d2dd96f | 2024-06-07 19:05:42 +0200 | [diff] [blame] | 138 | $($(PKG)_DL_OPTS) |
Thomas Petazzoni | 6e6b99a | 2012-04-17 16:45:19 +0200 | [diff] [blame] | 139 | endef |