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