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