cond-short.mk revision 1.1 1 # $NetBSD: cond-short.mk,v 1.1 2020/06/28 09:42:40 rillig Exp $
2 #
3 # Demonstrates that in conditions, the right-hand side of an && or ||
4 # is evaluated even though it cannot influence the result.
5 #
6 # This is unexpected for several reasons:
7 #
8 # 1. The manual page says: "bmake will only evaluate a conditional as
9 # far as is necessary to determine its value."
10 #
11 # 2. It differs from the way that these operators are evaluated in
12 # almost all other programming languages.
13 #
14 # 3. In cond.c there are lots of doEval variables.
15 #
16
17 .if 0 && ${echo "unexpected and" 1>&2 :L:sh}
18 .endif
19
20 .if 1 && ${echo "expected and" 1>&2 :L:sh}
21 .endif
22
23 .if 1 || ${echo "unexpected or" 1>&2 :L:sh}
24 .endif
25
26 .if 0 || ${echo "expected or" 1>&2 :L:sh}
27 .endif
28
29 # The following paragraphs demonstrate the workaround.
30
31 .if 0
32 . if ${echo "unexpected nested and" 1>&2 :L:sh}
33 . endif
34 .endif
35
36 .if 1
37 .elif ${echo "unexpected nested or" 1>&2 :L:sh}
38 .endif
39
40 all:
41 @:;:
42