summaryrefslogtreecommitdiff
path: root/devdocs/gnu_make/utilities-in-makefiles.html
blob: 60dd10c0054b277e47a21cbc0d375669a39e60e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  <h1 class="section">Utilities in Makefiles</h1> <p>Write the Makefile commands (and any shell scripts, such as <code>configure</code>) to run under <code>sh</code> (both the traditional Bourne shell and the <small>POSIX</small> shell), not <code>csh</code>. Don’t use any special features of <code>ksh</code> or <code>bash</code>, or <small>POSIX</small> features not widely supported in traditional Bourne <code>sh</code>. </p> <p>The <code>configure</code> script and the Makefile rules for building and installation should not use any utilities directly except these: </p> <div class="example"> <pre class="example">awk cat cmp cp diff echo egrep expr false grep install-info ln ls
mkdir mv printf pwd rm rmdir sed sleep sort tar test touch tr true
</pre>
</div> <p>Compression programs such as <code>gzip</code> can be used in the <code>dist</code> rule. </p> <p>Generally, stick to the widely-supported (usually <small>POSIX</small>-specified) options and features of these programs. For example, don’t use ‘<samp>mkdir -p</samp>’, convenient as it may be, because a few systems don’t support it at all and with others, it is not safe for parallel execution. For a list of known incompatibilities, see <a href="https://www.gnu.org/software/autoconf/manual/html_node/Portable-Shell.html#Portable-Shell">Portable Shell Programming</a> in <cite>Autoconf</cite>. </p> <p>It is a good idea to avoid creating symbolic links in makefiles, since a few file systems don’t support them. </p> <p>The Makefile rules for building and installation can also use compilers and related programs, but should do so via <code>make</code> variables so that the user can substitute alternatives. Here are some of the programs we mean: </p> <div class="example"> <pre class="example">ar bison cc flex install ld ldconfig lex
make makeinfo ranlib texi2dvi yacc
</pre>
</div> <p>Use the following <code>make</code> variables to run those programs: </p> <div class="example"> <pre class="example">$(AR) $(BISON) $(CC) $(FLEX) $(INSTALL) $(LD) $(LDCONFIG) $(LEX)
$(MAKE) $(MAKEINFO) $(RANLIB) $(TEXI2DVI) $(YACC)
</pre>
</div> <p>When you use <code>ranlib</code> or <code>ldconfig</code>, you should make sure nothing bad happens if the system does not have the program in question. Arrange to ignore an error from that command, and print a message before the command to tell the user that failure of this command does not mean a problem. (The Autoconf ‘<samp>AC_PROG_RANLIB</samp>’ macro can help with this.) </p> <p>If you use symbolic links, you should implement a fallback for systems that don’t have symbolic links. </p> <p>Additional utilities that can be used via Make variables are: </p> <div class="example"> <pre class="example">chgrp chmod chown mknod
</pre>
</div> <p>It is ok to use other utilities in Makefile portions (or scripts) intended only for particular systems where you know those utilities exist. </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/Utilities-in-Makefiles.html" class="_attribution-link">https://www.gnu.org/software/make/manual/html_node/Utilities-in-Makefiles.html</a>
  </p>
</div>