Add files from parent branch HEAD:
[pkgsrc.git] / mk / bsd.pkg.error.mk
1 # $NetBSD: bsd.pkg.error.mk,v 1.3 2006/10/06 19:05:43 rillig Exp $
2
3 ERROR_DIR=              ${WRKDIR}/.error
4 WARNING_DIR=            ${WRKDIR}/.warning
5 _ERROR_DONE_DIR=        ${WRKDIR}/.error-done
6 _WARNING_DONE_DIR=      ${WRKDIR}/.warning-done
7
8 # Macros for outputting delayed error and warning messages that are
9 # picked up by the error-check target and can be used in place of
10 # ${ECHO}.  We output to files that are named without leading dots.
11 #
12 DELAYED_ERROR_MSG?=     ${ECHO} >> ${ERROR_DIR}/${.TARGET:T:C/^[.]*//:Q}
13 DELAYED_WARNING_MSG?=   ${ECHO} >> ${WARNING_DIR}/${.TARGET:T:C/^[.]*//:Q}
14
15 makedirs: ${ERROR_DIR} ${WARNING_DIR} ${_ERROR_DONE_DIR} ${_WARNING_DONE_DIR}
16 ${ERROR_DIR} ${WARNING_DIR} ${_ERROR_DONE_DIR} ${_WARNING_DONE_DIR}:
17         ${RUN}${MKDIR} ${.TARGET}
18
19 .PHONY: error-check
20
21 ######################################################################
22 ### error-check (PRIVATE)
23 ######################################################################
24 ### error-check is a macro target that will peek in the warning and
25 ### error directories to check for the presence of any files.  If they
26 ### exist and are non-empty, then they are assumed to be message files
27 ### and will be outputted then removed.  If they are from the error
28 ### directory, then the target will fail.
29 ###
30 error-check: .USE
31         ${RUN}                                  \
32         ${RM} -f ${WARNING_DIR}/*.tmp;                                  \
33         ${TEST} -d ${WARNING_DIR} || exit 0;                            \
34         cd ${WARNING_DIR};                                              \
35         for file in ./*; do                                             \
36                 ${TEST} "$$file" != "./*" || exit 0;                    \
37                 break;                                                  \
38         done;                                                           \
39         ${CAT} ./* | ${WARNING_CAT};                                    \
40         ${MV} -f ./* ${_WARNING_DONE_DIR}
41
42         ${RUN}                                  \
43         ${RM} -f ${ERROR_DIR}/*.tmp;                                    \
44         ${TEST} -d ${ERROR_DIR} || exit 0;                              \
45         cd ${ERROR_DIR};                                                \
46         for file in ./*; do                                             \
47                 ${TEST} "$$file" != "./*" || exit 0;                    \
48                 break;                                                  \
49         done;                                                           \
50         ${CAT} * | ${ERROR_CAT};                                        \
51         if ${_NONZERO_FILESIZE_P} ./*; then                             \
52                 ${MV} -f ./* ${_ERROR_DONE_DIR};                        \
53                 exit 1;                                                 \
54         fi
55
56 ######################################################################
57 ### error-clean (PRIVATE)
58 ######################################################################
59 ### error-clean removes the error and warning directory and files.
60 ###
61 error-clean:
62         ${RUN}${RM} -fr ${ERROR_DIR} ${WARNING_DIR}