1*394d03c6Srillig# $NetBSD: varname-dot-suffixes.mk,v 1.3 2022/04/15 09:33:20 rillig Exp $
22ec6e74eSrillig#
32ec6e74eSrillig# Tests for the special "variable" .SUFFIXES, which lists the suffixes that
42ec6e74eSrillig# have been registered for use in suffix transformation rules.  Suffixes are
52ec6e74eSrillig# listed even if there is no actual transformation rule that uses them.
62ec6e74eSrillig#
72ec6e74eSrillig# The name '.SUFFIXES' does not refer to a real variable, instead it can be
82ec6e74eSrillig# used as a starting "variable name" for expressions like ${.SUFFIXES} or
92ec6e74eSrillig# ${.SUFFIXES:M*o}.
102ec6e74eSrillig
112ec6e74eSrillig# In the beginning, there are no suffix rules, the expression is thus empty.
122ec6e74eSrillig.if ${.SUFFIXES} != ""
132ec6e74eSrillig.endif
142ec6e74eSrillig
152ec6e74eSrillig# There is no actual variable named '.SUFFIXES', it is all made up.
162ec6e74eSrillig.if defined(.SUFFIXES)
172ec6e74eSrillig.  error
182ec6e74eSrillig.endif
192ec6e74eSrillig
202ec6e74eSrillig# The suffixes list is still empty, and so is the "variable" '.SUFFIXES'.
212ec6e74eSrillig.if !empty(.SUFFIXES)
222ec6e74eSrillig.  error
232ec6e74eSrillig.endif
242ec6e74eSrillig
252ec6e74eSrillig.SUFFIXES: .c .o .1		.err
262ec6e74eSrillig
272ec6e74eSrillig# The suffixes are listed in declaration order.
282ec6e74eSrillig.if ${.SUFFIXES} != ".c .o .1 .err"
292ec6e74eSrillig.  error
302ec6e74eSrillig.endif
312ec6e74eSrillig
322ec6e74eSrillig# There is still no actual variable named '.SUFFIXES', it is all made up.
332ec6e74eSrillig.if defined(.SUFFIXES)
342ec6e74eSrillig.  error
352ec6e74eSrillig.endif
362ec6e74eSrillig
372ec6e74eSrillig# Now the suffixes list is not empty anymore.  It may seem strange that there
382ec6e74eSrillig# is no variable named '.SUFFIXES' but evaluating '${.SUFFIXES}' nevertheless
392ec6e74eSrillig# returns something.  For all practical use cases, it's good enough though.
402ec6e74eSrillig.if empty(.SUFFIXES)
412ec6e74eSrillig.  error
422ec6e74eSrillig.endif
432ec6e74eSrillig
442ec6e74eSrillig.SUFFIXES: .tar.gz
452ec6e74eSrillig
462ec6e74eSrillig# Changes to the suffixes list are reflected immediately.
472ec6e74eSrillig.if ${.SUFFIXES} != ".c .o .1 .err .tar.gz"
482ec6e74eSrillig.  error
492ec6e74eSrillig.endif
502ec6e74eSrillig
512ec6e74eSrillig# Deleting .SUFFIXES has no effect since there is no actual variable of that
522ec6e74eSrillig# name.
532ec6e74eSrillig.MAKEFLAGS: -dv
542ec6e74eSrillig# expect: Global: delete .SUFFIXES (not found)
552ec6e74eSrillig.undef .SUFFIXES
562ec6e74eSrillig.MAKEFLAGS: -d0
572ec6e74eSrillig.if ${.SUFFIXES} != ".c .o .1 .err .tar.gz"
582ec6e74eSrillig.  error
592ec6e74eSrillig.endif
602ec6e74eSrillig
612ec6e74eSrillig# The list of suffixes can only be modified using dependency declarations, any
622ec6e74eSrillig# attempt at setting the variable named '.SUFFIXES' is rejected.
632ec6e74eSrillig.MAKEFLAGS: -dv
642ec6e74eSrillig# expect: Global: .SUFFIXES = set ignored (read-only)
652ec6e74eSrillig.SUFFIXES=	set
662ec6e74eSrillig# expect: Global: .SUFFIXES = append ignored (read-only)
672ec6e74eSrillig.SUFFIXES+=	append
682ec6e74eSrillig# expect: Global: .SUFFIXES = assign ignored (read-only)
692ec6e74eSrillig_:=		${.SUFFIXES::=assign}
702234d9c8Srillig# expect: Global: .SUFFIXES = preserve ignored (read-only)
712ec6e74eSrillig_:=		${preserve:L:_=.SUFFIXES}
722ec6e74eSrillig.MAKEFLAGS: -d0
732ec6e74eSrillig
742ec6e74eSrillig# Using the name '.SUFFIXES' in a .for loop looks strange because these
752ec6e74eSrillig# variable names are typically in singular form, and .for loops do not use
762ec6e74eSrillig# real variables either, they are made up as well, see directive-for.mk.  The
772ec6e74eSrillig# replacement mechanism for the iteration variables takes precedence.
782ec6e74eSrillig.for .SUFFIXES in .c .o
792ec6e74eSrillig.  if ${.SUFFIXES} != ".c" && ${.SUFFIXES} != ".o"
802ec6e74eSrillig.    error
812ec6e74eSrillig.  endif
822ec6e74eSrillig.endfor
832ec6e74eSrillig
842ec6e74eSrillig# After the .for loop, the expression '${.SUFFIXES}' refers to the list of
852ec6e74eSrillig# suffixes again.
862ec6e74eSrillig.if ${.SUFFIXES} != ".c .o .1 .err .tar.gz"
872ec6e74eSrillig.  error
882ec6e74eSrillig.endif
892ec6e74eSrillig
902ec6e74eSrillig# Using the name '.SUFFIXES' in the modifier ':@var@body@' does not create an
912ec6e74eSrillig# actual variable either.  Like in the .for loop, choosing the name
922ec6e74eSrillig# '.SUFFIXES' for the iteration variable is unusual.  In ODE Make, the
932ec6e74eSrillig# convention for these iteration variables is to have dots at both ends, so
942ec6e74eSrillig# the name would be '.SUFFIXES.', furthermore the name of the iteration
952ec6e74eSrillig# variable is typically in singular form.
962ec6e74eSrillig.MAKEFLAGS: -dv
972ec6e74eSrillig# expect: Command: .SUFFIXES = 1 ignored (read-only)
982ec6e74eSrillig# expect: Command: .SUFFIXES = 2 ignored (read-only)
992234d9c8Srillig# XXX: Missing space after ':'
1002234d9c8Srillig# expect: Command: delete .SUFFIXES (not found)
1012ec6e74eSrillig.if ${1 2:L:@.SUFFIXES@${.SUFFIXES}@} != ".c .o .1 .err .tar.gz .c .o .1 .err .tar.gz"
1022ec6e74eSrillig.  error
1032ec6e74eSrillig.endif
1042ec6e74eSrillig.MAKEFLAGS: -d0
1052ec6e74eSrillig
1062ec6e74eSrilligall:
107