summaryrefslogtreecommitdiff
path: root/devdocs/gnu_make/last-resort.html
blob: e608f799f92cf273b9849367ff7b5775f3a3e02a (plain)
1
2
3
4
5
6
7
8
9
10
11
  <h1 class="section">Defining Last-Resort Default Rules</h1>   <p>You can define a last-resort implicit rule by writing a terminal match-anything pattern rule with no prerequisites (see <a href="match_002danything-rules">Match-Anything Rules</a>). This is just like any other pattern rule; the only thing special about it is that it will match any target. So such a rule’s recipe is used for all targets and prerequisites that have no recipe of their own and for which no other implicit rule applies. </p> <p>For example, when testing a makefile, you might not care if the source files contain real data, only that they exist. Then you might do this: </p> <div class="example"> <pre class="example">%::
        touch $@
</pre>
</div> <p>to cause all the source files needed (as prerequisites) to be created automatically. </p>  <p>You can instead define a recipe to be used for targets for which there are no rules at all, even ones which don’t specify recipes. You do this by writing a rule for the target <code>.DEFAULT</code>. Such a rule’s recipe is used for all prerequisites which do not appear as targets in any explicit rule, and for which no implicit rule applies. Naturally, there is no <code>.DEFAULT</code> rule unless you write one. </p> <p>If you use <code>.DEFAULT</code> with no recipe or prerequisites: </p> <div class="example"> <pre class="example">.DEFAULT:
</pre>
</div> <p>the recipe previously stored for <code>.DEFAULT</code> is cleared. Then <code>make</code> acts as if you had never defined <code>.DEFAULT</code> at all. </p> <p>If you do not want a target to get the recipe from a match-anything pattern rule or <code>.DEFAULT</code>, but you also do not want any recipe to be run for the target, you can give it an empty recipe (see <a href="empty-recipes">Defining Empty Recipes</a>). </p> <p>You can use a last-resort rule to override part of another makefile. See <a href="overriding-makefiles">Overriding Part of Another Makefile</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/Last-Resort.html" class="_attribution-link">https://www.gnu.org/software/make/manual/html_node/Last-Resort.html</a>
  </p>
</div>