1 1.7 rillig # $NetBSD: directive-ifmake.mk,v 1.7 2020/11/11 07:13:42 rillig Exp $ 2 1.1 rillig # 3 1.3 rillig # Tests for the .ifmake directive, which provides a shortcut for asking 4 1.3 rillig # whether a certain target is requested to be made from the command line. 5 1.1 rillig 6 1.7 rillig # The targets 'first' and 'second' are passed in on the command line. 7 1.7 rillig 8 1.3 rillig # This is the most basic form. 9 1.3 rillig .ifmake first 10 1.5 rillig . info ok: positive condition works 11 1.3 rillig .else 12 1.5 rillig . warning positive condition fails 13 1.3 rillig .endif 14 1.1 rillig 15 1.3 rillig # The not operator works as expected. 16 1.3 rillig # An alternative interpretation were that this condition is asking whether 17 1.3 rillig # the target "!first" was requested. To distinguish this, see the next test. 18 1.3 rillig .ifmake !first 19 1.5 rillig . warning unexpected 20 1.3 rillig .else 21 1.5 rillig . info ok: negation works 22 1.3 rillig .endif 23 1.3 rillig 24 1.3 rillig # See if the exclamation mark really means "not", or if it is just part of 25 1.3 rillig # the target name. 26 1.3 rillig .ifmake !!first 27 1.5 rillig . info ok: double negation works 28 1.3 rillig .else 29 1.5 rillig . warning double negation fails 30 1.3 rillig .endif 31 1.3 rillig 32 1.3 rillig # Multiple targets can be combined using the && and || operators. 33 1.3 rillig .ifmake first && second 34 1.5 rillig . info ok: both mentioned 35 1.3 rillig .else 36 1.5 rillig . warning && does not work as expected 37 1.3 rillig .endif 38 1.3 rillig 39 1.3 rillig # Negation also works in complex conditions. 40 1.3 rillig .ifmake first && !unmentioned 41 1.5 rillig . info ok: only those mentioned 42 1.3 rillig .else 43 1.5 rillig . warning && with ! does not work as expected 44 1.3 rillig .endif 45 1.3 rillig 46 1.4 rillig # Using the .MAKEFLAGS special dependency target, arbitrary command 47 1.4 rillig # line options can be added at parse time. This means that it is 48 1.4 rillig # possible to extend the targets to be made. 49 1.4 rillig .MAKEFLAGS: late-target 50 1.4 rillig .ifmake late-target 51 1.5 rillig . info Targets can even be added at parse time. 52 1.4 rillig .else 53 1.5 rillig . info No, targets cannot be added at parse time anymore. 54 1.4 rillig .endif 55 1.4 rillig 56 1.6 rillig # Numbers are interpreted as numbers, no matter whether the directive is 57 1.6 rillig # a plain .if or an .ifmake. 58 1.6 rillig .ifmake 0 59 1.6 rillig . error 60 1.6 rillig .endif 61 1.6 rillig .ifmake 1 62 1.6 rillig .else 63 1.6 rillig . error 64 1.6 rillig .endif 65 1.6 rillig 66 1.7 rillig # A condition that consists of a variable expression only (without any 67 1.7 rillig # comparison operator) can be used with .if and the other .ifxxx directives. 68 1.7 rillig .ifmake ${:Ufirst} 69 1.7 rillig . info ok 70 1.7 rillig .else 71 1.7 rillig . error 72 1.7 rillig .endif 73 1.7 rillig 74 1.7 rillig 75 1.4 rillig first second unmentioned late-target: 76 1.3 rillig : $@ 77