xref: /OK3568_Linux_fs/buildroot/package/pkg-download.mk (revision 4882a59341e53eb6f0b4789bf948001014eff981)
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
10# Download method commands
11export WGET := $(call qstrip,$(BR2_WGET))
12export SVN := $(call qstrip,$(BR2_SVN))
13export CVS := $(call qstrip,$(BR2_CVS))
14export BZR := $(call qstrip,$(BR2_BZR))
15export GIT := $(call qstrip,$(BR2_GIT))
16export HG := $(call qstrip,$(BR2_HG))
17export SCP := $(call qstrip,$(BR2_SCP))
18export LOCALFILES := $(call qstrip,$(BR2_LOCALFILES))
19
20# Version of the format of the archives we generate in the corresponding
21# download backend:
22BR_FMT_VERSION_git = -br1
23BR_FMT_VERSION_svn = -br2
24
25DL_WRAPPER = support/download/dl-wrapper
26
27# DL_DIR may have been set already from the environment
28ifeq ($(origin DL_DIR),undefined)
29DL_DIR ?= $(call qstrip,$(BR2_DL_DIR))
30ifeq ($(DL_DIR),)
31DL_DIR := $(TOPDIR)/dl
32endif
33else
34# Restore the BR2_DL_DIR that was overridden by the .config file
35BR2_DL_DIR = $(DL_DIR)
36endif
37
38# ensure it exists and a absolute path, derefrecing symlinks
39DL_DIR := $(shell mkdir -p $(DL_DIR) && cd $(DL_DIR) >/dev/null && pwd -P)
40
41#
42# URI scheme helper functions
43# Example URIs:
44# * http://www.example.com/dir/file
45# * scp://www.example.com:dir/file (with domainseparator :)
46#
47# geturischeme: http
48geturischeme = $(firstword $(subst ://, ,$(call qstrip,$(1))))
49# getschemeplusuri: git|parameter+http://example.com
50getschemeplusuri = $(call geturischeme,$(1))$(if $(2),\|$(2))+$(1)
51# stripurischeme: www.example.com/dir/file
52stripurischeme = $(lastword $(subst ://, ,$(call qstrip,$(1))))
53# domain: www.example.com
54domain = $(firstword $(subst $(call domainseparator,$(2)), ,$(call stripurischeme,$(1))))
55# notdomain: dir/file
56notdomain = $(patsubst $(call domain,$(1),$(2))$(call domainseparator,$(2))%,%,$(call stripurischeme,$(1)))
57#
58# default domainseparator is /, specify alternative value as first argument
59domainseparator = $(if $(1),$(1),/)
60
61# github(user,package,version): returns site of GitHub repository
62github = https://github.com/$(1)/$(2)/archive/$(3)
63
64# gitlab(user,package,version): returns site of Gitlab-generated tarball
65gitlab = https://gitlab.com/$(1)/$(2)/-/archive/$(3)
66
67# Expressly do not check hashes for those files
68# Exported variables default to immediately expanded in some versions of
69# make, but we need it to be recursively-epxanded, so explicitly assign it.
70export BR_NO_CHECK_HASH_FOR =
71
72################################################################################
73# DOWNLOAD_URIS - List the candidates URIs where to get the package from:
74# 1) BR2_PRIMARY_SITE if enabled
75# 2) Download site, unless BR2_PRIMARY_SITE_ONLY is set
76# 3) BR2_BACKUP_SITE if enabled, unless BR2_PRIMARY_SITE_ONLY is set
77#
78# Argument 1 is the source location
79# Argument 2 is the upper-case package name
80#
81################################################################################
82
83ifneq ($(call qstrip,$(BR2_PRIMARY_SITE)),)
84DOWNLOAD_URIS += \
85	$(call getschemeplusuri,$(call qstrip,$(BR2_PRIMARY_SITE)/$($(2)_DL_SUBDIR)),urlencode) \
86	$(call getschemeplusuri,$(call qstrip,$(BR2_PRIMARY_SITE)),urlencode)
87endif
88
89ifeq ($(BR2_PRIMARY_SITE_ONLY),)
90DOWNLOAD_URIS += \
91	$(patsubst %/,%,$(dir $(call qstrip,$(1))))
92ifneq ($(call qstrip,$(BR2_BACKUP_SITE)),)
93DOWNLOAD_URIS += \
94	$(call getschemeplusuri,$(call qstrip,$(BR2_BACKUP_SITE)/$($(2)_DL_SUBDIR)),urlencode) \
95	$(call getschemeplusuri,$(call qstrip,$(BR2_BACKUP_SITE)),urlencode)
96endif
97endif
98
99################################################################################
100# DOWNLOAD -- Download helper. Will call DL_WRAPPER which will try to download
101# source from the list returned by DOWNLOAD_URIS.
102#
103# Argument 1 is the source location
104# Argument 2 is the upper-case package name
105#
106################################################################################
107
108define DOWNLOAD
109	$(Q)mkdir -p $($(2)_DL_DIR)
110	$(Q)$(EXTRA_ENV) $($(2)_DL_ENV) \
111		flock $($(2)_DL_DIR)/.lock $(DL_WRAPPER) \
112		-c '$($(2)_DL_VERSION)' \
113		-d '$($(2)_DL_DIR)' \
114		-D '$(TOPDIR)/archives' \
115		-f '$(notdir $(1))' \
116		-H '$($(2)_HASH_FILE)' \
117		-n '$($(2)_BASENAME_RAW)' \
118		-N '$($(2)_RAWNAME)' \
119		-o '$($(2)_DL_DIR)/$(notdir $(1))' \
120		$(if $($(2)_GIT_SUBMODULES),-r) \
121		$(foreach uri,$(call DOWNLOAD_URIS,$(1),$(2)),-u $(uri)) \
122		$(QUIET) \
123		-- \
124		$($(2)_DL_OPTS)
125endef
126