update Mon Mar 15 12:37:00 PDT 2010
[pkgsrc.git] / mk / checksum / checksum.mk
1 # $NetBSD: checksum.mk,v 1.15 2009/07/15 09:40:30 joerg Exp $
2 #
3 # See bsd.checksum.mk for helpful comments.
4 #
5
6 _DIGEST_ALGORITHMS?=            SHA1 RMD160
7 _PATCH_DIGEST_ALGORITHMS?=      SHA1
8
9 # These variables are set by pkgsrc/mk/fetch/bsd.fetch-vars.mk.
10 #_CKSUMFILES?=  # empty
11 #_IGNOREFILES?= # empty
12
13 # _COOKIE.checksum
14 #       The file whose presence determines whether or not the checksum
15 #       process is run.
16 #
17 #       This is not a traditional cookie file.  We do not actually
18 #       wish to create a cookie file for the completion of the checksum
19 #       phase because we want to be able to detect if any of the files
20 #       have changed right up until the distfiles are extracted.
21 #       Therefore, we use the presence of the cookie file from the
22 #       "extract" phase to determine whether we need to continue to
23 #       verify checksums.
24 #
25 #       _COOKIE.extract is defined in pkgsrc/mk/extract/extract.mk.
26 #
27 _COOKIE.checksum=       ${_COOKIE.extract}
28
29 _CHECKSUM_CMD=                                                          \
30         ${SETENV} DIGEST=${TOOLS_DIGEST:Q} CAT=${TOOLS_CAT:Q}           \
31                 ECHO=${TOOLS_ECHO:Q} SED=${TOOLS_SED:Q}                 \
32                 TEST=${TOOLS_TEST:Q}                                    \
33         ${SH} ${PKGSRCDIR}/mk/checksum/checksum                         \
34
35 .if defined(NO_CHECKSUM) || empty(_CKSUMFILES)
36 checksum checksum-phase:
37         @${DO_NADA}
38 .else
39 checksum checksum-phase:
40         ${RUN} set -e;                                                  \
41         case ${.TARGET:Q} in                                            \
42         *-phase)        ${TEST} ! -f ${_COOKIE.checksum} || exit 0 ;;   \
43         esac;                                                           \
44         if cd ${DISTDIR} && ${_CHECKSUM_CMD} ${DISTINFO_FILE} ${_CKSUMFILES}; then \
45                 ${TRUE};                                                \
46         else                                                            \
47                 ${ERROR_MSG} "Make sure the Makefile and checksum file (${DISTINFO_FILE})"; \
48                 ${ERROR_MSG} "are up to date.  If you want to override this check, type"; \
49                 ${ERROR_MSG} "\"${MAKE} NO_CHECKSUM=yes [other args]\"."; \
50                 exit 1;                                                 \
51         fi
52 .endif
53
54 _DISTINFO_CMD=  ${SETENV} DIGEST=${TOOLS_DIGEST:Q} SED=${TOOLS_SED:Q}   \
55                         TEST=${TOOLS_TEST:Q} WC=${TOOLS_WC:Q}           \
56                 ${AWK} -f ${PKGSRCDIR}/mk/checksum/distinfo.awk --
57
58 .if exists(${DISTDIR})
59 _DISTINFO_ARGS_COMMON+= -d ${DISTDIR}
60 .endif
61 .if exists(${DISTINFO_FILE})
62 _DISTINFO_ARGS_COMMON+= -f ${DISTINFO_FILE}
63 .endif
64 .if defined(_DIGEST_ALGORITHMS) && !empty(_DIGEST_ALGORITHMS)
65 _DISTINFO_ARGS_COMMON+= ${_DIGEST_ALGORITHMS:S/^/-a /}
66 .endif
67 .if defined(_PATCH_DIGEST_ALGORITHMS) && !empty(_PATCH_DIGEST_ALGORITHMS)
68 _DISTINFO_ARGS_COMMON+= ${_PATCH_DIGEST_ALGORITHMS:S/^/-p /}
69 .endif
70
71 .if defined(_CKSUMFILES) && !empty(_CKSUMFILES)
72 _DISTINFO_ARGS_DISTSUM+=        ${_CKSUMFILES:S/^/-c /}
73 .endif
74 .if defined(_IGNOREFILES) && !empty(_IGNOREFILES)
75 _DISTINFO_ARGS_DISTSUM+=        ${_IGNOREFILES:S/^/-i /}
76 .endif
77
78 _DISTINFO_ARGS_PATCHSUM+=       ${PATCHDIR}/patch-*
79 _DISTINFO_ARGS_PATCHSUM+=       ${PATCHDIR}/emul-*-patch-*
80
81 distinfo:
82         ${RUN}set -e;                                                   \
83         newfile=${DISTINFO_FILE}.$$$$;                                  \
84         if ${_DISTINFO_CMD} ${_DISTINFO_ARGS_COMMON}                    \
85                 ${_DISTINFO_ARGS_DISTSUM}                               \
86                 ${_DISTINFO_ARGS_PATCHSUM} > $$newfile;                 \
87         then                                                            \
88                 ${RM} -f $$newfile;                                     \
89                 ${ECHO_MSG} "=> distinfo: unchanged.";                  \
90         else                                                            \
91                 ${MV} -f $$newfile ${DISTINFO_FILE};                    \
92         fi
93
94 makesum:
95         ${RUN}set -e;                                                   \
96         newfile=${DISTINFO_FILE}.$$$$;                                  \
97         if ${_DISTINFO_CMD} ${_DISTINFO_ARGS_COMMON}                    \
98                 ${_DISTINFO_ARGS_DISTSUM} > $$newfile;                  \
99         then                                                            \
100                 ${RM} -f $$newfile;                                     \
101                 ${ECHO_MSG} "=> distinfo: distfiles part unchanged.";   \
102         else                                                            \
103                 ${MV} -f $$newfile ${DISTINFO_FILE};                    \
104         fi
105
106 makepatchsum:
107         ${RUN}set -e;                                                   \
108         newfile=${DISTINFO_FILE}.$$$$;                                  \
109         if ${_DISTINFO_CMD} ${_DISTINFO_ARGS_COMMON}                    \
110                 ${_DISTINFO_ARGS_PATCHSUM} > $$newfile;                 \
111         then                                                            \
112                 ${RM} -f $$newfile;                                     \
113                 ${ECHO_MSG} "=> distinfo: patches part unchanged.";     \
114         else                                                            \
115                 ${MV} -f $$newfile ${DISTINFO_FILE};                    \
116         fi
117
118 .PHONY: depends-checksum
119 depends-checksum:
120         ${RUN}                                                          \
121         ${_DEPENDS_WALK_CMD} ${PKGPATH} |                               \
122         while read dir; do                                              \
123                 ${ECHO} "===> Checksumming for $${dir}" &&              \
124                 cd ${.CURDIR}/../../$$dir &&                            \
125                 ${RECURSIVE_MAKE} ${MAKEFLAGS} checksum;                \
126         done