summaryrefslogtreecommitdiff
path: root/devdocs/gnu_make/archive-suffix-rules.html
blob: e0c75430083d37d68c2c39df154c0caf7addbe12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  <h1 class="section">Suffix Rules for Archive Files</h1>     <p>You can write a special kind of suffix rule for dealing with archive files. See <a href="suffix-rules">Suffix Rules</a>, for a full explanation of suffix rules. Archive suffix rules are obsolete in GNU <code>make</code>, because pattern rules for archives are a more general mechanism (see <a href="archive-update">Archive Update</a>). But they are retained for compatibility with other <code>make</code>s. </p> <p>To write a suffix rule for archives, you simply write a suffix rule using the target suffix ‘<samp>.a</samp>’ (the usual suffix for archive files). For example, here is the old-fashioned suffix rule to update a library archive from C source files: </p> <div class="example"> <pre class="example">.c.a:
        $(CC) $(CFLAGS) $(CPPFLAGS) -c $&lt; -o $*.o
        $(AR) r $@ $*.o
        $(RM) $*.o
</pre>
</div> <p>This works just as if you had written the pattern rule: </p> <div class="example"> <pre class="example">(%.o): %.c
        $(CC) $(CFLAGS) $(CPPFLAGS) -c $&lt; -o $*.o
        $(AR) r $@ $*.o
        $(RM) $*.o
</pre>
</div> <p>In fact, this is just what <code>make</code> does when it sees a suffix rule with ‘<samp>.a</samp>’ as the target suffix. Any double-suffix rule ‘<samp>.<var>x</var>.a</samp>’ is converted to a pattern rule with the target pattern ‘<samp>(%.o)</samp>’ and a prerequisite pattern of ‘<samp>%.<var>x</var></samp>’. </p> <p>Since you might want to use ‘<samp>.a</samp>’ as the suffix for some other kind of file, <code>make</code> also converts archive suffix rules to pattern rules in the normal way (see <a href="suffix-rules">Suffix Rules</a>). Thus a double-suffix rule ‘<samp>.<var>x</var>.a</samp>’ produces two pattern rules: ‘<samp>(%.o): %.<var>x</var></samp>’ and ‘<samp>%.a: %.<var>x</var></samp>’. </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/Archive-Suffix-Rules.html" class="_attribution-link">https://www.gnu.org/software/make/manual/html_node/Archive-Suffix-Rules.html</a>
  </p>
</div>