varmod-assign-shell.mk revision 1.3 1 # $NetBSD: varmod-assign-shell.mk,v 1.3 2022/01/09 18:22:31 rillig Exp $
2 #
3 # Tests for the variable modifier '::!=', which assigns the output of a shell
4 # command to the variable, but only if the command exited successfully. This
5 # is different from the other places that capture the output of an external
6 # command (variable assignment operator '!=', expression modifier ':sh',
7 # expression modifier ':!...!'), which also use the output when the shell
8 # command fails or crashes.
9 #
10 # The variable modifier '::!=' and its close relatives have been around since
11 # var.c 1.45 from 2000-06-01.
12 #
13 # Before 2020.08.25.21.16.53, the variable modifier '::!=' had a bug for
14 # unsuccessful commands, it put the previous value of the variable into the
15 # error message instead of the command that was executed. That's where the
16 # counterintuitive error message 'make: "previous" returned non-zero status'
17 # comes from.
18 #
19 # BUGS
20 # Even though the variable modifier '::!=' produces an error message,
21 # the exit status of make is still 0.
22 #
23 # Having an error message instead of a warning like for the variable
24 # assignment operator '!=' is another unnecessary inconsistency.
25
26 DIRECT= previous
27 DIRECT!= echo output; false
28
29 ASSIGNED= previous
30 _:= ${ASSIGNED::!=echo output; false}
31
32 all:
33 @echo DIRECT=${DIRECT:Q}
34 @echo ASSIGNED=${ASSIGNED:Q}
35