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