2013-06-06 07:53:30 +08:00
|
|
|
################################################################################
|
2012-04-17 22:45:20 +08:00
|
|
|
#
|
|
|
|
# This file contains the download helpers for the various package
|
|
|
|
# infrastructures. It is used to handle downloads from HTTP servers,
|
|
|
|
# FTP servers, Git repositories, Subversion repositories, Mercurial
|
|
|
|
# repositories, Bazaar repositories, and SCP servers.
|
|
|
|
#
|
2013-06-06 07:53:30 +08:00
|
|
|
################################################################################
|
2012-04-17 22:45:20 +08:00
|
|
|
|
2012-04-17 22:45:19 +08:00
|
|
|
# Download method commands
|
2013-07-20 14:52:43 +08:00
|
|
|
WGET := $(call qstrip,$(BR2_WGET)) $(QUIET)
|
|
|
|
SVN := $(call qstrip,$(BR2_SVN))
|
2013-09-11 20:12:04 +08:00
|
|
|
CVS := $(call qstrip,$(BR2_CVS))
|
2013-07-20 14:52:43 +08:00
|
|
|
BZR := $(call qstrip,$(BR2_BZR))
|
|
|
|
GIT := $(call qstrip,$(BR2_GIT))
|
|
|
|
HG := $(call qstrip,$(BR2_HG)) $(QUIET)
|
|
|
|
SCP := $(call qstrip,$(BR2_SCP)) $(QUIET)
|
|
|
|
SSH := $(call qstrip,$(BR2_SSH)) $(QUIET)
|
|
|
|
LOCALFILES := $(call qstrip,$(BR2_LOCALFILES))
|
2012-04-17 22:45:19 +08:00
|
|
|
|
|
|
|
# Default spider mode is 'DOWNLOAD'. Other possible values are 'SOURCE_CHECK'
|
|
|
|
# used by the _source-check target and 'SHOW_EXTERNAL_DEPS', used by the
|
|
|
|
# external-deps target.
|
|
|
|
DL_MODE=DOWNLOAD
|
|
|
|
|
2014-02-04 23:18:51 +08:00
|
|
|
# DL_DIR may have been set already from the environment
|
2014-02-11 05:48:55 +08:00
|
|
|
ifeq ($(origin DL_DIR),undefined)
|
2014-02-04 23:18:51 +08:00
|
|
|
DL_DIR ?= $(call qstrip,$(BR2_DL_DIR))
|
2012-04-17 22:45:19 +08:00
|
|
|
ifeq ($(DL_DIR),)
|
2013-07-20 14:52:43 +08:00
|
|
|
DL_DIR := $(TOPDIR)/dl
|
2012-04-17 22:45:19 +08:00
|
|
|
endif
|
2014-02-11 05:48:55 +08:00
|
|
|
else
|
|
|
|
# Restore the BR2_DL_DIR that was overridden by the .config file
|
|
|
|
BR2_DL_DIR = $(DL_DIR)
|
|
|
|
endif
|
2012-04-17 22:45:19 +08:00
|
|
|
|
2012-09-10 18:38:29 +08:00
|
|
|
# ensure it exists and a absolute path
|
2013-07-20 14:52:43 +08:00
|
|
|
DL_DIR := $(shell mkdir -p $(DL_DIR) && cd $(DL_DIR) >/dev/null && pwd)
|
2012-09-10 18:38:29 +08:00
|
|
|
|
2012-04-17 22:45:19 +08:00
|
|
|
#
|
|
|
|
# URI scheme helper functions
|
|
|
|
# Example URIs:
|
|
|
|
# * http://www.example.com/dir/file
|
|
|
|
# * scp://www.example.com:dir/file (with domainseparator :)
|
|
|
|
#
|
|
|
|
# geturischeme: http
|
|
|
|
geturischeme=$(firstword $(subst ://, ,$(call qstrip,$(1))))
|
|
|
|
# stripurischeme: www.example.com/dir/file
|
|
|
|
stripurischeme=$(lastword $(subst ://, ,$(call qstrip,$(1))))
|
|
|
|
# domain: www.example.com
|
|
|
|
domain=$(firstword $(subst $(call domainseparator,$(2)), ,$(call stripurischeme,$(1))))
|
|
|
|
# notdomain: dir/file
|
|
|
|
notdomain=$(patsubst $(call domain,$(1),$(2))$(call domainseparator,$(2))%,%,$(call stripurischeme,$(1)))
|
|
|
|
#
|
|
|
|
# default domainseparator is /, specify alternative value as first argument
|
|
|
|
domainseparator=$(if $(1),$(1),/)
|
|
|
|
|
2013-12-06 01:20:44 +08:00
|
|
|
# github(user,package,version): returns site of github repository
|
|
|
|
github = https://github.com/$(1)/$(2)/tarball/$(3)
|
|
|
|
|
2012-04-17 22:45:19 +08:00
|
|
|
################################################################################
|
2013-09-11 20:12:04 +08:00
|
|
|
# The DOWNLOAD_* helpers are in charge of getting a working copy
|
|
|
|
# of the source repository for their corresponding SCM,
|
2012-04-17 22:45:19 +08:00
|
|
|
# checking out the requested version / commit / tag, and create an
|
|
|
|
# archive out of it. DOWNLOAD_SCP uses scp to obtain a remote file with
|
|
|
|
# ssh authentication. DOWNLOAD_WGET is the normal wget-based download
|
|
|
|
# mechanism.
|
|
|
|
#
|
2013-09-11 20:12:04 +08:00
|
|
|
# The SOURCE_CHECK_* helpers are in charge of simply checking that the source
|
|
|
|
# is available for download. This can be used to make sure one will be able
|
|
|
|
# to get all the sources needed for one's build configuration.
|
2012-04-17 22:45:19 +08:00
|
|
|
#
|
2013-09-11 20:12:04 +08:00
|
|
|
# The SHOW_EXTERNAL_DEPS_* helpers simply output to the console the names
|
|
|
|
# of the files that will be downloaded, or path and revision of the
|
|
|
|
# source repositories, producing a list of all the "external dependencies"
|
|
|
|
# of a given build configuration.
|
2012-04-17 22:45:19 +08:00
|
|
|
################################################################################
|
|
|
|
|
2012-11-01 09:21:05 +08:00
|
|
|
# Try a shallow clone - but that only works if the version is a ref (tag or
|
2012-12-02 08:56:07 +08:00
|
|
|
# branch). Before trying to do a shallow clone we check if $($(PKG)_DL_VERSION)
|
|
|
|
# is in the list provided by git ls-remote. If not we fall back on a full clone.
|
|
|
|
#
|
|
|
|
# Messages for the type of clone used are provided to ease debugging in case of
|
|
|
|
# problems
|
2012-04-17 22:45:19 +08:00
|
|
|
define DOWNLOAD_GIT
|
|
|
|
test -e $(DL_DIR)/$($(PKG)_SOURCE) || \
|
|
|
|
(pushd $(DL_DIR) > /dev/null && \
|
2012-12-07 00:37:07 +08:00
|
|
|
((test "`git ls-remote $($(PKG)_SITE) $($(PKG)_DL_VERSION)`" && \
|
2012-12-02 08:56:07 +08:00
|
|
|
echo "Doing shallow clone" && \
|
|
|
|
$(GIT) clone --depth 1 -b $($(PKG)_DL_VERSION) --bare $($(PKG)_SITE) $($(PKG)_BASE_NAME)) || \
|
|
|
|
(echo "Doing full clone" && \
|
|
|
|
$(GIT) clone --bare $($(PKG)_SITE) $($(PKG)_BASE_NAME))) && \
|
2012-04-17 22:45:19 +08:00
|
|
|
pushd $($(PKG)_BASE_NAME) > /dev/null && \
|
pkg-download: make sure git downloads fail for unknown versions
The current git download helper creates the tarball by doing:
git archive <version> | gzip -c > <tarball>
Unfortunately, even if "git archive" fails and returns a non-zero
error code, gzip ignores that, compresses nothing, and returns success
(zero error code). The consequence of this behavior is that when the
git version provided in the package is incorrect, we are not failing
during the download step, but later on when trying to extract the
tarball (which was incorrectly created as a result of the failing git
archive).
To fix this, we change the tarball creation logic to:
git archive -o <tarball>.tmp <version> &&
gzip -c <tarball>.tmp > <tarball> &&
rm -f <tarball>.tmp
If the build is interrupted during the "gzip" command, we may leave
the .tmp file behind us, but this also happens with wget downloads,
and is generally not considered a problem, since this temporary file
will be overwritten next time we attempt to do download this package.
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Signed-off-by: Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
2014-02-04 21:36:56 +08:00
|
|
|
$(GIT) archive --format=tar --prefix=$($(PKG)_BASE_NAME)/ -o $(DL_DIR)/.$($(PKG)_SOURCE).tmp $($(PKG)_DL_VERSION) && \
|
|
|
|
gzip -c $(DL_DIR)/.$($(PKG)_SOURCE).tmp > $(DL_DIR)/$($(PKG)_SOURCE) && \
|
|
|
|
rm -f $(DL_DIR)/.$($(PKG)_SOURCE).tmp && \
|
2012-04-17 22:45:19 +08:00
|
|
|
popd > /dev/null && \
|
|
|
|
rm -rf $($(PKG)_DL_DIR) && \
|
|
|
|
popd > /dev/null)
|
|
|
|
endef
|
|
|
|
|
|
|
|
# TODO: improve to check that the given PKG_DL_VERSION exists on the remote
|
|
|
|
# repository
|
|
|
|
define SOURCE_CHECK_GIT
|
|
|
|
$(GIT) ls-remote --heads $($(PKG)_SITE) > /dev/null
|
|
|
|
endef
|
|
|
|
|
|
|
|
define SHOW_EXTERNAL_DEPS_GIT
|
|
|
|
echo $($(PKG)_SOURCE)
|
|
|
|
endef
|
|
|
|
|
|
|
|
|
|
|
|
define DOWNLOAD_BZR
|
|
|
|
test -e $(DL_DIR)/$($(PKG)_SOURCE) || \
|
|
|
|
$(BZR) export $(DL_DIR)/$($(PKG)_SOURCE) $($(PKG)_SITE) -r $($(PKG)_DL_VERSION)
|
|
|
|
endef
|
|
|
|
|
|
|
|
define SOURCE_CHECK_BZR
|
|
|
|
$(BZR) ls --quiet $($(PKG)_SITE) > /dev/null
|
|
|
|
endef
|
|
|
|
|
|
|
|
define SHOW_EXTERNAL_DEPS_BZR
|
|
|
|
echo $($(PKG)_SOURCE)
|
|
|
|
endef
|
|
|
|
|
2013-09-11 20:12:04 +08:00
|
|
|
define DOWNLOAD_CVS
|
|
|
|
test -e $(DL_DIR)/$($(PKG)_SOURCE) || \
|
|
|
|
(pushd $(DL_DIR) > /dev/null && \
|
|
|
|
$(CVS) -z3 -d:pserver:anonymous@$(call stripurischeme,$(call qstrip,$($(PKG)_SITE))) \
|
|
|
|
co -d $($(PKG)_BASE_NAME) -r :$($(PKG)_DL_VERSION) -P $($(PKG)_RAWNAME) && \
|
|
|
|
$(TAR) czf $($(PKG)_SOURCE) $($(PKG)_BASE_NAME)/ && \
|
|
|
|
rm -rf $($(PKG)_DL_DIR) && \
|
|
|
|
popd > /dev/null)
|
|
|
|
endef
|
|
|
|
|
|
|
|
# Not all CVS servers support ls/rls, use login to see if we can connect
|
|
|
|
define SOURCE_CHECK_CVS
|
|
|
|
$(CVS) -d:pserver:anonymous:@$(call stripurischeme,$(call qstrip,$($(PKG)_SITE))) login
|
|
|
|
endef
|
|
|
|
|
|
|
|
define SHOW_EXTERNAL_DEPS_CVS
|
|
|
|
echo $($(PKG)_SOURCE)
|
|
|
|
endef
|
2012-04-17 22:45:19 +08:00
|
|
|
|
|
|
|
define DOWNLOAD_SVN
|
|
|
|
test -e $(DL_DIR)/$($(PKG)_SOURCE) || \
|
|
|
|
(pushd $(DL_DIR) > /dev/null && \
|
|
|
|
$(SVN) export -r $($(PKG)_DL_VERSION) $($(PKG)_SITE) $($(PKG)_DL_DIR) && \
|
|
|
|
$(TAR) czf $($(PKG)_SOURCE) $($(PKG)_BASE_NAME)/ && \
|
|
|
|
rm -rf $($(PKG)_DL_DIR) && \
|
|
|
|
popd > /dev/null)
|
|
|
|
endef
|
|
|
|
|
|
|
|
define SOURCE_CHECK_SVN
|
|
|
|
$(SVN) ls $($(PKG)_SITE) > /dev/null
|
|
|
|
endef
|
|
|
|
|
|
|
|
define SHOW_EXTERNAL_DEPS_SVN
|
|
|
|
echo $($(PKG)_SOURCE)
|
|
|
|
endef
|
|
|
|
|
|
|
|
# SCP URIs should be of the form scp://[user@]host:filepath
|
|
|
|
# Note that filepath is relative to the user's home directory, so you may want
|
|
|
|
# to prepend the path with a slash: scp://[user@]host:/absolutepath
|
|
|
|
define DOWNLOAD_SCP
|
|
|
|
test -e $(DL_DIR)/$(2) || \
|
|
|
|
$(SCP) '$(call stripurischeme,$(call qstrip,$(1)))' $(DL_DIR)/$(2)
|
|
|
|
endef
|
|
|
|
|
|
|
|
define SOURCE_CHECK_SCP
|
|
|
|
$(SSH) $(call domain,$(1),:) ls '$(call notdomain,$(1),:)' > /dev/null
|
|
|
|
endef
|
|
|
|
|
|
|
|
define SHOW_EXTERNAL_DEPS_SCP
|
|
|
|
echo $(2)
|
|
|
|
endef
|
|
|
|
|
|
|
|
|
|
|
|
define DOWNLOAD_HG
|
|
|
|
test -e $(DL_DIR)/$($(PKG)_SOURCE) || \
|
|
|
|
(pushd $(DL_DIR) > /dev/null && \
|
2013-12-11 02:31:30 +08:00
|
|
|
rm -rf $($(PKG)_BASE_NAME) && \
|
2012-04-17 22:45:19 +08:00
|
|
|
$(HG) clone --noupdate --rev $($(PKG)_DL_VERSION) $($(PKG)_SITE) $($(PKG)_BASE_NAME) && \
|
|
|
|
$(HG) archive --repository $($(PKG)_BASE_NAME) --type tgz --prefix $($(PKG)_BASE_NAME)/ \
|
|
|
|
--rev $($(PKG)_DL_VERSION) $(DL_DIR)/$($(PKG)_SOURCE) && \
|
|
|
|
rm -rf $($(PKG)_DL_DIR) && \
|
|
|
|
popd > /dev/null)
|
|
|
|
endef
|
|
|
|
|
|
|
|
# TODO: improve to check that the given PKG_DL_VERSION exists on the remote
|
|
|
|
# repository
|
|
|
|
define SOURCE_CHECK_HG
|
|
|
|
$(HG) incoming --force -l1 $($(PKG)_SITE) > /dev/null
|
|
|
|
endef
|
|
|
|
|
|
|
|
define SHOW_EXTERNAL_DEPS_HG
|
|
|
|
echo $($(PKG)_SOURCE)
|
|
|
|
endef
|
|
|
|
|
|
|
|
# Download a file using wget. Only download the file if it doesn't
|
|
|
|
# already exist in the download directory. If the download fails,
|
|
|
|
# remove the file (because wget -O creates a 0-byte file even if the
|
2012-06-30 19:43:03 +08:00
|
|
|
# download fails). To handle an interrupted download as well, download
|
|
|
|
# to a temporary file first. The temporary file will be overwritten
|
|
|
|
# the next time the download is tried.
|
2012-04-17 22:45:19 +08:00
|
|
|
define DOWNLOAD_WGET
|
|
|
|
test -e $(DL_DIR)/$(2) || \
|
2012-06-30 19:43:03 +08:00
|
|
|
($(WGET) -O $(DL_DIR)/$(2).tmp '$(call qstrip,$(1))' && \
|
|
|
|
mv $(DL_DIR)/$(2).tmp $(DL_DIR)/$(2)) || \
|
|
|
|
(rm -f $(DL_DIR)/$(2).tmp ; exit 1)
|
2012-04-17 22:45:19 +08:00
|
|
|
endef
|
|
|
|
|
|
|
|
define SOURCE_CHECK_WGET
|
|
|
|
$(WGET) --spider '$(call qstrip,$(1))'
|
|
|
|
endef
|
|
|
|
|
|
|
|
define SHOW_EXTERNAL_DEPS_WGET
|
|
|
|
echo $(2)
|
|
|
|
endef
|
|
|
|
|
|
|
|
define DOWNLOAD_LOCALFILES
|
2012-06-22 13:42:34 +08:00
|
|
|
test -e $(DL_DIR)/$(2) || \
|
2012-06-22 13:42:35 +08:00
|
|
|
$(LOCALFILES) $(call stripurischeme,$(call qstrip,$(1))) $(DL_DIR)
|
2012-04-17 22:45:19 +08:00
|
|
|
endef
|
|
|
|
|
|
|
|
define SOURCE_CHECK_LOCALFILES
|
2012-06-22 13:42:35 +08:00
|
|
|
test -e $(call stripurischeme,$(call qstrip,$(1)))
|
2012-04-17 22:45:19 +08:00
|
|
|
endef
|
|
|
|
|
|
|
|
define SHOW_EXTERNAL_DEPS_LOCALFILES
|
2012-06-22 13:42:34 +08:00
|
|
|
echo $(2)
|
2012-04-17 22:45:19 +08:00
|
|
|
endef
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# DOWNLOAD -- Download helper. Will try to download source from:
|
|
|
|
# 1) BR2_PRIMARY_SITE if enabled
|
2012-06-22 13:37:03 +08:00
|
|
|
# 2) Download site, unless BR2_PRIMARY_SITE_ONLY is set
|
|
|
|
# 3) BR2_BACKUP_SITE if enabled, unless BR2_PRIMARY_SITE_ONLY is set
|
2012-04-17 22:45:19 +08:00
|
|
|
#
|
|
|
|
# Argument 1 is the source location
|
|
|
|
#
|
|
|
|
# E.G. use like this:
|
2014-03-03 01:51:34 +08:00
|
|
|
# $(call DOWNLOAD,$(FOO_SITE))
|
2012-04-17 22:45:19 +08:00
|
|
|
################################################################################
|
|
|
|
|
|
|
|
define DOWNLOAD
|
2014-03-03 01:51:34 +08:00
|
|
|
$(call DOWNLOAD_INNER,$(1),$(notdir $(1)))
|
2012-04-17 22:45:19 +08:00
|
|
|
endef
|
|
|
|
|
|
|
|
define DOWNLOAD_INNER
|
|
|
|
$(Q)if test -n "$(call qstrip,$(BR2_PRIMARY_SITE))" ; then \
|
|
|
|
case "$(call geturischeme,$(BR2_PRIMARY_SITE))" in \
|
2012-05-23 17:30:36 +08:00
|
|
|
scp) $(call $(DL_MODE)_SCP,$(BR2_PRIMARY_SITE)/$(2),$(2)) && exit ;; \
|
2012-04-25 09:45:16 +08:00
|
|
|
*) $(call $(DL_MODE)_WGET,$(BR2_PRIMARY_SITE)/$(2),$(2)) && exit ;; \
|
2012-04-17 22:45:19 +08:00
|
|
|
esac ; \
|
|
|
|
fi ; \
|
2012-06-22 13:37:03 +08:00
|
|
|
if test "$(BR2_PRIMARY_SITE_ONLY)" = "y" ; then \
|
|
|
|
exit 1 ; \
|
|
|
|
fi ; \
|
2012-04-17 22:45:19 +08:00
|
|
|
if test -n "$(1)" ; then \
|
2012-06-22 13:42:36 +08:00
|
|
|
if test -z "$($(PKG)_SITE_METHOD)" ; then \
|
|
|
|
scheme="$(call geturischeme,$(1))" ; \
|
|
|
|
else \
|
|
|
|
scheme="$($(PKG)_SITE_METHOD)" ; \
|
|
|
|
fi ; \
|
|
|
|
case "$$scheme" in \
|
2012-04-17 22:45:19 +08:00
|
|
|
git) $($(DL_MODE)_GIT) && exit ;; \
|
|
|
|
svn) $($(DL_MODE)_SVN) && exit ;; \
|
2013-09-11 20:12:04 +08:00
|
|
|
cvs) $($(DL_MODE)_CVS) && exit ;; \
|
2012-04-17 22:45:19 +08:00
|
|
|
bzr) $($(DL_MODE)_BZR) && exit ;; \
|
|
|
|
file) $($(DL_MODE)_LOCALFILES) && exit ;; \
|
|
|
|
scp) $($(DL_MODE)_SCP) && exit ;; \
|
|
|
|
hg) $($(DL_MODE)_HG) && exit ;; \
|
|
|
|
*) $(call $(DL_MODE)_WGET,$(1),$(2)) && exit ;; \
|
|
|
|
esac ; \
|
|
|
|
fi ; \
|
|
|
|
if test -n "$(call qstrip,$(BR2_BACKUP_SITE))" ; then \
|
|
|
|
$(call $(DL_MODE)_WGET,$(BR2_BACKUP_SITE)/$(2),$(2)) && exit ; \
|
|
|
|
fi ; \
|
|
|
|
exit 1
|
|
|
|
endef
|