Home | History | Annotate | Line # | Download | only in unit-tests
directive-ifdef.mk revision 1.5
      1  1.5  rillig # $NetBSD: directive-ifdef.mk,v 1.5 2022/01/23 21:48:59 rillig Exp $
      2  1.1  rillig #
      3  1.5  rillig # Tests for the .ifdef directive, which evaluates bare words by calling
      4  1.5  rillig # 'defined(word)'.
      5  1.1  rillig 
      6  1.5  rillig DEFINED=	defined
      7  1.5  rillig 
      8  1.5  rillig # There is no variable named 'UNDEF', therefore the condition evaluates to
      9  1.5  rillig # false.
     10  1.5  rillig .ifdef UNDEF
     11  1.5  rillig .  error
     12  1.5  rillig .endif
     13  1.5  rillig 
     14  1.5  rillig # There is a variable named 'DEFINED', so the condition evaluates to true.
     15  1.5  rillig .ifdef DEFINED
     16  1.5  rillig .else
     17  1.5  rillig .  error
     18  1.5  rillig .endif
     19  1.1  rillig 
     20  1.5  rillig # Since a bare word is an abbreviation for 'defined(word)', these can be
     21  1.5  rillig # used to construct complex conditions.
     22  1.5  rillig .ifdef UNDEF && DEFINED
     23  1.5  rillig .  error
     24  1.5  rillig .endif
     25  1.5  rillig .ifdef UNDEF || DEFINED
     26  1.5  rillig .else
     27  1.5  rillig .  error
     28  1.5  rillig .endif
     29  1.3  rillig 
     30  1.3  rillig # It looks redundant to have a call to defined() in an .ifdef, but it's
     31  1.5  rillig # possible.  The '.ifdef' only affects bare words, not function calls.
     32  1.3  rillig .ifdef defined(DEFINED)
     33  1.3  rillig .else
     34  1.3  rillig .  error
     35  1.3  rillig .endif
     36  1.3  rillig 
     37  1.5  rillig # String literals are handled the same in all variants of the '.if' directive,
     38  1.5  rillig # they evaluate to true if they are not empty, therefore this particular
     39  1.5  rillig # example looks confusing and is thus not found in practice.
     40  1.4  rillig .ifdef ""
     41  1.4  rillig .  error
     42  1.4  rillig .else
     43  1.4  rillig .endif
     44  1.4  rillig 
     45  1.5  rillig # Whitespace counts as non-empty as well.
     46  1.4  rillig .ifdef " "
     47  1.4  rillig .else
     48  1.4  rillig .  error
     49  1.4  rillig .endif
     50  1.4  rillig 
     51  1.5  rillig all: .PHONY
     52