cmd-interrupt.mk revision 1.4 1 # $NetBSD: cmd-interrupt.mk,v 1.4 2023/03/18 22:20:12 sjg Exp $
2 #
3 # Tests for interrupting a command.
4 #
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
7 # would be newer than all of its sources and would therefore not be
8 # tried again in the next run.
9 #
10 # This happens for ordinary targets as well as for .PHONY targets, even
11 # though the .PHONY targets usually do not correspond to a file.
12 #
13 # To protect the target from being removed, the target has to be marked with
14 # the special source .PRECIOUS. These targets need to ensure for themselves
15 # that interrupting them does not leave an inconsistent state behind.
16 #
17 # See also:
18 # CompatDeleteTarget
19
20 all: clean-before interrupt-ordinary interrupt-phony interrupt-precious clean-after
21
22 clean-before clean-after: .PHONY
23 @rm -f cmd-interrupt-ordinary cmd-interrupt-phony cmd-interrupt-precious
24
25 interrupt-ordinary:
26 @${.MAKE} ${MAKEFLAGS} -f ${MAKEFILE} cmd-interrupt-ordinary || true
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) :? ok : error }
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 }
39
40 cmd-interrupt-ordinary:
41 > ${.TARGET}
42 @kill -INT ${.MAKE.PID}
43
44 cmd-interrupt-phony: .PHONY
45 > ${.TARGET}
46 @kill -INT ${.MAKE.PID}
47
48 cmd-interrupt-precious: .PRECIOUS
49 > ${.TARGET}
50 @kill -INT ${.MAKE.PID}
51