| @@ -1,35 +1,50 @@ | | | @@ -1,35 +1,50 @@ |
1 | # $NetBSD: cmd-interrupt.mk,v 1.1 2020/08/28 15:40:53 rillig Exp $ | | 1 | # $NetBSD: cmd-interrupt.mk,v 1.2 2020/08/28 18:16:22 rillig Exp $ |
2 | # | | 2 | # |
3 | # Tests for interrupting a command. | | 3 | # Tests for interrupting a command. |
4 | # | | 4 | # |
5 | # If a command is interrupted (usually by the user, here by itself), the | | 5 | # If a command is interrupted (usually by the user, here by itself), the |
6 | # target is removed. This is to avoid having an unfinished target that | | 6 | # target is removed. This is to avoid having an unfinished target that |
7 | # would be newer than all of its sources and would therefore not be | | 7 | # would be newer than all of its sources and would therefore not be |
8 | # tried again in the next run. | | 8 | # tried again in the next run. |
9 | # | | 9 | # |
10 | # For .PHONY targets, there is usually no corresponding file and therefore | | 10 | # This happens for ordinary targets as well as for .PHONY targets, even |
11 | # nothing that could be removed. These .PHONY targets need to ensure for | | 11 | # though the .PHONY targets usually do not correspond to a file. |
12 | # themselves that interrupting them does not leave an inconsistent state | | 12 | # |
13 | # behind. | | 13 | # To protect the target from being removed, the target has to be marked with |
14 | | | 14 | # the special source .PRECIOUS. These targets need to ensure for themselves |
15 | SELF:= ${.PARSEDIR}/${.PARSEFILE} | | 15 | # that interrupting them does not leave an inconsistent state behind. |
16 | | | 16 | # |
17 | _!= rm -f cmd-interrupt-ordinary cmd-interrupt-phony | | 17 | # See also: |
| | | 18 | # CompatDeleteTarget |
18 | | | 19 | |
19 | all: interrupt-ordinary interrupt-phony | | 20 | all: clean-before interrupt-ordinary interrupt-phony interrupt-precious clean-after |
20 | | | 21 | |
21 | interrupt-ordinary: | | 22 | clean-before clean-after: .PHONY |
22 | ${.MAKE} ${MAKEFLAGS} -f ${SELF} cmd-interrupt-ordinary || true | | 23 | @rm -f cmd-interrupt-ordinary cmd-interrupt-phony cmd-interrupt-precious |
23 | @echo ${exists(cmd-interrupt-ordinary) :? error : ok } | | | |
24 | | | 24 | |
25 | interrupt-phony: | | 25 | interrupt-ordinary: .PHONY |
26 | ${.MAKE} ${MAKEFLAGS} -f ${SELF} cmd-interrupt-phony || true | | 26 | @${.MAKE} ${MAKEFLAGS} -f ${MAKEFILE} cmd-interrupt-ordinary || true |
27 | @echo ${exists(cmd-interrupt-phony) :? ok : error } | | 27 | # The ././ is necessary to work around the file cache. |
| | | 28 | @echo ${.TARGET}: ${exists(././cmd-interrupt-ordinary) :? error : ok } |
| | | 29 | |
| | | 30 | interrupt-phony: .PHONY |
| | | 31 | @${.MAKE} ${MAKEFLAGS} -f ${MAKEFILE} cmd-interrupt-phony || true |
| | | 32 | # The ././ is necessary to work around the file cache. |
| | | 33 | @echo ${.TARGET}: ${exists(././cmd-interrupt-phony) :? error : ok } |
| | | 34 | |
| | | 35 | interrupt-precious: .PRECIOUS |
| | | 36 | @${.MAKE} ${MAKEFLAGS} -f ${MAKEFILE} cmd-interrupt-precious || true |
| | | 37 | # The ././ is necessary to work around the file cache. |
| | | 38 | @echo ${.TARGET}: ${exists(././cmd-interrupt-precious) :? ok : error } |
28 | | | 39 | |
29 | cmd-interrupt-ordinary: | | 40 | cmd-interrupt-ordinary: |
30 | > ${.TARGET} | | 41 | > ${.TARGET} |
31 | kill -INT $$$$ | | 42 | @kill -INT ${.MAKE.PID} |
32 | | | 43 | |
33 | cmd-interrupt-phony: .PHONY | | 44 | cmd-interrupt-phony: .PHONY |
34 | > ${.TARGET} | | 45 | > ${.TARGET} |
35 | kill -INT $$$$ | | 46 | @kill -INT ${.MAKE.PID} |
| | | 47 | |
| | | 48 | cmd-interrupt-precious: .PRECIOUS |
| | | 49 | > ${.TARGET} |
| | | 50 | @kill -INT ${.MAKE.PID} |