diff options
| author | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
| commit | 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch) | |
| tree | f1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/gnu_make/immediate-assignment.html | |
new repository
Diffstat (limited to 'devdocs/gnu_make/immediate-assignment.html')
| -rw-r--r-- | devdocs/gnu_make/immediate-assignment.html | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/devdocs/gnu_make/immediate-assignment.html b/devdocs/gnu_make/immediate-assignment.html new file mode 100644 index 00000000..eff5701d --- /dev/null +++ b/devdocs/gnu_make/immediate-assignment.html @@ -0,0 +1,19 @@ + <h1 class="subsection">Immediately Expanded Variable Assignment</h1> <p>Another form of assignment allows for immediate expansion, but unlike simple assignment the resulting variable is recursive: it will be re-expanded again on every use. In order to avoid unexpected results, after the value is immediately expanded it will automatically be quoted: all instances of <code>$</code> in the value after expansion will be converted into <code>$$</code>. This type of assignment uses the ‘<samp>:::=</samp>’ operator. For example, </p> <div class="example"> <pre class="example">var = first +OUT :::= $(var) +var = second +</pre> +</div> <p>results in the <code>OUT</code> variable containing the text ‘<samp>first</samp>’, while here: </p> <div class="example"> <pre class="example">var = one$$two +OUT :::= $(var) +var = three$$four +</pre> +</div> <p>results in the <code>OUT</code> variable containing the text ‘<samp>one$$two</samp>’. The value is expanded when the variable is assigned, so the result is the expansion of the first value of <code>var</code>, ‘<samp>one$two</samp>’; then the value is re-escaped before the assignment is complete giving the final result of ‘<samp>one$$two</samp>’. </p> <p>The variable <code>OUT</code> is thereafter considered a recursive variable, so it will be re-expanded when it is used. </p> <p>This seems functionally equivalent to the ‘<samp>:=</samp>’ / ‘<samp>::=</samp>’ operators, but there are a few differences: </p> <p>First, after assignment the variable is a normal recursive variable; when you append to it with ‘<samp>+=</samp>’ the value on the right-hand side is not expanded immediately. If you prefer the ‘<samp>+=</samp>’ operator to expand the right-hand side immediately you should use the ‘<samp>:=</samp>’ / ‘<samp>::=</samp>’ assignment instead. </p> <p>Second, these variables are slightly less efficient than simply expanded variables since they do need to be re-expanded when they are used, rather than merely copied. However since all variable references are escaped this expansion simply un-escapes the value, it won’t expand any variables or run any functions. </p> <p>Here is another example: </p> <div class="example"> <pre class="example">var = one$$two +OUT :::= $(var) +OUT += $(var) +var = three$$four +</pre> +</div> <p>After this, the value of <code>OUT</code> is the text ‘<samp>one$$two $(var)</samp>’. When this variable is used it will be expanded and the result will be ‘<samp>one$two three$four</samp>’. </p> <p>This style of assignment is equivalent to the traditional BSD <code>make</code> ‘<samp>:=</samp>’ operator; as you can see it works slightly differently than the GNU <code>make</code> ‘<samp>:=</samp>’ operator. The <code>:::=</code> operator is added to the POSIX specification in Issue 8 to provide portability. </p><div class="_attribution"> + <p class="_attribution-p"> + Copyright © 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 Free Software Foundation, Inc. <br>Licensed under the GNU Free Documentation License.<br> + <a href="https://www.gnu.org/software/make/manual/html_node/Immediate-Assignment.html" class="_attribution-link">https://www.gnu.org/software/make/manual/html_node/Immediate-Assignment.html</a> + </p> +</div> |
