varmod-assign-shell.mk revision 1.1 1 # $NetBSD: varmod-assign-shell.mk,v 1.1 2021/12/28 00:56:17 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 variable assignment operator '!=', which also assigns
6 # when the shell command fails or crashes.
7 #
8 # The variable modifier '::!=' and its close relatives have been around since
9 # var.c 1.45 from 2000-06-01.
10 #
11 # Before 2020.08.25.21.16.53, the variable modifier '::!=' had a bug for
12 # unsuccessful commands, it put the previous value of the variable into the
13 # error message instead of the command that was executed. That's where the
14 # counterintuitive error message 'make: "previous" returned non-zero status'
15 # comes from.
16 #
17 # BUGS
18 # Even though the variable modifier '::!=' produces an error message,
19 # the exit status of make is still 0.
20 #
21 # Having an error message instead of a warning like for the variable
22 # assignment operator '!=' is another unnecessary inconsistency.
23
24 DIRECT= previous
25 DIRECT!= echo output; false
26
27 ASSIGNED= previous
28 _:= ${ASSIGNED::!=echo output; false}
29
30 all:
31 @echo DIRECT=${DIRECT:Q}
32 @echo ASSIGNED=${ASSIGNED:Q}
33