Home | History | Annotate | Line # | Download | only in unit-tests
      1  1.5  rillig # $NetBSD: varname-dot-suffixes.mk,v 1.5 2023/12/20 09:03:09 rillig Exp $
      2  1.1  rillig #
      3  1.1  rillig # Tests for the special "variable" .SUFFIXES, which lists the suffixes that
      4  1.1  rillig # have been registered for use in suffix transformation rules.  Suffixes are
      5  1.1  rillig # listed even if there is no actual transformation rule that uses them.
      6  1.1  rillig #
      7  1.1  rillig # The name '.SUFFIXES' does not refer to a real variable, instead it can be
      8  1.1  rillig # used as a starting "variable name" for expressions like ${.SUFFIXES} or
      9  1.1  rillig # ${.SUFFIXES:M*o}.
     10  1.1  rillig 
     11  1.1  rillig # In the beginning, there are no suffix rules, the expression is thus empty.
     12  1.1  rillig .if ${.SUFFIXES} != ""
     13  1.1  rillig .endif
     14  1.1  rillig 
     15  1.1  rillig # There is no actual variable named '.SUFFIXES', it is all made up.
     16  1.1  rillig .if defined(.SUFFIXES)
     17  1.1  rillig .  error
     18  1.1  rillig .endif
     19  1.1  rillig 
     20  1.1  rillig # The suffixes list is still empty, and so is the "variable" '.SUFFIXES'.
     21  1.1  rillig .if !empty(.SUFFIXES)
     22  1.1  rillig .  error
     23  1.1  rillig .endif
     24  1.1  rillig 
     25  1.1  rillig .SUFFIXES: .c .o .1		.err
     26  1.1  rillig 
     27  1.1  rillig # The suffixes are listed in declaration order.
     28  1.1  rillig .if ${.SUFFIXES} != ".c .o .1 .err"
     29  1.1  rillig .  error
     30  1.1  rillig .endif
     31  1.1  rillig 
     32  1.1  rillig # There is still no actual variable named '.SUFFIXES', it is all made up.
     33  1.1  rillig .if defined(.SUFFIXES)
     34  1.1  rillig .  error
     35  1.1  rillig .endif
     36  1.1  rillig 
     37  1.1  rillig # Now the suffixes list is not empty anymore.  It may seem strange that there
     38  1.1  rillig # is no variable named '.SUFFIXES' but evaluating '${.SUFFIXES}' nevertheless
     39  1.1  rillig # returns something.  For all practical use cases, it's good enough though.
     40  1.1  rillig .if empty(.SUFFIXES)
     41  1.1  rillig .  error
     42  1.1  rillig .endif
     43  1.1  rillig 
     44  1.1  rillig .SUFFIXES: .tar.gz
     45  1.1  rillig 
     46  1.1  rillig # Changes to the suffixes list are reflected immediately.
     47  1.1  rillig .if ${.SUFFIXES} != ".c .o .1 .err .tar.gz"
     48  1.1  rillig .  error
     49  1.1  rillig .endif
     50  1.1  rillig 
     51  1.1  rillig # Deleting .SUFFIXES has no effect since there is no actual variable of that
     52  1.1  rillig # name.
     53  1.1  rillig .MAKEFLAGS: -dv
     54  1.4  rillig # expect: Global: ignoring delete '.SUFFIXES' as it is not found
     55  1.1  rillig .undef .SUFFIXES
     56  1.1  rillig .MAKEFLAGS: -d0
     57  1.1  rillig .if ${.SUFFIXES} != ".c .o .1 .err .tar.gz"
     58  1.1  rillig .  error
     59  1.1  rillig .endif
     60  1.1  rillig 
     61  1.1  rillig # The list of suffixes can only be modified using dependency declarations, any
     62  1.1  rillig # attempt at setting the variable named '.SUFFIXES' is rejected.
     63  1.1  rillig .MAKEFLAGS: -dv
     64  1.5  rillig # expect: Global: ignoring '.SUFFIXES = set' as it is read-only
     65  1.1  rillig .SUFFIXES=	set
     66  1.5  rillig # expect: Global: ignoring '.SUFFIXES = append' as it is read-only
     67  1.1  rillig .SUFFIXES+=	append
     68  1.5  rillig # expect: Global: ignoring '.SUFFIXES = assign' as it is read-only
     69  1.1  rillig _:=		${.SUFFIXES::=assign}
     70  1.5  rillig # expect: Global: ignoring '.SUFFIXES = preserve' as it is read-only
     71  1.1  rillig _:=		${preserve:L:_=.SUFFIXES}
     72  1.1  rillig .MAKEFLAGS: -d0
     73  1.1  rillig 
     74  1.1  rillig # Using the name '.SUFFIXES' in a .for loop looks strange because these
     75  1.1  rillig # variable names are typically in singular form, and .for loops do not use
     76  1.1  rillig # real variables either, they are made up as well, see directive-for.mk.  The
     77  1.1  rillig # replacement mechanism for the iteration variables takes precedence.
     78  1.1  rillig .for .SUFFIXES in .c .o
     79  1.1  rillig .  if ${.SUFFIXES} != ".c" && ${.SUFFIXES} != ".o"
     80  1.1  rillig .    error
     81  1.1  rillig .  endif
     82  1.1  rillig .endfor
     83  1.1  rillig 
     84  1.1  rillig # After the .for loop, the expression '${.SUFFIXES}' refers to the list of
     85  1.1  rillig # suffixes again.
     86  1.1  rillig .if ${.SUFFIXES} != ".c .o .1 .err .tar.gz"
     87  1.1  rillig .  error
     88  1.1  rillig .endif
     89  1.1  rillig 
     90  1.1  rillig # Using the name '.SUFFIXES' in the modifier ':@var@body@' does not create an
     91  1.1  rillig # actual variable either.  Like in the .for loop, choosing the name
     92  1.1  rillig # '.SUFFIXES' for the iteration variable is unusual.  In ODE Make, the
     93  1.1  rillig # convention for these iteration variables is to have dots at both ends, so
     94  1.1  rillig # the name would be '.SUFFIXES.', furthermore the name of the iteration
     95  1.1  rillig # variable is typically in singular form.
     96  1.1  rillig .MAKEFLAGS: -dv
     97  1.5  rillig # expect: Command: ignoring '.SUFFIXES = 1' as it is read-only
     98  1.5  rillig # expect: Command: ignoring '.SUFFIXES = 2' as it is read-only
     99  1.4  rillig # expect: Command: ignoring delete '.SUFFIXES' as it is not found
    100  1.1  rillig .if ${1 2:L:@.SUFFIXES@${.SUFFIXES}@} != ".c .o .1 .err .tar.gz .c .o .1 .err .tar.gz"
    101  1.1  rillig .  error
    102  1.1  rillig .endif
    103  1.1  rillig .MAKEFLAGS: -d0
    104  1.1  rillig 
    105  1.1  rillig all:
    106