2c88efad6f
In the first version of this test, I had completely misunderstood the whole topic. To test the interrupt, the make process has to be interrupted, not the shell. This generates the correct message that the target is removed. The filename for .PHONY targets is removed even though .PHONY targets usually don't correspond to a file. The message is only printed if there actually is a corresponding file. That's why this message does not appear when interrupting "make clean". Finally, since files get created and removed during a single run of make, the file cache needs to be disabled. This is done by prefixing the filenames with "././", see Dir_FindFile.
51 lines
1.8 KiB
Makefile
51 lines
1.8 KiB
Makefile
# $NetBSD: cmd-interrupt.mk,v 1.2 2020/08/28 18:16:22 rillig Exp $
|
|
#
|
|
# Tests for interrupting a command.
|
|
#
|
|
# If a command is interrupted (usually by the user, here by itself), the
|
|
# target is removed. This is to avoid having an unfinished target that
|
|
# would be newer than all of its sources and would therefore not be
|
|
# tried again in the next run.
|
|
#
|
|
# This happens for ordinary targets as well as for .PHONY targets, even
|
|
# though the .PHONY targets usually do not correspond to a file.
|
|
#
|
|
# To protect the target from being removed, the target has to be marked with
|
|
# the special source .PRECIOUS. These targets need to ensure for themselves
|
|
# that interrupting them does not leave an inconsistent state behind.
|
|
#
|
|
# See also:
|
|
# CompatDeleteTarget
|
|
|
|
all: clean-before interrupt-ordinary interrupt-phony interrupt-precious clean-after
|
|
|
|
clean-before clean-after: .PHONY
|
|
@rm -f cmd-interrupt-ordinary cmd-interrupt-phony cmd-interrupt-precious
|
|
|
|
interrupt-ordinary: .PHONY
|
|
@${.MAKE} ${MAKEFLAGS} -f ${MAKEFILE} cmd-interrupt-ordinary || true
|
|
# The ././ is necessary to work around the file cache.
|
|
@echo ${.TARGET}: ${exists(././cmd-interrupt-ordinary) :? error : ok }
|
|
|
|
interrupt-phony: .PHONY
|
|
@${.MAKE} ${MAKEFLAGS} -f ${MAKEFILE} cmd-interrupt-phony || true
|
|
# The ././ is necessary to work around the file cache.
|
|
@echo ${.TARGET}: ${exists(././cmd-interrupt-phony) :? error : ok }
|
|
|
|
interrupt-precious: .PRECIOUS
|
|
@${.MAKE} ${MAKEFLAGS} -f ${MAKEFILE} cmd-interrupt-precious || true
|
|
# The ././ is necessary to work around the file cache.
|
|
@echo ${.TARGET}: ${exists(././cmd-interrupt-precious) :? ok : error }
|
|
|
|
cmd-interrupt-ordinary:
|
|
> ${.TARGET}
|
|
@kill -INT ${.MAKE.PID}
|
|
|
|
cmd-interrupt-phony: .PHONY
|
|
> ${.TARGET}
|
|
@kill -INT ${.MAKE.PID}
|
|
|
|
cmd-interrupt-precious: .PRECIOUS
|
|
> ${.TARGET}
|
|
@kill -INT ${.MAKE.PID}
|