var-scope-local.mk revision 1.2 1 # $NetBSD: var-scope-local.mk,v 1.2 2022/01/27 06:56:27 sjg Exp $
2 #
3 # Tests for target-local variables, such as ${.TARGET} or $@.
4
5 # TODO: Implementation
6
7 # Ensure that the name of the variable is exactly the given one.
8 # The variable "@" is an alias for ".TARGET", so the implementation might
9 # canonicalize these aliases at some point, and that might be surprising.
10 # This aliasing happens for single-character variable names like $@ or $<
11 # (see VarFind, CanonicalVarname), but not for braced or parenthesized
12 # expressions like ${@}, ${.TARGET} ${VAR:Mpattern} (see Var_Parse,
13 # ParseVarname).
14 .if ${@:L} != "@"
15 . error
16 .endif
17 .if ${.TARGET:L} != ".TARGET"
18 . error
19 .endif
20 .if ${@F:L} != "@F"
21 . error
22 .endif
23 .if ${@D:L} != "@D"
24 . error
25 .endif
26
27 all:
28
29 .SUFFIXES: .c .o
30
31 var-scope-local.c var-scope-local2.c var-scope-local3.c:
32 : Making ${.TARGET} out of nothing.
33
34 .c.o:
35 : Making ${.TARGET} from ${.IMPSRC}.
36
37 # The local variables @F, @D, <F, <D are legacy forms.
38 # See the manual page for details.
39 : Making basename "${@F}" in "${@D}" from "${<F}" in "${<D}" VAR="${VAR}".
40
41 all: var-scope-local.o var-scope-local2.o var-scope-local3.o
42 # The ::= modifier overwrites the .TARGET variable in the node
43 # 'all', not in the global scope. This can be seen with the -dv
44 # option, looking for "all:@ = overwritten".
45 : ${.TARGET} ${.TARGET::=overwritten}${.TARGET} VAR="${VAR}"
46
47 # we can set variables per target with some limitations
48 .MAKE.TARGET_LOCAL_VARIABLES= yes
49 VAR= global
50 # the rest of the line is the value
51 var-scope-local.o: VAR= local
52 # += will *not* take global value and add to it in local context
53 var-scope-local2.o: VAR+= local
54 # but once defined in local context += behaves as expected.
55 var-scope-local2.o: VAR += to ${.TARGET}
56 # we can get the global value though
57 # so complex values can always be set via global variable and then
58 # assigned to local context
59 # Note: that the global ${VAR} is expanded at this point
60 # just as with any dependency line.
61 var-scope-local3.o: VAR= ${VAR}+local
62
63 # while VAR=use will be set for a .USE node, it will never be seen
64 # since only the ultimate target's context is searched
65 a_use: .USE VAR=use
66 : ${.TARGET} uses .USE VAR="${VAR}"
67
68 var-scope-local3.o: a_use
69