diff options
| author | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
| commit | 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch) | |
| tree | f1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/gnu_make/make-deduces.html | |
new repository
Diffstat (limited to 'devdocs/gnu_make/make-deduces.html')
| -rw-r--r-- | devdocs/gnu_make/make-deduces.html | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/devdocs/gnu_make/make-deduces.html b/devdocs/gnu_make/make-deduces.html new file mode 100644 index 00000000..747b1840 --- /dev/null +++ b/devdocs/gnu_make/make-deduces.html @@ -0,0 +1,25 @@ + <h1 class="section">Letting make Deduce the Recipes</h1> <p>It is not necessary to spell out the recipes for compiling the individual C source files, because <code>make</code> can figure them out: it has an <em>implicit rule</em> for updating a ‘<samp>.o</samp>’ file from a correspondingly named ‘<samp>.c</samp>’ file using a ‘<samp>cc -c</samp>’ command. For example, it will use the recipe ‘<samp>cc -c main.c -o main.o</samp>’ to compile <samp>main.c</samp> into <samp>main.o</samp>. We can therefore omit the recipes from the rules for the object files. See <a href="implicit-rules">Using Implicit Rules</a>. </p> <p>When a ‘<samp>.c</samp>’ file is used automatically in this way, it is also automatically added to the list of prerequisites. We can therefore omit the ‘<samp>.c</samp>’ files from the prerequisites, provided we omit the recipe. </p> <p>Here is the entire example, with both of these changes, and a variable <code>objects</code> as suggested above: </p> <div class="example"> <pre class="example">objects = main.o kbd.o command.o display.o \ + insert.o search.o files.o utils.o + +edit : $(objects) + cc -o edit $(objects) + +main.o : defs.h +kbd.o : defs.h command.h +command.o : defs.h command.h +display.o : defs.h buffer.h +insert.o : defs.h buffer.h +search.o : defs.h buffer.h +files.o : defs.h buffer.h command.h +utils.o : defs.h + +.PHONY : clean +clean : + rm edit $(objects) +</pre> +</div> <p>This is how we would write the makefile in actual practice. (The complications associated with ‘<samp>clean</samp>’ are described elsewhere. See <a href="phony-targets">Phony Targets</a>, and <a href="errors">Errors in Recipes</a>.) </p> <p>Because implicit rules are so convenient, they are important. You will see them used frequently. </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/make-Deduces.html" class="_attribution-link">https://www.gnu.org/software/make/manual/html_node/make-Deduces.html</a> + </p> +</div> |
