1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
<h1 class="section">Rule Syntax</h1> <p>In general, a rule looks like this: </p> <div class="example"> <pre class="example"><var>targets</var> : <var>prerequisites</var>
<var>recipe</var>
…
</pre>
</div> <p>or like this: </p> <div class="example"> <pre class="example"><var>targets</var> : <var>prerequisites</var> ; <var>recipe</var>
<var>recipe</var>
…
</pre>
</div> <p>The <var>targets</var> are file names, separated by spaces. Wildcard characters may be used (see <a href="wildcards">Using Wildcard Characters in File Names</a>) and a name of the form <samp><var>a</var>(<var>m</var>)</samp> represents member <var>m</var> in archive file <var>a</var> (see <a href="archive-members">Archive Members as Targets</a>). Usually there is only one target per rule, but occasionally there is a reason to have more (see <a href="multiple-targets">Multiple Targets in a Rule</a>). </p> <p>The <var>recipe</var> lines start with a tab character (or the first character in the value of the <code>.RECIPEPREFIX</code> variable; see <a href="special-variables">Special Variables</a>). The first recipe line may appear on the line after the prerequisites, with a tab character, or may appear on the same line, with a semicolon. Either way, the effect is the same. There are other differences in the syntax of recipes. See <a href="recipes">Writing Recipes in Rules</a>. </p> <p>Because dollar signs are used to start <code>make</code> variable references, if you really want a dollar sign in a target or prerequisite you must write two of them, ‘<samp>$$</samp>’ (see <a href="using-variables">How to Use Variables</a>). If you have enabled secondary expansion (see <a href="secondary-expansion">Secondary Expansion</a>) and you want a literal dollar sign in the prerequisites list, you must actually write <em>four</em> dollar signs (‘<samp>$$$$</samp>’). </p> <p>You may split a long line by inserting a backslash followed by a newline, but this is not required, as <code>make</code> places no limit on the length of a line in a makefile. </p> <p>A rule tells <code>make</code> two things: when the targets are out of date, and how to update them when necessary. </p> <p>The criterion for being out of date is specified in terms of the <var>prerequisites</var>, which consist of file names separated by spaces. (Wildcards and archive members (see <a href="archives">Archives</a>) are allowed here too.) A target is out of date if it does not exist or if it is older than any of the prerequisites (by comparison of last-modification times). The idea is that the contents of the target file are computed based on information in the prerequisites, so if any of the prerequisites changes, the contents of the existing target file are no longer necessarily valid. </p> <p>How to update is specified by a <var>recipe</var>. This is one or more lines to be executed by the shell (normally ‘<samp>sh</samp>’), but with some extra features (see <a href="recipes">Writing Recipes in Rules</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/Rule-Syntax.html" class="_attribution-link">https://www.gnu.org/software/make/manual/html_node/Rule-Syntax.html</a>
</p>
</div>
|