xref: /freebsd/contrib/bmake/unit-tests/cmd-interrupt.mk (revision a4e5e0106ac7145f56eb39a691e302cabb4635be)
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
20all: clean-before interrupt-ordinary interrupt-phony interrupt-precious clean-after
21
22clean-before clean-after: .PHONY
23	@rm -f cmd-interrupt-ordinary cmd-interrupt-phony cmd-interrupt-precious
24
25interrupt-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
30interrupt-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
35interrupt-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
40cmd-interrupt-ordinary:
41	> ${.TARGET}
42	@kill -INT ${.MAKE.PID}
43
44cmd-interrupt-phony: .PHONY
45	> ${.TARGET}
46	@kill -INT ${.MAKE.PID}
47
48cmd-interrupt-precious: .PRECIOUS
49	> ${.TARGET}
50	@kill -INT ${.MAKE.PID}
51