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/reference.html | |
new repository
Diffstat (limited to 'devdocs/gnu_make/reference.html')
| -rw-r--r-- | devdocs/gnu_make/reference.html | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/devdocs/gnu_make/reference.html b/devdocs/gnu_make/reference.html new file mode 100644 index 00000000..8dfc3d86 --- /dev/null +++ b/devdocs/gnu_make/reference.html @@ -0,0 +1,16 @@ + <h1 class="section">Basics of Variable References</h1> <p>To substitute a variable’s value, write a dollar sign followed by the name of the variable in parentheses or braces: either ‘<samp>$(foo)</samp>’ or ‘<samp>${foo}</samp>’ is a valid reference to the variable <code>foo</code>. This special significance of ‘<samp>$</samp>’ is why you must write ‘<samp>$$</samp>’ to have the effect of a single dollar sign in a file name or recipe. </p> <p>Variable references can be used in any context: targets, prerequisites, recipes, most directives, and new variable values. Here is an example of a common case, where a variable holds the names of all the object files in a program: </p> <div class="example"> <pre class="example">objects = program.o foo.o utils.o +program : $(objects) + cc -o program $(objects) + +$(objects) : defs.h +</pre> +</div> <p>Variable references work by strict textual substitution. Thus, the rule </p> <div class="example"> <pre class="example">foo = c +prog.o : prog.$(foo) + $(foo)$(foo) -$(foo) prog.$(foo) +</pre> +</div> <p>could be used to compile a C program <samp>prog.c</samp>. Since spaces before the variable value are ignored in variable assignments, the value of <code>foo</code> is precisely ‘<samp>c</samp>’. (Don’t actually write your makefiles this way!) </p> <p>A dollar sign followed by a character other than a dollar sign, open-parenthesis or open-brace treats that single character as the variable name. Thus, you could reference the variable <code>x</code> with ‘<samp>$x</samp>’. However, this practice can lead to confusion (e.g., ‘<samp>$foo</samp>’ refers to the variable <code>f</code> followed by the string <code>oo</code>) so we recommend using parentheses or braces around all variables, even single-letter variables, unless omitting them gives significant readability improvements. One place where readability is often improved is automatic variables (see <a href="automatic-variables">Automatic Variables</a>). </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/Reference.html" class="_attribution-link">https://www.gnu.org/software/make/manual/html_node/Reference.html</a> + </p> +</div> |
