varmod-assign-shell.mk revision 1.7 1 1.7 rillig # $NetBSD: varmod-assign-shell.mk,v 1.7 2024/06/30 11:44:14 rillig Exp $
2 1.1 rillig #
3 1.1 rillig # Tests for the variable modifier '::!=', which assigns the output of a shell
4 1.1 rillig # command to the variable, but only if the command exited successfully. This
5 1.3 rillig # is different from the other places that capture the output of an external
6 1.3 rillig # command (variable assignment operator '!=', expression modifier ':sh',
7 1.3 rillig # expression modifier ':!...!'), which also use the output when the shell
8 1.3 rillig # command fails or crashes.
9 1.1 rillig #
10 1.1 rillig # The variable modifier '::!=' and its close relatives have been around since
11 1.1 rillig # var.c 1.45 from 2000-06-01.
12 1.1 rillig #
13 1.1 rillig # Before 2020.08.25.21.16.53, the variable modifier '::!=' had a bug for
14 1.1 rillig # unsuccessful commands, it put the previous value of the variable into the
15 1.1 rillig # error message instead of the command that was executed. That's where the
16 1.1 rillig # counterintuitive error message 'make: "previous" returned non-zero status'
17 1.1 rillig # comes from.
18 1.1 rillig
19 1.2 rillig DIRECT= previous
20 1.6 rillig # expect+1: warning: Command "echo output; (exit 13)" exited with status 13
21 1.6 rillig DIRECT!= echo output; (exit 13)
22 1.1 rillig
23 1.2 rillig ASSIGNED= previous
24 1.7 rillig .MAKEFLAGS: -dv # to see the "Capturing" debug output
25 1.7 rillig # expect+1: warning: while evaluating variable "ASSIGNED": Command "echo output; (exit 13)" exited with status 13
26 1.6 rillig _:= ${ASSIGNED::!=echo output; ${:U(exit 13)}}
27 1.4 rillig .MAKEFLAGS: -d0
28 1.1 rillig
29 1.1 rillig all:
30 1.1 rillig @echo DIRECT=${DIRECT:Q}
31 1.1 rillig @echo ASSIGNED=${ASSIGNED:Q}
32