scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 579cb416287ce2df8d4276726a42f5fa7e778311
parent 08f9ec8a609965cecbb560144d0890efed8910ca
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri, 10 Jan 2025 10:19:39 +0100

make: Do not remove targets when using -n

As specified by the POSIX specification:

	If not already ignored, make shall trap SIGHUP, SIGTERM, SIGINT,
	and SIGQUIT and remove the current target unless the target
	is a directory or the target is a prerequisite of the special
	target .PRECIOUS or unless one of the -n, -p, or -q options
	was specified.	Any targets removed in this manner shall be
	reported in diagnostic messages of unspecified format, written
	to standard error.  After this cleanup process, if any, make
	shall take the standard action for all other signals.

Diffstat:
Msrc/cmd/scc-make/rules.c | 2+-
Atests/make/execute/0099-signal.sh | 36++++++++++++++++++++++++++++++++++++
2 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/src/cmd/scc-make/rules.c b/src/cmd/scc-make/rules.c @@ -454,7 +454,7 @@ cleanup(Target *tp) } } - if (!precious) { + if (!precious && !nflag) { printf("make: trying to remove target %s\n", tp->name); remove(tp->name); } diff --git a/tests/make/execute/0099-signal.sh b/tests/make/execute/0099-signal.sh @@ -0,0 +1,36 @@ +#!/bin/sh + +cleanup() +{ + rm -f test.txt + kill -KILL $pid 2>/dev/null + if test $1 -ne 0 + then + kill -KILL $$ + fi +} + +trap 'cleanup 0' EXIT +trap 'cleanup 1' INT TERM HUP + +scc-make -nf - test.txt <<'EOF' & +test.txt: + @+touch $@ + +@while : ; do sleep 1 ; done +EOF + +pid=$! + +sleep 10 && kill $$ 2>/dev/null & + +while : +do + if test -f test.txt + then + kill $pid 2>/dev/null + wait $pid + break + fi +done + +test -f test.txt