summaryrefslogtreecommitdiff
path: root/devdocs/gnu_make/splitting-lines.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/splitting-lines.html
new repository
Diffstat (limited to 'devdocs/gnu_make/splitting-lines.html')
-rw-r--r--devdocs/gnu_make/splitting-lines.html13
1 files changed, 13 insertions, 0 deletions
diff --git a/devdocs/gnu_make/splitting-lines.html b/devdocs/gnu_make/splitting-lines.html
new file mode 100644
index 00000000..27b90211
--- /dev/null
+++ b/devdocs/gnu_make/splitting-lines.html
@@ -0,0 +1,13 @@
+ <h1 class="subsection">Splitting Long Lines</h1> <p>Makefiles use a “line-based” syntax in which the newline character is special and marks the end of a statement. GNU <code>make</code> has no limit on the length of a statement line, up to the amount of memory in your computer. </p> <p>However, it is difficult to read lines which are too long to display without wrapping or scrolling. So, you can format your makefiles for readability by adding newlines into the middle of a statement: you do this by escaping the internal newlines with a backslash (<code>\</code>) character. Where we need to make a distinction we will refer to “physical lines” as a single line ending with a newline (regardless of whether it is escaped) and a “logical line” being a complete statement including all escaped newlines up to the first non-escaped newline. </p> <p>The way in which backslash/newline combinations are handled depends on whether the statement is a recipe line or a non-recipe line. Handling of backslash/newline in a recipe line is discussed later (see <a href="splitting-recipe-lines">Splitting Recipe Lines</a>). </p> <p>Outside of recipe lines, backslash/newlines are converted into a single space character. Once that is done, all whitespace around the backslash/newline is condensed into a single space: this includes all whitespace preceding the backslash, all whitespace at the beginning of the line after the backslash/newline, and any consecutive backslash/newline combinations. </p> <p>If the <code>.POSIX</code> special target is defined then backslash/newline handling is modified slightly to conform to POSIX.2: first, whitespace preceding a backslash is not removed and second, consecutive backslash/newlines are not condensed. </p> <h4 class="subsubheading">Splitting Without Adding Whitespace</h4> <p>If you need to split a line but do <em>not</em> want any whitespace added, you can utilize a subtle trick: replace your backslash/newline pairs with the three characters dollar sign, backslash, and newline: </p> <div class="example"> <pre class="example">var := one$\
+ word
+</pre>
+</div> <p>After <code>make</code> removes the backslash/newline and condenses the following line into a single space, this is equivalent to: </p> <div class="example"> <pre class="example">var := one$ word
+</pre>
+</div> <p>Then <code>make</code> will perform variable expansion. The variable reference ‘<samp>$ </samp>’ refers to a variable with the one-character name “ ” (space) which does not exist, and so expands to the empty string, giving a final assignment which is the equivalent of: </p> <div class="example"> <pre class="example">var := oneword
+</pre>
+</div><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/Splitting-Lines.html" class="_attribution-link">https://www.gnu.org/software/make/manual/html_node/Splitting-Lines.html</a>
+ </p>
+</div>