/usr/share/doc/make-doc/make.html/Archives.html is in make-doc 4.2.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- This file documents the GNU make utility, which determines
automatically which pieces of a large program need to be recompiled,
and issues the commands to recompile them.
This is Edition 0.74, last updated 21 May 2016,
of The GNU Make Manual, for GNU make version 4.2.1.
Copyright (C) 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 Free Software
Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with no
Invariant Sections, with the Front-Cover Texts being "A GNU Manual,"
and with the Back-Cover Texts as in (a) below. A copy of the
license is included in the section entitled "GNU Free Documentation
License."
(a) The FSF's Back-Cover Text is: "You have the freedom to copy and
modify this GNU manual. Buying copies from the FSF supports it in
developing GNU and promoting software freedom." -->
<!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Archives (GNU make)</title>
<meta name="description" content="Archives (GNU make)">
<meta name="keywords" content="Archives (GNU make)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<link href="index.html#Top" rel="start" title="Top">
<link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="index.html#Top" rel="up" title="Top">
<link href="Extending-make.html#Extending-make" rel="next" title="Extending make">
<link href="Implicit-Rules.html#Implicit-Rule-Search" rel="prev" title="Implicit Rule Search">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smalllisp {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
ul.no-bullet {list-style: none}
-->
</style>
</head>
<body lang="en">
<a name="Archives"></a>
<div class="header">
<p>
Next: <a href="Extending-make.html#Extending-make" accesskey="n" rel="next">Extending make</a>, Previous: <a href="Implicit-Rules.html#Implicit-Rules" accesskey="p" rel="prev">Implicit Rules</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Using-make-to-Update-Archive-Files"></a>
<h2 class="chapter">11 Using <code>make</code> to Update Archive Files</h2>
<a name="index-archive"></a>
<p><em>Archive files</em> are files containing named sub-files called
<em>members</em>; they are maintained with the program <code>ar</code> and their
main use is as subroutine libraries for linking.
</p>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">• <a href="#Archive-Members" accesskey="1">Archive Members</a>:</td><td> </td><td align="left" valign="top">Archive members as targets.
</td></tr>
<tr><td align="left" valign="top">• <a href="#Archive-Update" accesskey="2">Archive Update</a>:</td><td> </td><td align="left" valign="top">The implicit rule for archive member targets.
</td></tr>
<tr><td align="left" valign="top">• <a href="#Archive-Pitfalls" accesskey="3">Archive Pitfalls</a>:</td><td> </td><td align="left" valign="top">Dangers to watch out for when using archives.
</td></tr>
<tr><td align="left" valign="top">• <a href="#Archive-Suffix-Rules" accesskey="4">Archive Suffix Rules</a>:</td><td> </td><td align="left" valign="top">You can write a special kind of suffix rule
for updating archives.
</td></tr>
</table>
<hr>
<a name="Archive-Members"></a>
<div class="header">
<p>
Next: <a href="#Archive-Update" accesskey="n" rel="next">Archive Update</a>, Previous: <a href="#Archives" accesskey="p" rel="prev">Archives</a>, Up: <a href="#Archives" accesskey="u" rel="up">Archives</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Archive-Members-as-Targets"></a>
<h3 class="section">11.1 Archive Members as Targets</h3>
<a name="index-archive-member-targets"></a>
<p>An individual member of an archive file can be used as a target or
prerequisite in <code>make</code>. You specify the member named <var>member</var> in
archive file <var>archive</var> as follows:
</p>
<div class="example">
<pre class="example"><var>archive</var>(<var>member</var>)
</pre></div>
<p>This construct is available only in targets and prerequisites, not in
recipes! Most programs that you might use in recipes do not support
this syntax and cannot act directly on archive members. Only
<code>ar</code> and other programs specifically designed to operate on
archives can do so. Therefore, valid recipes to update an archive
member target probably must use <code>ar</code>. For example, this rule
says to create a member <samp>hack.o</samp> in archive <samp>foolib</samp> by
copying the file <samp>hack.o</samp>:
</p>
<div class="example">
<pre class="example">foolib(hack.o) : hack.o
ar cr foolib hack.o
</pre></div>
<p>In fact, nearly all archive member targets are updated in just this way
and there is an implicit rule to do it for you. <strong>Please note:</strong> The
‘<samp>c</samp>’ flag to <code>ar</code> is required if the archive file does not
already exist.
</p>
<p>To specify several members in the same archive, you can write all the
member names together between the parentheses. For example:
</p>
<div class="example">
<pre class="example">foolib(hack.o kludge.o)
</pre></div>
<p>is equivalent to:
</p>
<div class="example">
<pre class="example">foolib(hack.o) foolib(kludge.o)
</pre></div>
<a name="index-wildcard_002c-in-archive-member"></a>
<p>You can also use shell-style wildcards in an archive member reference.
See <a href="Rules.html#Wildcards">Using Wildcard Characters in File Names</a>. For
example, ‘<samp>foolib(*.o)</samp>’<!-- /@w --> expands to all existing members of the
<samp>foolib</samp> archive whose names end in ‘<samp>.o</samp>’; perhaps
‘<samp>foolib(hack.o)<!-- /@w --> foolib(kludge.o)<!-- /@w --></samp>’.
</p>
<hr>
<a name="Archive-Update"></a>
<div class="header">
<p>
Next: <a href="#Archive-Pitfalls" accesskey="n" rel="next">Archive Pitfalls</a>, Previous: <a href="#Archive-Members" accesskey="p" rel="prev">Archive Members</a>, Up: <a href="#Archives" accesskey="u" rel="up">Archives</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Implicit-Rule-for-Archive-Member-Targets"></a>
<h3 class="section">11.2 Implicit Rule for Archive Member Targets</h3>
<p>Recall that a target that looks like <samp><var>a</var>(<var>m</var>)</samp> stands for the
member named <var>m</var> in the archive file <var>a</var>.
</p>
<p>When <code>make</code> looks for an implicit rule for such a target, as a special
feature it considers implicit rules that match <samp>(<var>m</var>)</samp>, as well as
those that match the actual target <samp><var>a</var>(<var>m</var>)</samp>.
</p>
<p>This causes one special rule whose target is <samp>(%)</samp> to match. This
rule updates the target <samp><var>a</var>(<var>m</var>)</samp> by copying the file <var>m</var>
into the archive. For example, it will update the archive member target
<samp>foo.a(bar.o)</samp> by copying the <em>file</em> <samp>bar.o</samp> into the
archive <samp>foo.a</samp> as a <em>member</em> named <samp>bar.o</samp>.
</p>
<p>When this rule is chained with others, the result is very powerful.
Thus, ‘<samp>make "foo.a(bar.o)"</samp>’ (the quotes are needed to protect the
‘<samp>(</samp>’ and ‘<samp>)</samp>’ from being interpreted specially by the shell) in
the presence of a file <samp>bar.c</samp> is enough to cause the following
recipe to be run, even without a makefile:
</p>
<div class="example">
<pre class="example">cc -c bar.c -o bar.o
ar r foo.a bar.o
rm -f bar.o
</pre></div>
<p>Here <code>make</code> has envisioned the file <samp>bar.o</samp> as an intermediate
file. See <a href="Implicit-Rules.html#Chained-Rules">Chains of Implicit Rules</a>.
</p>
<p>Implicit rules such as this one are written using the automatic variable
‘<samp>$%</samp>’. See <a href="Implicit-Rules.html#Automatic-Variables">Automatic Variables</a>.
</p>
<p>An archive member name in an archive cannot contain a directory name, but
it may be useful in a makefile to pretend that it does. If you write an
archive member target <samp>foo.a(dir/file.o)</samp>, <code>make</code> will perform
automatic updating with this recipe:
</p>
<div class="example">
<pre class="example">ar r foo.a dir/file.o
</pre></div>
<p>which has the effect of copying the file <samp>dir/file.o</samp> into a member
named <samp>file.o</samp>. In connection with such usage, the automatic variables
<code>%D</code> and <code>%F</code> may be useful.
</p>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">• <a href="#Archive-Symbols" accesskey="1">Archive Symbols</a>:</td><td> </td><td align="left" valign="top">How to update archive symbol directories.
</td></tr>
</table>
<hr>
<a name="Archive-Symbols"></a>
<div class="header">
<p>
Previous: <a href="#Archive-Update" accesskey="p" rel="prev">Archive Update</a>, Up: <a href="#Archive-Update" accesskey="u" rel="up">Archive Update</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Updating-Archive-Symbol-Directories"></a>
<h4 class="subsection">11.2.1 Updating Archive Symbol Directories</h4>
<a name="index-_005f_005f_002eSYMDEF"></a>
<a name="index-updating-archive-symbol-directories"></a>
<a name="index-archive-symbol-directory-updating"></a>
<a name="index-symbol-directories_002c-updating-archive"></a>
<a name="index-directories_002c-updating-archive-symbol"></a>
<p>An archive file that is used as a library usually contains a special member
named <samp>__.SYMDEF</samp> that contains a directory of the external symbol
names defined by all the other members. After you update any other
members, you need to update <samp>__.SYMDEF</samp> so that it will summarize the
other members properly. This is done by running the <code>ranlib</code> program:
</p>
<div class="example">
<pre class="example">ranlib <var>archivefile</var>
</pre></div>
<p>Normally you would put this command in the rule for the archive file,
and make all the members of the archive file prerequisites of that rule.
For example,
</p>
<div class="example">
<pre class="example">libfoo.a: libfoo.a(x.o) libfoo.a(y.o) …
ranlib libfoo.a
</pre></div>
<p>The effect of this is to update archive members <samp>x.o</samp>, <samp>y.o</samp>,
etc., and then update the symbol directory member <samp>__.SYMDEF</samp> by
running <code>ranlib</code>. The rules for updating the members are not shown
here; most likely you can omit them and use the implicit rule which copies
files into the archive, as described in the preceding section.
</p>
<p>This is not necessary when using the GNU <code>ar</code> program, which
updates the <samp>__.SYMDEF</samp> member automatically.
</p>
<hr>
<a name="Archive-Pitfalls"></a>
<div class="header">
<p>
Next: <a href="#Archive-Suffix-Rules" accesskey="n" rel="next">Archive Suffix Rules</a>, Previous: <a href="#Archive-Update" accesskey="p" rel="prev">Archive Update</a>, Up: <a href="#Archives" accesskey="u" rel="up">Archives</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Dangers-When-Using-Archives"></a>
<h3 class="section">11.3 Dangers When Using Archives</h3>
<a name="index-archive_002c-and-parallel-execution"></a>
<a name="index-parallel-execution_002c-and-archive-update"></a>
<a name="index-archive_002c-and-_002dj"></a>
<a name="index-_002dj_002c-and-archive-update"></a>
<p>It is important to be careful when using parallel execution (the
<code>-j</code> switch; see <a href="Recipes.html#Parallel">Parallel Execution</a>) and archives.
If multiple <code>ar</code> commands run at the same time on the same archive
file, they will not know about each other and can corrupt the file.
</p>
<p>Possibly a future version of <code>make</code> will provide a mechanism to
circumvent this problem by serializing all recipes that operate on the
same archive file. But for the time being, you must either write your
makefiles to avoid this problem in some other way, or not use <code>-j</code>.
</p>
<hr>
<a name="Archive-Suffix-Rules"></a>
<div class="header">
<p>
Previous: <a href="#Archive-Pitfalls" accesskey="p" rel="prev">Archive Pitfalls</a>, Up: <a href="#Archives" accesskey="u" rel="up">Archives</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Suffix-Rules-for-Archive-Files"></a>
<h3 class="section">11.4 Suffix Rules for Archive Files</h3>
<a name="index-suffix-rule_002c-for-archive"></a>
<a name="index-archive_002c-suffix-rule-for"></a>
<a name="index-library-archive_002c-suffix-rule-for"></a>
<a name="index-_002ea-_0028archives_0029"></a>
<p>You can write a special kind of suffix rule for dealing with archive
files. See <a href="Implicit-Rules.html#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 $< -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 $< -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>’<!-- /@w --> 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="Implicit-Rules.html#Suffix-Rules">Suffix Rules</a>). Thus a double-suffix rule
‘<samp>.<var>x</var>.a</samp>’<!-- /@w --> produces two pattern rules: ‘<samp>(%.o):<!-- /@w -->
%.<var>x</var><!-- /@w --></samp>’ and ‘<samp>%.a<!-- /@w -->: %.<var>x</var><!-- /@w --></samp>’.
</p>
<hr>
<div class="header">
<p>
Previous: <a href="#Archive-Pitfalls" accesskey="p" rel="prev">Archive Pitfalls</a>, Up: <a href="#Archives" accesskey="u" rel="up">Archives</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>
|