summaryrefslogtreecommitdiff
path: root/mk/fetch.mk
blob: b6164c03c306bb2359855f37e2550fc5b7abac53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# This file is part of the OpenADK project. OpenADK is copyrighted
# material, please see the LICENCE file in the top-level directory.

ifneq ($(strip ${DIST_SUBDIR}),)
FULLDISTDIR?=		${DL_DIR}/${DIST_SUBDIR}
else
FULLDISTDIR?=		${DL_DIR}
endif

FULLDISTFILES=		$(patsubst %,${FULLDISTDIR}/%,${DISTFILES})

FETCH_STYLE?=		auto
do-fetch:
fetch:
ifneq ($(filter auto,${FETCH_STYLE}),)
	${MAKE} ${FULLDISTFILES}
else
	${MAKE} do-fetch
endif

refetch:
	-rm -f ${FULLDISTFILES}
	${MAKE} fetch

_CHECKSUM_COOKIE?=	${WRKDIR}/.checksum_done
checksum: ${_CHECKSUM_COOKIE}
ifeq ($(strip ${PKG_NOCHECKSUM}),)
${_CHECKSUM_COOKIE}: ${FULLDISTFILES}
	-rm -rf ${WRKDIR}
ifneq ($(ADK_DISABLE_CHECKSUM),y)
	@if [ ! -e $(firstword ${FULLDISTFILES}).nohash ]; then \
	OK=n; \
	allsums="$(strip ${PKG_HASH})"; \
	($${SHA256} ${FULLDISTFILES}; echo exit) | while read sum name; do \
		if [[ $$sum = exit ]]; then \
			[[ $$OK = n ]] && echo >&2 "==> No distfile found!" || :; \
			[[ $$OK = 1 ]] || exit 1; \
			break; \
		fi; \
		cursum="$${allsums%% *}"; \
		allsums="$${allsums#* }"; \
		if [[ $$sum = "$$cursum" ]]; then \
			[[ $$OK = 0 ]] || OK=1; \
			continue; \
		fi; \
		echo >&2 "==> Checksum mismatch for $${name##*/} (SHA256)"; \
		echo >&2 ":---> should be '$$cursum'"; \
		echo >&2 ":---> really is '$$sum'"; \
		OK=0; \
	done; \
	fi
endif
	mkdir -p ${WRKDIR}
	touch ${_CHECKSUM_COOKIE}
endif

# GNU make's poor excuse for loops
define FETCH_template
$(1):
	@fullname='$(1)'; \
	filename=$$$${fullname##*/}; \
	mkdir -p "$$$${fullname%%/$$$$filename}"; \
	cd "$$$${fullname%%/$$$$filename}"; \
	for url in "${PKG_SITES}"; do case $$$$url in \
	   file://*|git://*|*.git) \
		echo "Trying to downloading from backup site first"; \
		if $${FETCHCMD} $$$$filename $${MASTER_SITE_BACKUP}/$$$$filename $(DL_TRACE); then \
			touch $$$$filename.nohash; \
			: check the size here; \
			[[ ! -e $$$$filename ]] || exit 0; \
		fi; \
		rm -rf $${PKG_NAME}-$${PKG_VERSION}; \
		if [ ! -z "$${PKG_GIT}" ]; then \
		  echo "Using git ${PKG_GIT}: $${PKG_VERSION}" $(DL_TRACE); \
		  case "$${PKG_GIT}" in \
		    tag|branch) \
			git clone --progress --depth 1 --branch $${PKG_VERSION} $${PKG_SITES} $${PKG_NAME}-$${PKG_VERSION} $(DL_TRACE); \
			if [ $$$$? -ne 0 ]; then echo "git clone error"; exit 1; fi; \
			;; \
		    hash) \
			git clone --progress $${PKG_SITES} $${PKG_NAME}-$${PKG_VERSION} $(DL_TRACE); \
			if [ $$$$? -ne 0 ]; then echo "git clone error"; exit 1; fi; \
			(cd $${PKG_NAME}-$${PKG_VERSION}; git checkout $${PKG_VERSION}) $(DL_TRACE); \
			;; \
		  esac ;\
		else \
		  git clone --progress --depth 1 $${PKG_SITES} $${PKG_NAME}-$${PKG_VERSION} $(DL_TRACE); \
		  if [ $$$$? -ne 0 ]; then echo "git clone error"; exit 1; fi; \
		fi; \
		if [ ! -z "$${PKG_GIT_SUBMODULE}" ]; then \
			(cd $${PKG_NAME}-$${PKG_VERSION}; git submodule update --init --recursive) $(DL_TRACE); \
		fi; \
		rm -rf $${PKG_NAME}-$${PKG_VERSION}/.git; \
		tar cJf $${PKG_NAME}-$${PKG_VERSION}.tar.xz $${PKG_NAME}-$${PKG_VERSION}; \
		touch $$$${filename}.nohash; \
		rm -rf $${PKG_NAME}-$${PKG_VERSION}; \
		: check the size here; \
		[[ ! -e $$$$filename ]] || exit 0; \
		;; \
	    http://*|https://*|ftp://*) \
		for site in $${PKG_SITES} $${MASTER_SITE_BACKUP}; do \
			echo "$${FETCHCMD} $$$$site$$$$filename" $(DL_TRACE); \
			rm -f "$$$$filename"; \
			if $${FETCHCMD} $$$$filename $$$$site$$$$filename $(DL_TRACE); then \
				: check the size here; \
				[[ ! -e $$$$filename ]] || exit 0; \
			fi; \
		done; \
		;; \
	   *) \
		echo url schema not known; \
		false ;; \
	esac; \
	done
endef

$(foreach distfile,${FULLDISTFILES},$(eval $(call FETCH_template,$(distfile))))