blob: ca01ff67a59eb9ee7644b33ab2804e94115df988 [file] [log] [blame]
Alexandre Belloni8dfd59d2013-06-05 23:53:30 +00001################################################################################
Thomas Petazzonic0e6b522012-04-17 16:45:20 +02002#
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 Belloni8dfd59d2013-06-05 23:53:30 +00008################################################################################
Thomas Petazzonic0e6b522012-04-17 16:45:20 +02009
Thomas Petazzoni6e6b99a2012-04-17 16:45:19 +020010# Download method commands
Yann E. MORINafece242024-06-02 20:23:07 +020011export CURL := $(call qstrip,$(BR2_CURL))
Yann E. MORIN4dc54da2015-01-02 16:53:41 +010012export WGET := $(call qstrip,$(BR2_WGET))
Yann E. MORINdaf034f2014-07-02 23:11:20 +020013export SVN := $(call qstrip,$(BR2_SVN))
Yann E. MORINf4526c02014-07-02 23:11:21 +020014export CVS := $(call qstrip,$(BR2_CVS))
Yann E. MORIN45261f12014-07-02 23:11:24 +020015export BZR := $(call qstrip,$(BR2_BZR))
Yann E. MORIN95a57222014-07-02 23:11:19 +020016export GIT := $(call qstrip,$(BR2_GIT))
Yann E. MORIN4dc54da2015-01-02 16:53:41 +010017export HG := $(call qstrip,$(BR2_HG))
18export SCP := $(call qstrip,$(BR2_SCP))
Thomas Preston16f660f2020-04-15 17:48:45 +010019export SFTP := $(call qstrip,$(BR2_SFTP))
Yann E. MORIN283b8b72014-07-02 23:11:26 +020020export LOCALFILES := $(call qstrip,$(BR2_LOCALFILES))
Thomas Petazzoni6e6b99a2012-04-17 16:45:19 +020021
Yann E. MORIN5b95a5d2019-03-25 22:48:12 +010022# Version of the format of the archives we generate in the corresponding
Yann E. MORIN3035fc22024-05-04 23:40:12 +020023# download backend and post-process:
Yann E. MORINb11956f2024-05-04 23:40:18 +020024BR_FMT_VERSION_git = -git4
25BR_FMT_VERSION_svn = -svn5
26BR_FMT_VERSION_go = -go2
27BR_FMT_VERSION_cargo = -cargo2
Yann E. MORIN5b95a5d2019-03-25 22:48:12 +010028
Yann E. MORIN78b92e52014-12-11 23:52:05 +010029DL_WRAPPER = support/download/dl-wrapper
30
Arnout Vandecappelle67680212014-02-04 16:18:51 +010031# DL_DIR may have been set already from the environment
Arnout Vandecappelleaf97c942014-02-10 22:48:55 +010032ifeq ($(origin DL_DIR),undefined)
Arnout Vandecappelle67680212014-02-04 16:18:51 +010033DL_DIR ?= $(call qstrip,$(BR2_DL_DIR))
Thomas Petazzoni6e6b99a2012-04-17 16:45:19 +020034ifeq ($(DL_DIR),)
Jerzy Grzegoreke0d9d332013-07-20 08:52:43 +020035DL_DIR := $(TOPDIR)/dl
Thomas Petazzoni6e6b99a2012-04-17 16:45:19 +020036endif
Arnout Vandecappelleaf97c942014-02-10 22:48:55 +010037else
38# Restore the BR2_DL_DIR that was overridden by the .config file
39BR2_DL_DIR = $(DL_DIR)
40endif
Thomas Petazzoni6e6b99a2012-04-17 16:45:19 +020041
Yann E. MORIN632e1642018-11-15 18:03:48 +010042# ensure it exists and a absolute path, derefrecing symlinks
43DL_DIR := $(shell mkdir -p $(DL_DIR) && cd $(DL_DIR) >/dev/null && pwd -P)
Peter Korsgaarda77ee7f2012-09-10 12:38:29 +020044
Thomas Petazzoni6e6b99a2012-04-17 16:45:19 +020045#
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 Schampheleiref268f712014-10-07 09:06:03 +020052geturischeme = $(firstword $(subst ://, ,$(call qstrip,$(1))))
Maxime Hadjinlianc8ef0c02018-04-02 10:14:23 +020053# getschemeplusuri: git|parameter+http://example.com
54getschemeplusuri = $(call geturischeme,$(1))$(if $(2),\|$(2))+$(1)
Thomas Petazzoni6e6b99a2012-04-17 16:45:19 +020055# stripurischeme: www.example.com/dir/file
Thomas De Schampheleiref268f712014-10-07 09:06:03 +020056stripurischeme = $(lastword $(subst ://, ,$(call qstrip,$(1))))
Thomas Petazzoni6e6b99a2012-04-17 16:45:19 +020057# domain: www.example.com
Thomas De Schampheleiref268f712014-10-07 09:06:03 +020058domain = $(firstword $(subst $(call domainseparator,$(2)), ,$(call stripurischeme,$(1))))
Thomas Petazzoni6e6b99a2012-04-17 16:45:19 +020059# notdomain: dir/file
Thomas De Schampheleiref268f712014-10-07 09:06:03 +020060notdomain = $(patsubst $(call domain,$(1),$(2))$(call domainseparator,$(2))%,%,$(call stripurischeme,$(1)))
Thomas Petazzoni6e6b99a2012-04-17 16:45:19 +020061#
62# default domainseparator is /, specify alternative value as first argument
Thomas De Schampheleiref268f712014-10-07 09:06:03 +020063domainseparator = $(if $(1),$(1),/)
Thomas Petazzoni6e6b99a2012-04-17 16:45:19 +020064
Yann E. MORIN2114c292017-11-13 23:00:09 +010065# github(user,package,version): returns site of GitHub repository
66github = https://github.com/$(1)/$(2)/archive/$(3)
Mischa Jonkerbb083e92013-12-05 18:20:44 +010067
Thomas Petazzonif83826c2021-03-28 21:13:49 +020068# gitlab(user,package,version): returns site of Gitlab-generated tarball
69gitlab = https://gitlab.com/$(1)/$(2)/-/archive/$(3)
70
Yann E. MORIN8d2f4e62015-04-23 00:08:38 +020071# Expressly do not check hashes for those files
Yann E. MORINe091e312023-11-06 20:09:14 +010072BR_NO_CHECK_HASH_FOR =
Yann E. MORIN8d2f4e62015-04-23 00:08:38 +020073
Thomas Petazzoni6e6b99a2012-04-17 16:45:19 +020074################################################################################
Yann E. MORIN06426e12019-04-15 21:47:24 +020075# DOWNLOAD_URIS - List the candidates URIs where to get the package from:
Thomas Petazzoni6e6b99a2012-04-17 16:45:19 +020076# 1) BR2_PRIMARY_SITE if enabled
Thomas De Schampheleire5a83e082012-06-22 07:37:03 +020077# 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 Petazzoni6e6b99a2012-04-17 16:45:19 +020079#
80# Argument 1 is the source location
Yann E. MORIN06426e12019-04-15 21:47:24 +020081# Argument 2 is the upper-case package name
Thomas Petazzoni6e6b99a2012-04-17 16:45:19 +020082#
Thomas Petazzoni6e6b99a2012-04-17 16:45:19 +020083################################################################################
84
Maxime Hadjinlianc8ef0c02018-04-02 10:14:23 +020085ifneq ($(call qstrip,$(BR2_PRIMARY_SITE)),)
86DOWNLOAD_URIS += \
Yann E. MORIN06426e12019-04-15 21:47:24 +020087 $(call getschemeplusuri,$(call qstrip,$(BR2_PRIMARY_SITE)/$($(2)_DL_SUBDIR)),urlencode) \
Yann E. MORIN813b94e2019-04-15 21:47:23 +020088 $(call getschemeplusuri,$(call qstrip,$(BR2_PRIMARY_SITE)),urlencode)
Maxime Hadjinlianc8ef0c02018-04-02 10:14:23 +020089endif
Thomas Petazzoni224a5912015-04-26 11:51:04 +020090
Maxime Hadjinlianc8ef0c02018-04-02 10:14:23 +020091ifeq ($(BR2_PRIMARY_SITE_ONLY),)
92DOWNLOAD_URIS += \
Yann E. MORIN813b94e2019-04-15 21:47:23 +020093 $(patsubst %/,%,$(dir $(call qstrip,$(1))))
Maxime Hadjinlianc8ef0c02018-04-02 10:14:23 +020094ifneq ($(call qstrip,$(BR2_BACKUP_SITE)),)
95DOWNLOAD_URIS += \
Yann E. MORIN06426e12019-04-15 21:47:24 +020096 $(call getschemeplusuri,$(call qstrip,$(BR2_BACKUP_SITE)/$($(2)_DL_SUBDIR)),urlencode) \
Yann E. MORIN813b94e2019-04-15 21:47:23 +020097 $(call getschemeplusuri,$(call qstrip,$(BR2_BACKUP_SITE)),urlencode)
Maxime Hadjinlianc8ef0c02018-04-02 10:14:23 +020098endif
99endif
100
Yann E. MORIN06426e12019-04-15 21:47:24 +0200101################################################################################
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. MORINd2dd96f2024-06-07 19:05:42 +0200106# Argument 2 is a space-separated list of optional arguments
Yann E. MORIN06426e12019-04-15 21:47:24 +0200107#
108################################################################################
109
Luca Pescee9960262022-12-06 11:41:23 +0100110# 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).
112ifneq ($(BR_ORIG_UMASK),)
113DOWNLOAD_SET_UMASK = umask $(BR_ORIG_UMASK);
114endif
115
Maxime Hadjinlianc8ef0c02018-04-02 10:14:23 +0200116define DOWNLOAD
Luca Pescee9960262022-12-06 11:41:23 +0100117 $(Q)$(DOWNLOAD_SET_UMASK) mkdir -p $($(PKG)_DL_DIR)
118 $(Q)$(DOWNLOAD_SET_UMASK) $(EXTRA_ENV) \
Yann E. MORINd2dd96f2024-06-07 19:05:42 +0200119 $($(PKG)_DL_ENV) \
Yann E. MORINce6b48c2024-06-05 19:53:17 +0200120 TAR="$(TAR)" \
Yann E. MORINe091e312023-11-06 20:09:14 +0100121 BR_NO_CHECK_HASH_FOR="$(if $(BR2_DOWNLOAD_FORCE_CHECK_HASHES),,$(BR_NO_CHECK_HASH_FOR))" \
Yann E. MORINd2dd96f2024-06-07 19:05:42 +0200122 flock $($(PKG)_DL_DIR)/.lock $(DL_WRAPPER) \
123 -c '$($(PKG)_DL_VERSION)' \
124 -d '$($(PKG)_DL_DIR)' \
Yann E. MORINe80d1d02018-04-02 17:13:58 +0200125 -D '$(DL_DIR)' \
Maxime Hadjinlian765e94e2018-04-02 15:33:53 +0200126 -f '$(notdir $(1))' \
Yann E. MORINd2dd96f2024-06-07 19:05:42 +0200127 $(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 Hadjinlianc8ef0c02018-04-02 10:14:23 +0200136 $(QUIET) \
137 -- \
Yann E. MORINd2dd96f2024-06-07 19:05:42 +0200138 $($(PKG)_DL_OPTS)
Thomas Petazzoni6e6b99a2012-04-17 16:45:19 +0200139endef