summaryrefslogtreecommitdiff
path: root/devdocs/gnu_make/static-usage.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/static-usage.html
new repository
Diffstat (limited to 'devdocs/gnu_make/static-usage.html')
-rw-r--r--devdocs/gnu_make/static-usage.html27
1 files changed, 27 insertions, 0 deletions
diff --git a/devdocs/gnu_make/static-usage.html b/devdocs/gnu_make/static-usage.html
new file mode 100644
index 00000000..85823662
--- /dev/null
+++ b/devdocs/gnu_make/static-usage.html
@@ -0,0 +1,27 @@
+ <h1 class="subsection">Syntax of Static Pattern Rules</h1> <p>Here is the syntax of a static pattern rule: </p> <div class="example"> <pre class="example"><var>targets</var> …: <var>target-pattern</var>: <var>prereq-patterns</var> …
+ <var>recipe</var>
+ …
+</pre>
+</div> <p>The <var>targets</var> list specifies the targets that the rule applies to. The targets can contain wildcard characters, just like the targets of ordinary rules (see <a href="wildcards">Using Wildcard Characters in File Names</a>). </p> <p>The <var>target-pattern</var> and <var>prereq-patterns</var> say how to compute the prerequisites of each target. Each target is matched against the <var>target-pattern</var> to extract a part of the target name, called the <em>stem</em>. This stem is substituted into each of the <var>prereq-patterns</var> to make the prerequisite names (one from each <var>prereq-pattern</var>). </p> <p>Each pattern normally contains the character ‘<samp>%</samp>’ just once. When the <var>target-pattern</var> matches a target, the ‘<samp>%</samp>’ can match any part of the target name; this part is called the <em>stem</em>. The rest of the pattern must match exactly. For example, the target <samp>foo.o</samp> matches the pattern ‘<samp>%.o</samp>’, with ‘<samp>foo</samp>’ as the stem. The targets <samp>foo.c</samp> and <samp>foo.out</samp> do not match that pattern. </p> <p>The prerequisite names for each target are made by substituting the stem for the ‘<samp>%</samp>’ in each prerequisite pattern. For example, if one prerequisite pattern is <samp>%.c</samp>, then substitution of the stem ‘<samp>foo</samp>’ gives the prerequisite name <samp>foo.c</samp>. It is legitimate to write a prerequisite pattern that does not contain ‘<samp>%</samp>’; then this prerequisite is the same for all targets. </p> <p>‘<samp>%</samp>’ characters in pattern rules can be quoted with preceding backslashes (‘<samp>\</samp>’). Backslashes that would otherwise quote ‘<samp>%</samp>’ characters can be quoted with more backslashes. Backslashes that quote ‘<samp>%</samp>’ characters or other backslashes are removed from the pattern before it is compared to file names or has a stem substituted into it. Backslashes that are not in danger of quoting ‘<samp>%</samp>’ characters go unmolested. For example, the pattern <samp>the\%weird\\%pattern\\</samp> has ‘<samp>the%weird\</samp>’ preceding the operative ‘<samp>%</samp>’ character, and ‘<samp>pattern\\</samp>’ following it. The final two backslashes are left alone because they cannot affect any ‘<samp>%</samp>’ character. </p> <p>Here is an example, which compiles each of <samp>foo.o</samp> and <samp>bar.o</samp> from the corresponding <samp>.c</samp> file: </p> <div class="example"> <pre class="example">objects = foo.o bar.o
+
+all: $(objects)
+
+$(objects): %.o: %.c
+ $(CC) -c $(CFLAGS) $&lt; -o $@
+</pre>
+</div> <p>Here ‘<samp>$&lt;</samp>’ is the automatic variable that holds the name of the prerequisite and ‘<samp>$@</samp>’ is the automatic variable that holds the name of the target; see <a href="automatic-variables">Automatic Variables</a>. </p> <p>Each target specified must match the target pattern; a warning is issued for each target that does not. If you have a list of files, only some of which will match the pattern, you can use the <code>filter</code> function to remove non-matching file names (see <a href="text-functions">Functions for String Substitution and Analysis</a>): </p> <div class="example"> <pre class="example">files = foo.elc bar.o lose.o
+
+$(filter %.o,$(files)): %.o: %.c
+ $(CC) -c $(CFLAGS) $&lt; -o $@
+$(filter %.elc,$(files)): %.elc: %.el
+ emacs -f batch-byte-compile $&lt;
+</pre>
+</div> <p>In this example the result of ‘<samp>$(filter %.o,$(files))</samp>’ is <samp>bar.o lose.o</samp>, and the first static pattern rule causes each of these object files to be updated by compiling the corresponding C source file. The result of ‘<samp>$(filter %.elc,$(files))</samp>’ is <samp>foo.elc</samp>, so that file is made from <samp>foo.el</samp>. </p> <p>Another example shows how to use <code>$*</code> in static pattern rules: </p> <div class="example"> <pre class="example">bigoutput littleoutput : %output : text.g
+ generate text.g -$* &gt; $@
+</pre>
+</div> <p>When the <code>generate</code> command is run, <code>$*</code> will expand to the stem, either ‘<samp>big</samp>’ or ‘<samp>little</samp>’. </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/Static-Usage.html" class="_attribution-link">https://www.gnu.org/software/make/manual/html_node/Static-Usage.html</a>
+ </p>
+</div>