summaryrefslogtreecommitdiff
path: root/devdocs/gnu_make/rules.html
blob: cf9e075f975d378c32eda0fa72c374f374097457 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
  <h1 class="chapter">Writing Rules</h1>     <p>A <em>rule</em> appears in the makefile and says when and how to remake certain files, called the rule’s <em>targets</em> (most often only one per rule). It lists the other files that are the <em>prerequisites</em> of the target, and the <em>recipe</em> to use to create or update the target. </p>   <p>The order of rules is not significant, except for determining the <em>default goal</em>: the target for <code>make</code> to consider, if you do not otherwise specify one. The default goal is the first target of the first rule in the first makefile. There are two exceptions: a target starting with a period is not a default unless it also contains one or more slashes, ‘<samp>/</samp>’; and, a target that defines a pattern rule has no effect on the default goal. (See <a href="pattern-rules">Defining and Redefining Pattern Rules</a>.) </p> <p>Therefore, we usually write the makefile so that the first rule is the one for compiling the entire program or all the programs described by the makefile (often with a target called ‘<samp>all</samp>’). See <a href="goals">Arguments to Specify the Goals</a>. </p> <table class="menu" border="0" cellspacing="0"> <tr>
<td align="left" valign="top">• <a href="rule-example" accesskey="1">Rule Example</a>
</td>
<td> </td>
<td align="left" valign="top">An example explained. </td>
</tr> <tr>
<td align="left" valign="top">• <a href="rule-syntax" accesskey="2">Rule Syntax</a>
</td>
<td> </td>
<td align="left" valign="top">General syntax explained. </td>
</tr> <tr>
<td align="left" valign="top">• <a href="prerequisite-types" accesskey="3">Prerequisite Types</a>
</td>
<td> </td>
<td align="left" valign="top">There are two types of prerequisites. </td>
</tr> <tr>
<td align="left" valign="top">• <a href="wildcards" accesskey="4">Wildcards</a>
</td>
<td> </td>
<td align="left" valign="top">Using wildcard characters such as ‘*’. </td>
</tr> <tr>
<td align="left" valign="top">• <a href="directory-search" accesskey="5">Directory Search</a>
</td>
<td> </td>
<td align="left" valign="top">Searching other directories for source files. </td>
</tr> <tr>
<td align="left" valign="top">• <a href="phony-targets" accesskey="6">Phony Targets</a>
</td>
<td> </td>
<td align="left" valign="top">Using a target that is not a real file’s name. </td>
</tr> <tr>
<td align="left" valign="top">• <a href="force-targets" accesskey="7">Force Targets</a>
</td>
<td> </td>
<td align="left" valign="top">You can use a target without a recipe or prerequisites to mark other targets as phony. </td>
</tr> <tr>
<td align="left" valign="top">• <a href="empty-targets" accesskey="8">Empty Targets</a>
</td>
<td> </td>
<td align="left" valign="top">When only the date matters and the files are empty. </td>
</tr> <tr>
<td align="left" valign="top">• <a href="special-targets" accesskey="9">Special Targets</a>
</td>
<td> </td>
<td align="left" valign="top">Targets with special built-in meanings. </td>
</tr> <tr>
<td align="left" valign="top">• <a href="multiple-targets">Multiple Targets</a>
</td>
<td> </td>
<td align="left" valign="top">When to make use of several targets in a rule. </td>
</tr> <tr>
<td align="left" valign="top">• <a href="multiple-rules">Multiple Rules</a>
</td>
<td> </td>
<td align="left" valign="top">How to use several rules with the same target. </td>
</tr> <tr>
<td align="left" valign="top">• <a href="static-pattern">Static Pattern</a>
</td>
<td> </td>
<td align="left" valign="top">Static pattern rules apply to multiple targets and can vary the prerequisites according to the target name. </td>
</tr> <tr>
<td align="left" valign="top">• <a href="double_002dcolon">Double-Colon</a>
</td>
<td> </td>
<td align="left" valign="top">How to use a special kind of rule to allow several independent rules for one target. </td>
</tr> <tr>
<td align="left" valign="top">• <a href="automatic-prerequisites">Automatic Prerequisites</a>
</td>
<td> </td>
<td align="left" valign="top">How to automatically generate rules giving prerequisites from source files themselves. </td>
</tr> </table><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/Rules.html" class="_attribution-link">https://www.gnu.org/software/make/manual/html_node/Rules.html</a>
  </p>
</div>