commit 1d704cf0b2455ad6c5f9a70769d5175c6ca09689
parent 99f85528fd9bef81dac4612fed849aafb321dea1
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Fri, 10 Jan 2025 10:19:39 +0100
make: Do not remove targets when using -q
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:
2 files changed, 38 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 && !nflag) {
+ if (!precious && !nflag && !qflag) {
printf("make: trying to remove target %s\n", tp->name);
remove(tp->name);
}
diff --git a/tests/make/execute/0101-signal.sh b/tests/make/execute/0101-signal.sh
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+cleanup()
+{
+ rm -f test.txt
+ kill -KILL $pid 2>/dev/null
+ if test $1 -ne 0
+ then
+ kill -KILL $$
+ fi
+}
+
+rm -f file.txt
+trap 'cleanup 0' EXIT
+trap 'cleanup 1' INT TERM HUP
+
+scc-make -qf - test.txt <<'EOF' &
+test.txt:
+ @+touch $@
+ +@while : ; do sleep 1 ; done
+EOF
+
+pid=$!
+
+sleep 10 && echo timeout >&2 && 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