1 1.3 rillig # $NetBSD: cond-op.mk,v 1.3 2020/08/28 13:50:48 rillig Exp $ 2 1.1 rillig # 3 1.2 rillig # Tests for operators like &&, ||, ! in .if conditions. 4 1.3 rillig # 5 1.3 rillig # See also: 6 1.3 rillig # cond-op-and.mk 7 1.3 rillig # cond-op-not.mk 8 1.3 rillig # cond-op-or.mk 9 1.3 rillig # cond-op-parentheses.mk 10 1.3 rillig 11 1.3 rillig # In make, && binds more tightly than ||, like in C. 12 1.3 rillig # If make had the same precedence for both && and ||, the result would be 13 1.3 rillig # different. 14 1.3 rillig # If || were to bind more tightly than &&, the result would be different 15 1.3 rillig # as well. 16 1.3 rillig .if !(1 || 1 && 0) 17 1.3 rillig .error 18 1.3 rillig .endif 19 1.3 rillig 20 1.3 rillig # If make were to interpret the && and || operators like the shell, the 21 1.3 rillig # implicit binding would be this: 22 1.3 rillig .if (1 || 1) && 0 23 1.3 rillig .error 24 1.3 rillig .endif 25 1.3 rillig 26 1.3 rillig # The precedence of the ! operator is different from C though. It has a 27 1.3 rillig # lower precedence than the comparison operators. 28 1.3 rillig .if !"word" == "word" 29 1.3 rillig .error 30 1.3 rillig .endif 31 1.3 rillig 32 1.3 rillig # This is how the above condition is actually interpreted. 33 1.3 rillig .if !("word" == "word") 34 1.3 rillig .error 35 1.3 rillig .endif 36 1.1 rillig 37 1.3 rillig # TODO: Demonstrate that the precedence of the ! and == operators actually 38 1.3 rillig # makes a difference. There is a simple example for sure, I just cannot 39 1.3 rillig # wrap my head around it. 40 1.1 rillig 41 1.1 rillig all: 42 1.1 rillig @:; 43