var-op-shell.mk revision 1.3 1 1.3 rillig # $NetBSD: var-op-shell.mk,v 1.3 2020/11/09 20:39:46 rillig Exp $
2 1.1 rillig #
3 1.2 rillig # Tests for the != variable assignment operator, which runs its right-hand
4 1.2 rillig # side through the shell.
5 1.1 rillig
6 1.3 rillig # The variable OUTPUT gets the output from running the shell command.
7 1.3 rillig OUTPUT!= echo "success"'ful'
8 1.3 rillig .if ${OUTPUT} != "successful"
9 1.3 rillig . error
10 1.3 rillig .endif
11 1.3 rillig
12 1.3 rillig # Since 2014-08-20, the output of the shell command may be empty.
13 1.3 rillig #
14 1.3 rillig # On 1996-05-29, when the '!=' assignment operator and Cmd_Exec were added,
15 1.3 rillig # an empty output produced the error message "Couldn't read shell's output
16 1.3 rillig # for \"%s\"".
17 1.3 rillig #
18 1.3 rillig # The error message is still there but reserved for technical errors.
19 1.3 rillig # It may be possible to trigger the error message by killing the shell after
20 1.3 rillig # reading part of its output.
21 1.3 rillig OUTPUT!= true
22 1.3 rillig .if ${OUTPUT} != ""
23 1.3 rillig . error
24 1.3 rillig .endif
25 1.3 rillig
26 1.3 rillig # The output of a shell command that failed is processed nevertheless.
27 1.3 rillig # TODO: Make this an error in lint mode.
28 1.3 rillig OUTPUT!= echo "failed"; false
29 1.3 rillig .if ${OUTPUT} != "failed"
30 1.3 rillig . error
31 1.3 rillig .endif
32 1.3 rillig
33 1.3 rillig # A command with empty output may fail as well.
34 1.3 rillig OUTPUT!= false
35 1.3 rillig .if ${OUTPUT} != ""
36 1.3 rillig . error
37 1.3 rillig .endif
38 1.3 rillig
39 1.3 rillig # In the output of the command, each newline is replaced with a space.
40 1.3 rillig # Except for the very last one, which is discarded.
41 1.3 rillig OUTPUT!= echo "line 1"; echo "line 2"
42 1.3 rillig .if ${OUTPUT} != "line 1 line 2"
43 1.3 rillig . error
44 1.3 rillig .endif
45 1.3 rillig
46 1.3 rillig # A failing command in the middle results in the exit status 0, which in the
47 1.3 rillig # end means that the whole sequence of commands succeeded.
48 1.3 rillig OUTPUT!= echo "before"; false; echo "after"
49 1.3 rillig .if ${OUTPUT} != "before after"
50 1.3 rillig . error
51 1.3 rillig .endif
52 1.3 rillig
53 1.3 rillig # NB: The signal number must be numeric since some shells (which ones?) don't
54 1.3 rillig # accept symbolic signal names. 14 is typically SIGALRM.
55 1.3 rillig #
56 1.3 rillig # XXX: The number of the signal is not mentioned in the warning since that
57 1.3 rillig # would have been difficult to implement; currently the errfmt is a format
58 1.3 rillig # string containing a single %s conversion.
59 1.3 rillig OUTPUT!= kill -14 $$$$
60 1.3 rillig .if ${OUTPUT} != ""
61 1.3 rillig . error
62 1.3 rillig .endif
63 1.3 rillig
64 1.3 rillig # A nonexistent command produces a non-zero exit status.
65 1.3 rillig OUTPUT!= /bin/no/such/command
66 1.3 rillig .if ${OUTPUT} != ""
67 1.3 rillig . error
68 1.3 rillig .endif
69 1.3 rillig
70 1.3 rillig # The output from the shell's stderr is not captured, it just passes through.
71 1.3 rillig OUTPUT!= echo "stdout"; echo "stderr" 1>&2
72 1.3 rillig .if ${OUTPUT} != "stdout"
73 1.3 rillig . error
74 1.3 rillig .endif
75 1.3 rillig
76 1.3 rillig # The 8 dollar signs end up as 4 dollar signs when expanded. The shell sees
77 1.3 rillig # the command "echo '$$$$'". The 4 dollar signs are stored in OUTPUT, and
78 1.3 rillig # when that variable is expanded, they expand to 2 dollar signs.
79 1.3 rillig OUTPUT!= echo '$$$$$$$$'
80 1.3 rillig .if ${OUTPUT} != "\$\$"
81 1.3 rillig . error
82 1.3 rillig .endif
83 1.1 rillig
84 1.1 rillig all:
85