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