Home | History | Annotate | Line # | Download | only in unit-tests
var-scope-local.mk revision 1.1
      1 # $NetBSD: var-scope-local.mk,v 1.1 2022/01/23 16:25:54 rillig 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:
     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}".
     40 
     41 all: var-scope-local.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}
     46