dep-var.mk revision 1.3 1 1.3 rillig # $NetBSD: dep-var.mk,v 1.3 2020/09/03 19:50:14 rillig Exp $
2 1.1 rillig #
3 1.1 rillig # Tests for variable references in dependency declarations.
4 1.1 rillig #
5 1.1 rillig # Uh oh, this feels so strange that probably nobody uses it. But it seems to
6 1.1 rillig # be the only way to reach the lower half of SuffExpandChildren.
7 1.1 rillig
8 1.1 rillig # XXX: The -dv log says:
9 1.1 rillig # Var_Parse: ${UNDEF1} with VARE_UNDEFERR|VARE_WANTRES
10 1.1 rillig # but no error message is generated for this line.
11 1.1 rillig # The variable expression ${UNDEF1} simply expands to an empty string.
12 1.1 rillig all: ${UNDEF1}
13 1.1 rillig
14 1.1 rillig # Using a double dollar in order to circumvent immediate variable expansion
15 1.1 rillig # feels like unintended behavior. At least the manual page says nothing at
16 1.1 rillig # all about defined or undefined variables in dependency lines.
17 1.1 rillig #
18 1.1 rillig # At the point where the expression ${DEF2} is expanded, the variable DEF2
19 1.1 rillig # is defined, so everything's fine.
20 1.2 rillig all: $${DEF2} a-$${DEF2}-b
21 1.1 rillig
22 1.1 rillig # This variable is not defined at all.
23 1.1 rillig # XXX: The -dv log says:
24 1.1 rillig # Var_Parse: ${UNDEF3} with VARE_UNDEFERR|VARE_WANTRES
25 1.1 rillig # but no error message is generated for this line, just like for UNDEF1.
26 1.1 rillig # The variable expression ${UNDEF3} simply expands to an empty string.
27 1.1 rillig all: $${UNDEF3}
28 1.1 rillig
29 1.3 rillig # Try out how many levels of indirection are really expanded in dependency
30 1.3 rillig # lines.
31 1.3 rillig #
32 1.3 rillig # The first level of indirection is the $$ in the dependency line.
33 1.3 rillig # When the dependency line is parsed, it is resolved to the string
34 1.3 rillig # "${INDIRECT_1}". At this point, the dollar is just an ordinary character,
35 1.3 rillig # waiting to be expanded at some later point.
36 1.3 rillig #
37 1.3 rillig # Later, in SuffExpandChildren, that expression is expanded again by calling
38 1.3 rillig # Var_Parse, and this time, the result is the string "1-2-${INDIRECT_2}-2-1".
39 1.3 rillig #
40 1.3 rillig # This string is not expanded anymore by Var_Parse. But there is another
41 1.3 rillig # effect. Now DirExpandCurly comes into play and expands the curly braces
42 1.3 rillig # in this filename pattern, resulting in the string "1-2-$INDIRECT_2-2-1".
43 1.3 rillig # As of 2020-09-03, the test dir.mk contains further details on this topic.
44 1.3 rillig #
45 1.3 rillig # Finally, this string is assigned to the local ${.TARGET} variable. This
46 1.3 rillig # variable is expanded when the shell command is generated. At that point,
47 1.3 rillig # the $I is expanded. Since the variable I is not defined, it expands to
48 1.3 rillig # the empty string. This way, the final output is the string
49 1.3 rillig # "1-2-NDIRECT_2-2-1", which differs from the actual name of the target.
50 1.3 rillig # For exactly this reason, it is not recommended to use dollar signs in
51 1.3 rillig # target names.
52 1.3 rillig #
53 1.3 rillig # The number of actual expansions is way more than one might expect,
54 1.3 rillig # therefore this feature is probably not widely used.
55 1.3 rillig #
56 1.3 rillig all: 1-$${INDIRECT_1}-1
57 1.3 rillig INDIRECT_1= 2-$${INDIRECT_2}-2
58 1.3 rillig INDIRECT_2= 3-$${INDIRECT_3}-3
59 1.3 rillig INDIRECT_3= indirect
60 1.3 rillig
61 1.1 rillig UNDEF1= undef1
62 1.1 rillig DEF2= def2
63 1.1 rillig
64 1.3 rillig undef1 def2 a-def2-b 1-2-$$INDIRECT_2-2-1:
65 1.3 rillig @echo ${.TARGET:Q}
66