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/command-variables.html | |
new repository
Diffstat (limited to 'devdocs/gnu_make/command-variables.html')
| -rw-r--r-- | devdocs/gnu_make/command-variables.html | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/devdocs/gnu_make/command-variables.html b/devdocs/gnu_make/command-variables.html new file mode 100644 index 00000000..4a14859d --- /dev/null +++ b/devdocs/gnu_make/command-variables.html @@ -0,0 +1,16 @@ + <h1 class="section">Variables for Specifying Commands</h1> <p>Makefiles should provide variables for overriding certain commands, options, and so on. </p> <p>In particular, you should run most utility programs via variables. Thus, if you use Bison, have a variable named <code>BISON</code> whose default value is set with ‘<samp>BISON = bison</samp>’, and refer to it with <code>$(BISON)</code> whenever you need to use Bison. </p> <p>File management utilities such as <code>ln</code>, <code>rm</code>, <code>mv</code>, and so on, need not be referred to through variables in this way, since users don’t need to replace them with other programs. </p> <p>Each program-name variable should come with an options variable that is used to supply options to the program. Append ‘<samp>FLAGS</samp>’ to the program-name variable name to get the options variable name—for example, <code>BISONFLAGS</code>. (The names <code>CFLAGS</code> for the C compiler, <code>YFLAGS</code> for yacc, and <code>LFLAGS</code> for lex, are exceptions to this rule, but we keep them because they are standard.) Use <code>CPPFLAGS</code> in any compilation command that runs the preprocessor, and use <code>LDFLAGS</code> in any compilation command that does linking as well as in any direct use of <code>ld</code>. </p> <p>If there are C compiler options that <em>must</em> be used for proper compilation of certain files, do not include them in <code>CFLAGS</code>. Users expect to be able to specify <code>CFLAGS</code> freely themselves. Instead, arrange to pass the necessary options to the C compiler independently of <code>CFLAGS</code>, by writing them explicitly in the compilation commands or by defining an implicit rule, like this: </p> <div class="example"> <pre class="example">CFLAGS = -g +ALL_CFLAGS = -I. $(CFLAGS) +.c.o: + $(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) $< +</pre> +</div> <p>Do include the ‘<samp>-g</samp>’ option in <code>CFLAGS</code>, because that is not <em>required</em> for proper compilation. You can consider it a default that is only recommended. If the package is set up so that it is compiled with GCC by default, then you might as well include ‘<samp>-O</samp>’ in the default value of <code>CFLAGS</code> as well. </p> <p>Put <code>CFLAGS</code> last in the compilation command, after other variables containing compiler options, so the user can use <code>CFLAGS</code> to override the others. </p> <p><code>CFLAGS</code> should be used in every invocation of the C compiler, both those which do compilation and those which do linking. </p> <p>Every Makefile should define the variable <code>INSTALL</code>, which is the basic command for installing a file into the system. </p> <p>Every Makefile should also define the variables <code>INSTALL_PROGRAM</code> and <code>INSTALL_DATA</code>. (The default for <code>INSTALL_PROGRAM</code> should be <code>$(INSTALL)</code>; the default for <code>INSTALL_DATA</code> should be <code>${INSTALL} -m 644</code>.) Then it should use those variables as the commands for actual installation, for executables and non-executables respectively. Minimal use of these variables is as follows: </p> <div class="example"> <pre class="example">$(INSTALL_PROGRAM) foo $(bindir)/foo +$(INSTALL_DATA) libfoo.a $(libdir)/libfoo.a +</pre> +</div> <p>However, it is preferable to support a <code>DESTDIR</code> prefix on the target files, as explained in the next section. </p> <p>It is acceptable, but not required, to install multiple files in one command, with the final argument being a directory, as in: </p> <div class="example"> <pre class="example">$(INSTALL_PROGRAM) foo bar baz $(bindir) +</pre> +</div><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/Command-Variables.html" class="_attribution-link">https://www.gnu.org/software/make/manual/html_node/Command-Variables.html</a> + </p> +</div> |
