summaryrefslogtreecommitdiff
path: root/mk/checksum/checksum.mk
blob: 5b6ec75e06e45b2dc971def1ef532a9217bcf608 (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
# $NetBSD: checksum.mk,v 1.12 2007/10/09 19:19:13 martti Exp $
#
# See bsd.checksum.mk for helpful comments.
#

_DIGEST_ALGORITHMS?=		SHA1 RMD160
_PATCH_DIGEST_ALGORITHMS?=	SHA1

# These variables are set by pkgsrc/mk/fetch/fetch.mk.
#_CKSUMFILES?=	# empty
#_IGNOREFILES?=	# empty

# _COOKIE.checksum
#       The file whose presence determines whether or not the checksum
#	process is run.
#
#	This is not a traditional cookie file.  We do not actually
#	wish to create a cookie file for the completion of the checksum
#	phase because we want to be able to detect if any of the files
#	have changed right up until the distfiles are extracted.
#	Therefore, we use the presence of the cookie file from the
#	"extract" phase to determine whether we need to continue to
#	verify checksums.
#
#	_COOKIE.extract is defined in pkgsrc/mk/extract/extract.mk.
#
_COOKIE.checksum=	${_COOKIE.extract}

_CHECKSUM_CMD=								\
	${SETENV} DIGEST=${TOOLS_DIGEST:Q} CAT=${TOOLS_CAT:Q}		\
		ECHO=${TOOLS_ECHO:Q} SED=${TOOLS_SED:Q}			\
		TEST=${TOOLS_TEST:Q}					\
	${SH} ${PKGSRCDIR}/mk/checksum/checksum				\

checksum checksum-phase:
	${RUN} set -e;							\
	case ${.TARGET:Q} in						\
	*-phase)	${TEST} ! -f ${_COOKIE.checksum} || exit 0 ;;	\
	esac;								\
	if cd ${DISTDIR} && ${_CHECKSUM_CMD} ${DISTINFO_FILE} ${_CKSUMFILES}; then \
		${TRUE};						\
	else								\
		${ERROR_MSG} "Make sure the Makefile and checksum file (${DISTINFO_FILE})"; \
		${ERROR_MSG} "are up to date.  If you want to override this check, type"; \
		${ERROR_MSG} "\"${MAKE} NO_CHECKSUM=yes [other args]\"."; \
		exit 1;							\
	fi

_DISTINFO_CMD=	${SETENV} DIGEST=${TOOLS_DIGEST:Q} SED=${TOOLS_SED:Q}	\
			TEST=${TOOLS_TEST:Q} WC=${TOOLS_WC:Q}		\
		${AWK} -f ${PKGSRCDIR}/mk/checksum/distinfo.awk --

.if exists(${DISTDIR})
_DISTINFO_ARGS_COMMON+=	-d ${DISTDIR}
.endif
.if exists(${DISTINFO_FILE})
_DISTINFO_ARGS_COMMON+=	-f ${DISTINFO_FILE}
.endif
.if defined(_DIGEST_ALGORITHMS) && !empty(_DIGEST_ALGORITHMS)
_DISTINFO_ARGS_COMMON+=	${_DIGEST_ALGORITHMS:S/^/-a /}
.endif
.if defined(_PATCH_DIGEST_ALGORITHMS) && !empty(_PATCH_DIGEST_ALGORITHMS)
_DISTINFO_ARGS_COMMON+=	${_PATCH_DIGEST_ALGORITHMS:S/^/-p /}
.endif

.if defined(_CKSUMFILES) && !empty(_CKSUMFILES)
_DISTINFO_ARGS_DISTSUM+=	${_CKSUMFILES:S/^/-c /}
.endif
.if defined(_IGNOREFILES) && !empty(_IGNOREFILES)
_DISTINFO_ARGS_DISTSUM+=	${_IGNOREFILES:S/^/-i /}
.endif

_DISTINFO_ARGS_PATCHSUM+=	${PATCHDIR}/patch-*
_DISTINFO_ARGS_PATCHSUM+=	${PATCHDIR}/emul-*-patch-*

distinfo:
	${RUN}set -e;							\
	newfile=${DISTINFO_FILE}.$$$$;					\
	if ${_DISTINFO_CMD} ${_DISTINFO_ARGS_COMMON}			\
		${_DISTINFO_ARGS_DISTSUM}				\
		${_DISTINFO_ARGS_PATCHSUM} > $$newfile;			\
	then								\
		${RM} -f $$newfile;					\
		${ECHO_MSG} "=> distinfo: unchanged.";			\
	else								\
		${MV} -f $$newfile ${DISTINFO_FILE};			\
	fi

makesum:
	${RUN}set -e;							\
	newfile=${DISTINFO_FILE}.$$$$;					\
	if ${_DISTINFO_CMD} ${_DISTINFO_ARGS_COMMON}			\
		${_DISTINFO_ARGS_DISTSUM} > $$newfile;			\
	then								\
		${RM} -f $$newfile;					\
		${ECHO_MSG} "=> distinfo: distfiles part unchanged.";	\
	else								\
		${MV} -f $$newfile ${DISTINFO_FILE};			\
	fi

makepatchsum:
	${RUN}set -e;							\
	newfile=${DISTINFO_FILE}.$$$$;					\
	if ${_DISTINFO_CMD} ${_DISTINFO_ARGS_COMMON}			\
		${_DISTINFO_ARGS_PATCHSUM} > $$newfile;			\
	then								\
		${RM} -f $$newfile;					\
		${ECHO_MSG} "=> distinfo: patches part unchanged.";	\
	else								\
		${MV} -f $$newfile ${DISTINFO_FILE};			\
	fi