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/multi_002dline.html | |
new repository
Diffstat (limited to 'devdocs/gnu_make/multi_002dline.html')
| -rw-r--r-- | devdocs/gnu_make/multi_002dline.html | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/devdocs/gnu_make/multi_002dline.html b/devdocs/gnu_make/multi_002dline.html new file mode 100644 index 00000000..0fb18744 --- /dev/null +++ b/devdocs/gnu_make/multi_002dline.html @@ -0,0 +1,23 @@ + <h1 class="section">Defining Multi-Line Variables</h1> <p>Another way to set the value of a variable is to use the <code>define</code> directive. This directive has an unusual syntax which allows newline characters to be included in the value, which is convenient for defining both canned sequences of commands (see <a href="canned-recipes">Defining Canned Recipes</a>), and also sections of makefile syntax to use with <code>eval</code> (see <a href="eval-function">Eval Function</a>). </p> <p>The <code>define</code> directive is followed on the same line by the name of the variable being defined and an (optional) assignment operator, and nothing more. The value to give the variable appears on the following lines. The end of the value is marked by a line containing just the word <code>endef</code>. </p> <p>Aside from this difference in syntax, <code>define</code> works just like any other variable definition. The variable name may contain function and variable references, which are expanded when the directive is read to find the actual variable name to use. </p> <p>The final newline before the <code>endef</code> is not included in the value; if you want your value to contain a trailing newline you must include a blank line. For example in order to define a variable that contains a newline character you must use <em>two</em> empty lines, not one: </p> <div class="example"> <pre class="example">define newline + + +endef +</pre> +</div> <p>You may omit the variable assignment operator if you prefer. If omitted, <code>make</code> assumes it to be ‘<samp>=</samp>’ and creates a recursively-expanded variable (see <a href="flavors">The Two Flavors of Variables</a>). When using a ‘<samp>+=</samp>’ operator, the value is appended to the previous value as with any other append operation: with a single space separating the old and new values. </p> <p>You may nest <code>define</code> directives: <code>make</code> will keep track of nested directives and report an error if they are not all properly closed with <code>endef</code>. Note that lines beginning with the recipe prefix character are considered part of a recipe, so any <code>define</code> or <code>endef</code> strings appearing on such a line will not be considered <code>make</code> directives. </p> <div class="example"> <pre class="example">define two-lines +echo foo +echo $(bar) +endef +</pre> +</div> <p>When used in a recipe, the previous example is functionally equivalent to this: </p> <div class="example"> <pre class="example">two-lines = echo foo; echo $(bar) +</pre> +</div> <p>since two commands separated by semicolon behave much like two separate shell commands. However, note that using two separate lines means <code>make</code> will invoke the shell twice, running an independent sub-shell for each line. See <a href="execution">Recipe Execution</a>. </p> <p>If you want variable definitions made with <code>define</code> to take precedence over command-line variable definitions, you can use the <code>override</code> directive together with <code>define</code>: </p> <div class="example"> <pre class="example">override define two-lines = +foo +$(bar) +endef +</pre> +</div> <p>See <a href="override-directive">The <code>override</code> Directive</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/Multi_002dLine.html" class="_attribution-link">https://www.gnu.org/software/make/manual/html_node/Multi_002dLine.html</a> + </p> +</div> |
