wget: update to 1.19.4
[openadk.git] / mk / fetch.mk
blob2d3e7d666db6be95e7f7852aed3133ccc9f84bda
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?= ${DL_DIR}/${DIST_SUBDIR}
6 else
7 FULLDISTDIR?= ${DL_DIR}
8 endif
10 FULLDISTFILES= $(patsubst %,${FULLDISTDIR}/%,${DISTFILES})
12 FETCH_STYLE?= auto
13 do-fetch:
14 fetch:
15 ifneq ($(filter auto,${FETCH_STYLE}),)
16 ${MAKE} ${FULLDISTFILES}
17 else
18 ${MAKE} do-fetch
19 endif
21 refetch:
22 -rm -f ${FULLDISTFILES}
23 ${MAKE} fetch
25 _CHECKSUM_COOKIE?= ${WRKDIR}/.checksum_done
26 checksum: ${_CHECKSUM_COOKIE}
27 ifeq ($(strip ${PKG_NOCHECKSUM}),)
28 ${_CHECKSUM_COOKIE}: ${FULLDISTFILES}
29 -rm -rf ${WRKDIR}
30 ifneq ($(ADK_DISABLE_CHECKSUM),y)
31 @if [ ! -e $(firstword ${FULLDISTFILES}).nohash ]; then \
32 OK=n; \
33 allsums="$(strip ${PKG_HASH})"; \
34 ($${SHA256} ${FULLDISTFILES}; echo exit) | while read sum name; do \
35 if [[ $$sum = exit ]]; then \
36 [[ $$OK = n ]] && echo >&2 "==> No distfile found!" || :; \
37 [[ $$OK = 1 ]] || exit 1; \
38 break; \
39 fi; \
40 cursum="$${allsums%% *}"; \
41 allsums="$${allsums#* }"; \
42 if [[ $$sum = "$$cursum" ]]; then \
43 [[ $$OK = 0 ]] || OK=1; \
44 continue; \
45 fi; \
46 echo >&2 "==> Checksum mismatch for $${name##*/} (SHA256)"; \
47 echo >&2 ":---> should be '$$cursum'"; \
48 echo >&2 ":---> really is '$$sum'"; \
49 OK=0; \
50 done; \
52 endif
53 mkdir -p ${WRKDIR}
54 touch ${_CHECKSUM_COOKIE}
55 endif
57 # GNU make's poor excuse for loops
58 define FETCH_template
59 $(1):
60 @fullname='$(1)'; \
61 filename=$$$${fullname##*/}; \
62 mkdir -p "$$$${fullname%%/$$$$filename}"; \
63 cd "$$$${fullname%%/$$$$filename}"; \
64 for url in "${PKG_SITES}"; do case $$$$url in \
65 file://*|git://*|*.git) \
66 echo "Trying to downloading from backup site first"; \
67 if $${FETCHCMD} $$$$filename $${MASTER_SITE_BACKUP}/$$$$filename $(DL_TRACE); then \
68 touch $$$$filename.nohash; \
69 : check the size here; \
70 [[ ! -e $$$$filename ]] || exit 0; \
71 fi; \
72 rm -rf $${PKG_NAME}-$${PKG_VERSION}; \
73 if [ ! -z "$${PKG_GIT}" ]; then \
74 echo "Using git ${PKG_GIT}: $${PKG_VERSION}" $(DL_TRACE); \
75 case "$${PKG_GIT}" in \
76 tag|branch) \
77 git clone --progress --depth 1 --branch $${PKG_VERSION} $${PKG_SITES} $${PKG_NAME}-$${PKG_VERSION} $(DL_TRACE); \
78 if [ $$$$? -ne 0 ]; then echo "git clone error"; exit 1; fi; \
79 ;; \
80 hash) \
81 git clone --progress $${PKG_SITES} $${PKG_NAME}-$${PKG_VERSION} $(DL_TRACE); \
82 if [ $$$$? -ne 0 ]; then echo "git clone error"; exit 1; fi; \
83 (cd $${PKG_NAME}-$${PKG_VERSION}; git checkout $${PKG_VERSION}) $(DL_TRACE); \
84 if [ $$$$? -ne 0 ]; then echo "git checkout error"; exit 1; fi; \
85 ;; \
86 esac ;\
87 else \
88 git clone --progress --depth 1 $${PKG_SITES} $${PKG_NAME}-$${PKG_VERSION} $(DL_TRACE); \
89 if [ $$$$? -ne 0 ]; then echo "git clone error"; exit 1; fi; \
90 fi; \
91 if [ ! -z "$${PKG_GIT_SUBMODULE}" ]; then \
92 (cd $${PKG_NAME}-$${PKG_VERSION}; git submodule update --init --recursive) $(DL_TRACE); \
93 fi; \
94 rm -rf $${PKG_NAME}-$${PKG_VERSION}/.git; \
95 tar cJf $${PKG_NAME}-$${PKG_VERSION}.tar.xz $${PKG_NAME}-$${PKG_VERSION}; \
96 touch $$$${filename}.nohash; \
97 rm -rf $${PKG_NAME}-$${PKG_VERSION}; \
98 : check the size here; \
99 [[ ! -e $$$$filename ]] || exit 0; \
100 ;; \
101 http://*|https://*|ftp://*) \
102 for site in $${PKG_SITES} $${MASTER_SITE_BACKUP}; do \
103 echo "$${FETCHCMD} $$$$site$$$$filename" $(DL_TRACE); \
104 rm -f "$$$$filename"; \
105 if $${FETCHCMD} $$$$filename $$$$site$$$$filename $(DL_TRACE); then \
106 : check the size here; \
107 [[ ! -e $$$$filename ]] || exit 0; \
108 fi; \
109 done; \
110 ;; \
111 *) \
112 echo url schema not known; \
113 false ;; \
114 esac; \
115 done
116 endef
118 $(foreach distfile,${FULLDISTFILES},$(eval $(call FETCH_template,$(distfile))))