summaryrefslogtreecommitdiff
path: root/devdocs/gnu_make/recursive-assignment.html
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
committerCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
commit754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch)
treef1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/gnu_make/recursive-assignment.html
new repository
Diffstat (limited to 'devdocs/gnu_make/recursive-assignment.html')
-rw-r--r--devdocs/gnu_make/recursive-assignment.html17
1 files changed, 17 insertions, 0 deletions
diff --git a/devdocs/gnu_make/recursive-assignment.html b/devdocs/gnu_make/recursive-assignment.html
new file mode 100644
index 00000000..7c47a9c2
--- /dev/null
+++ b/devdocs/gnu_make/recursive-assignment.html
@@ -0,0 +1,17 @@
+ <h1 class="subsection">Recursively Expanded Variable Assignment</h1> <p>The first flavor of variable is a <em>recursively expanded</em> variable. Variables of this sort are defined by lines using ‘<samp>=</samp>’ (see <a href="setting">Setting Variables</a>) or by the <code>define</code> directive (see <a href="multi_002dline">Defining Multi-Line Variables</a>). The value you specify is installed verbatim; if it contains references to other variables, these references are expanded whenever this variable is substituted (in the course of expanding some other string). When this happens, it is called <em>recursive expansion</em>. </p> <p>For example, </p> <div class="example"> <pre class="example">foo = $(bar)
+bar = $(ugh)
+ugh = Huh?
+
+all:;echo $(foo)
+</pre>
+</div> <p>will echo ‘<samp>Huh?</samp>’: ‘<samp>$(foo)</samp>’ expands to ‘<samp>$(bar)</samp>’ which expands to ‘<samp>$(ugh)</samp>’ which finally expands to ‘<samp>Huh?</samp>’. </p> <p>This flavor of variable is the only sort supported by most other versions of <code>make</code>. It has its advantages and its disadvantages. An advantage (most would say) is that: </p> <div class="example"> <pre class="example">CFLAGS = $(include_dirs) -O
+include_dirs = -Ifoo -Ibar
+</pre>
+</div> <p>will do what was intended: when ‘<samp>CFLAGS</samp>’ is expanded in a recipe, it will expand to ‘<samp>-Ifoo -Ibar -O</samp>’. A major disadvantage is that you cannot append something on the end of a variable, as in </p> <div class="example"> <pre class="example">CFLAGS = $(CFLAGS) -O
+</pre>
+</div> <p>because it will cause an infinite loop in the variable expansion. (Actually <code>make</code> detects the infinite loop and reports an error.) </p> <p>Another disadvantage is that any functions (see <a href="functions">Functions for Transforming Text</a>) referenced in the definition will be executed every time the variable is expanded. This makes <code>make</code> run slower; worse, it causes the <code>wildcard</code> and <code>shell</code> functions to give unpredictable results because you cannot easily control when they are called, or even how many times. </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/Recursive-Assignment.html" class="_attribution-link">https://www.gnu.org/software/make/manual/html_node/Recursive-Assignment.html</a>
+ </p>
+</div>