update to 3.1.5
[openadk.git] / mk / fetch.mk
bloba2590d46728184ee8795ff34e90e9be18b6a1338
1 # This file is part of the OpenADK project. OpenADK is copyrighted
2 # material, please see the LICENCE file in the top-level directory.
4 ifneq ($(strip ${DIST_SUBDIR}),)
5 FULLDISTDIR?= ${DISTDIR}/${DIST_SUBDIR}
6 else
7 FULLDISTDIR?= ${DISTDIR}
8 endif
10 FULLDISTFILES= $(patsubst %,${FULLDISTDIR}/%,${DISTFILES})
12 FETCH_STYLE?= auto
13 #pre-fetch:
14 do-fetch:
15 #post-fetch:
16 fetch:
17 # @${MAKE} pre-fetch
18 ifneq ($(filter auto,${FETCH_STYLE}),)
19 ${MAKE} ${FULLDISTFILES}
20 else
21 ${MAKE} do-fetch
22 endif
23 # @${MAKE} post-fetch
25 refetch:
26 -rm -f ${FULLDISTFILES}
27 ${MAKE} fetch
29 # XXX for now
30 _CHECKSUM_COOKIE?= ${WRKDIR}/.checksum_done
31 checksum: ${_CHECKSUM_COOKIE}
32 ifeq ($(strip ${NO_CHECKSUM}),)
33 ${_CHECKSUM_COOKIE}: ${FULLDISTFILES}
34 -rm -rf ${WRKDIR}
35 @OK=n; \
36 allsums="$(strip ${PKG_MD5SUM})"; \
37 (md5sum ${FULLDISTFILES}; echo exit) | while read sum name; do \
38 if [[ $$sum = exit ]]; then \
39 [[ $$OK = n ]] && echo >&2 "==> No distfile found!" || :; \
40 [[ $$OK = 1 ]] || exit 1; \
41 break; \
42 fi; \
43 cursum="$${allsums%% *}"; \
44 allsums="$${allsums#* }"; \
45 if [[ $$sum = "$$cursum" ]]; then \
46 [[ $$OK = 0 ]] || OK=1; \
47 continue; \
48 fi; \
49 echo >&2 "==> Checksum mismatch for $${name##*/} (MD5)"; \
50 echo >&2 ":---> should be '$$cursum'"; \
51 echo >&2 ":---> really is '$$sum'"; \
52 OK=0; \
53 done
54 mkdir -p ${WRKDIR}
55 touch ${_CHECKSUM_COOKIE}
56 endif
58 # GNU make's poor excuse for loops
59 define FETCH_template
60 $(1):
61 @fullname='$(1)'; \
62 filename=$$$${fullname##*/}; \
63 mkdir -p "$$$${fullname%%/$$$$filename}"; \
64 cd "$$$${fullname%%/$$$$filename}"; \
65 for site in $${PKG_SITES} $${MASTER_SITE_BACKUP}; do \
66 : echo "$${FETCH_CMD} $$$$site$$$$filename"; \
67 rm -f "$$$$filename"; \
68 if $${FETCH_CMD} $$$$site$$$$filename; then \
69 : check the size here; \
70 [[ ! -e $$$$filename ]] || exit 0; \
71 fi; \
72 done; \
73 exit 1
74 endef
76 $(foreach distfile,${FULLDISTFILES},$(eval $(call FETCH_template,$(distfile))))