1 # $NetBSD: cmd-interrupt.mk,v 1.2 2020/08/28 18:16:22 rillig Exp $
3 # Tests for interrupting a command.
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.
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.
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.
20 all: clean-before interrupt-ordinary interrupt-phony interrupt-precious clean-after
22 clean-before clean-after: .PHONY
23 @rm -f cmd-interrupt-ordinary cmd-interrupt-phony cmd-interrupt-precious
25 interrupt-ordinary: .PHONY
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 }
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 }
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 }
40 cmd-interrupt-ordinary:
42 @kill -INT ${.MAKE.PID}
44 cmd-interrupt-phony: .PHONY
46 @kill -INT ${.MAKE.PID}
48 cmd-interrupt-precious: .PRECIOUS
50 @kill -INT ${.MAKE.PID}