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