From 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 7 Apr 2024 13:41:34 -0500 Subject: new repository --- devdocs/gnu_make/immediate-assignment.html | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 devdocs/gnu_make/immediate-assignment.html (limited to 'devdocs/gnu_make/immediate-assignment.html') 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 @@ +

Immediately Expanded Variable Assignment

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 $ in the value after expansion will be converted into $$. This type of assignment uses the ‘:::=’ operator. For example,

var = first
+OUT :::= $(var)
+var = second
+
+

results in the OUT variable containing the text ‘first’, while here:

var = one$$two
+OUT :::= $(var)
+var = three$$four
+
+

results in the OUT variable containing the text ‘one$$two’. The value is expanded when the variable is assigned, so the result is the expansion of the first value of var, ‘one$two’; then the value is re-escaped before the assignment is complete giving the final result of ‘one$$two’.

The variable OUT is thereafter considered a recursive variable, so it will be re-expanded when it is used.

This seems functionally equivalent to the ‘:=’ / ‘::=’ operators, but there are a few differences:

First, after assignment the variable is a normal recursive variable; when you append to it with ‘+=’ the value on the right-hand side is not expanded immediately. If you prefer the ‘+=’ operator to expand the right-hand side immediately you should use the ‘:=’ / ‘::=’ assignment instead.

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.

Here is another example:

var = one$$two
+OUT :::= $(var)
+OUT += $(var)
+var = three$$four
+
+

After this, the value of OUT is the text ‘one$$two $(var)’. When this variable is used it will be expanded and the result will be ‘one$two three$four’.

This style of assignment is equivalent to the traditional BSD make:=’ operator; as you can see it works slightly differently than the GNU make:=’ operator. The :::= operator is added to the POSIX specification in Issue 8 to provide portability.

+

+ 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.
Licensed under the GNU Free Documentation License.
+ https://www.gnu.org/software/make/manual/html_node/Immediate-Assignment.html +

+
-- cgit v1.2.3