]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - usr.bin/ar/ar.1
MFC r287327: ar: Deobfuscate a while loop
[FreeBSD/stable/10.git] / usr.bin / ar / ar.1
1 .\" Copyright (c) 2007 Joseph Koshy.  All rights reserved.
2 .\"
3 .\" Redistribution and use in source and binary forms, with or without
4 .\" modification, are permitted provided that the following conditions
5 .\" are met:
6 .\" 1. Redistributions of source code must retain the above copyright
7 .\"    notice, this list of conditions and the following disclaimer.
8 .\" 2. Redistributions in binary form must reproduce the above copyright
9 .\"    notice, this list of conditions and the following disclaimer in the
10 .\"    documentation and/or other materials provided with the distribution.
11 .\"
12 .\" This software is provided by Joseph Koshy ``as is'' and
13 .\" any express or implied warranties, including, but not limited to, the
14 .\" implied warranties of merchantability and fitness for a particular purpose
15 .\" are disclaimed.  in no event shall Joseph Koshy be liable
16 .\" for any direct, indirect, incidental, special, exemplary, or consequential
17 .\" damages (including, but not limited to, procurement of substitute goods
18 .\" or services; loss of use, data, or profits; or business interruption)
19 .\" however caused and on any theory of liability, whether in contract, strict
20 .\" liability, or tort (including negligence or otherwise) arising in any way
21 .\" out of the use of this software, even if advised of the possibility of
22 .\" such damage.
23 .\"
24 .\" $FreeBSD$
25 .\"
26 .Dd August 31, 2015
27 .Dt AR 1
28 .Os
29 .Sh NAME
30 .Nm ar ,
31 .Nm ranlib
32 .Nd manage archives
33 .Sh SYNOPSIS
34 .Nm
35 .Fl d
36 .Op Fl T
37 .Op Fl f
38 .Op Fl j
39 .Op Fl v
40 .Op Fl z
41 .Ar archive
42 .Ar
43 .Nm
44 .Fl m
45 .Op Fl T
46 .Op Fl a Ar position-after
47 .Op Fl b Ar position-before
48 .Op Fl f
49 .Op Fl i Ar position-before
50 .Op Fl j
51 .Op Fl s | Fl S
52 .Op Fl z
53 .Ar archive
54 .Ar
55 .Nm
56 .Fl p
57 .Op Fl T
58 .Op Fl f
59 .Op Fl v
60 .Ar archive
61 .Op Ar
62 .Nm
63 .Fl q
64 .Op Fl T
65 .Op Fl c
66 .Op Fl D
67 .Op Fl f
68 .Op Fl s | Fl S
69 .Op Fl U
70 .Op Fl v
71 .Op Fl z
72 .Ar archive
73 .Ar
74 .Nm
75 .Fl r
76 .Op Fl T
77 .Op Fl a Ar position-after
78 .Op Fl b Ar position-before
79 .Op Fl c
80 .Op Fl D
81 .Op Fl f
82 .Op Fl i Ar position-before
83 .Op Fl j
84 .Op Fl s | Fl S
85 .Op Fl u
86 .Op Fl U
87 .Op Fl v
88 .Op Fl z
89 .Ar archive
90 .Ar
91 .Nm
92 .Fl s
93 .Op Fl j
94 .Op Fl z
95 .Ar archive
96 .Nm
97 .Fl t
98 .Op Fl f
99 .Op Fl T
100 .Op Fl v
101 .Ar archive
102 .Op Ar
103 .Nm
104 .Fl x
105 .Op Fl C
106 .Op Fl T
107 .Op Fl f
108 .Op Fl o
109 .Op Fl u
110 .Op Fl v
111 .Ar archive
112 .Op Ar
113 .Nm
114 .Fl M
115 .Nm ranlib
116 .Op Fl D
117 .Op Fl U
118 .Ar archive ...
119 .Sh DESCRIPTION
120 The
121 .Nm
122 utility creates and maintains groups of files combined into an
123 archive.
124 Once an archive has been created, new files can be added to it, and
125 existing files can be extracted, deleted or replaced.
126 .Pp
127 Files are named in the archive by their last file name component,
128 so if a file referenced by a path containing a
129 .Dq /
130 is archived, it will be named by the last component of the path.
131 Similarly when matching paths listed on the command line against
132 file names stored in the archive, only the last component of the
133 path will be compared.
134 .Pp
135 The normal use of
136 .Nm
137 is for the creation and maintenance of libraries suitable for use
138 with the link editor
139 .Xr ld 1 ,
140 although it is not restricted to this purpose.
141 The
142 .Nm
143 utility can create and manage an archive symbol table (see
144 .Xr ar 5 )
145 used to speed up link editing operations.
146 If a symbol table is present in an archive, it will be
147 kept up-to-date by subsequent operations on the archive.
148 .Pp
149 The
150 .Nm ranlib
151 utility is used to add an archive symbol table
152 to an existing archive.
153 .Sh OPTIONS
154 The
155 .Nm
156 utility supports the following options:
157 .Bl -tag -width indent
158 .It Fl a Ar member-after
159 When used with option
160 .Fl m
161 this option specifies that the archive members specified by
162 arguments
163 .Ar
164 are moved to after the archive member named by argument
165 .Ar member-after .
166 When used with option
167 .Fl r
168 this option specifies that the files specified by arguments
169 .Ar
170 are added after the archive member named by argument
171 .Ar member-after .
172 .It Fl b Ar member-before
173 When used with option
174 .Fl m
175 this option specifies that the archive members specified by
176 arguments
177 .Ar
178 are moved to before the archive member named by argument
179 .Ar member-before .
180 When used with option
181 .Fl r
182 this option specifies that the files specified by arguments
183 .Ar
184 are added before the archive member named by argument
185 .Ar member-before .
186 .It Fl c
187 Suppress the informational message printed when a new archive is
188 created using the
189 .Fl r
190 and
191 .Fl q
192 options.
193 .It Fl C
194 Prevent extracted files from replacing like-named files
195 in the file system.
196 .It Fl d
197 Delete the members named by arguments
198 .Ar
199 from the archive specified by argument
200 .Ar archive .
201 The archive's symbol table, if present, is updated to reflect
202 the new contents of the archive.
203 .It Fl D
204 When used in combination with the
205 .Fl r
206 or
207 .Fl q
208 option, insert 0's instead of the real mtime, uid and gid values
209 and 0644 instead of file mode from the members named by arguments
210 .Ar .
211 This ensures that checksums on the resulting archives are reproducible
212 when member contents are identical.
213 If multiple
214 .Fl D
215 and
216 .Fl U
217 options are specified on the command line, the final one takes precedence.
218 .It Fl f
219 Synonymous with option
220 .Fl T .
221 .It Fl i Ar member-before
222 Synonymous with option
223 .Fl b .
224 .It Fl j
225 This option is accepted but ignored.
226 .It Fl l
227 This option is accepted for compatibility with GNU
228 .Xr ar 1 ,
229 but is ignored.
230 .It Fl m
231 Move archive members specified by arguments
232 .Ar
233 within the archive.
234 If a position has been specified by one of the
235 .Fl a ,
236 .Fl b
237 or
238 .Fl i
239 options, the members are moved to before or after the specified
240 position.
241 If no position has been specified, the specified members are moved
242 to the end of the archive.
243 If the archive has a symbol table, it is updated to reflect the
244 new contents of the archive.
245 .It Fl M
246 Read and execute MRI librarian commands from standard input.
247 The commands understood by the
248 .Nm
249 utility are described in the section
250 .Sx "MRI Librarian Commands" .
251 .It Fl o
252 Preserve the original modification times of members when extracting
253 them.
254 .It Fl p
255 Write the contents of the specified archive members named by
256 arguments
257 .Ar
258 to standard output.
259 If no members were specified, the contents of all the files in the
260 archive are written in the order they appear in the archive.
261 .It Fl q
262 Append the files specified by arguments
263 .Ar
264 to the archive specified by argument
265 .Ar archive
266 without checking if the files already exist in the archive.
267 The archive symbol table will be updated as needed.
268 If the file specified by the argument
269 .Ar archive
270 does not already exist, a new archive will be created.
271 .It Fl r
272 Replace (add) the files specified by arguments
273 .Ar
274 in the archive specified by argument
275 .Ar archive ,
276 creating the archive if necessary.
277 Replacing existing members will not change the order of members within
278 the archive.
279 If a file named in arguments
280 .Ar
281 does not exist, existing members in the archive that match that
282 name are not changed.
283 New files are added to the end of the archive unless one of the
284 positioning options
285 .Fl a ,
286 .Fl b
287 or
288 .Fl i
289 is specified.
290 The archive symbol table, if it exists, is updated to reflect the
291 new state of the archive.
292 .It Fl s
293 Add an archive symbol table (see
294 .Xr ar 5 )
295 to the archive specified by argument
296 .Ar archive .
297 Invoking
298 .Nm
299 with the
300 .Fl s
301 option alone is equivalent to invoking
302 .Nm ranlib .
303 .It Fl S
304 Do not generate an archive symbol table.
305 .It Fl t
306 List the files specified by arguments
307 .Ar
308 in the order in which they appear in the archive, one per line.
309 If no files are specified, all files in the archive are listed.
310 .It Fl T
311 Use only the first fifteen characters of the archive member name or
312 command line file name argument when naming archive members.
313 .It Fl u
314 Conditionally update the archive or extract members.
315 When used with the
316 .Fl r
317 option, files named by arguments
318 .Ar
319 will be replaced in the archive if they are newer than their
320 archived versions.
321 When used with the
322 .Fl x
323 option, the members specified by arguments
324 .Ar
325 will be extracted only if they are newer than the corresponding
326 files in the file system.
327 .It Fl U
328 When used in combination with the
329 .Fl r
330 or
331 .Fl q
332 option, insert the real mtime, uid and gid, and file mode values
333 from the members named by arguments
334 .Ar .
335 If multiple
336 .Fl D
337 and
338 .Fl U
339 options are specified on the command line, the final one takes precedence.
340 .It Fl v
341 Provide verbose output.
342 When used with the
343 .Fl d ,
344 .Fl m ,
345 .Fl q
346 or
347 .Fl x
348 options,
349 .Nm
350 gives a file-by-file description of the archive modification being
351 performed, which consists of three white-space separated fields:
352 the option letter, a dash
353 .Dq "-" ,
354 and the file name.
355 When used with the
356 .Fl r
357 option,
358 .Nm
359 displays the description as above, but the initial letter is an
360 .Dq a
361 if the file is added to the archive, or an
362 .Dq r
363 if the file replaces a file already in the archive.
364 When used with the
365 .Fl p
366 option, the name of the file enclosed in
367 .Dq <
368 and
369 .Dq >
370 characters is written to standard output preceded by a single newline
371 character and followed by two newline characters.
372 The contents of the named file follow the file name.
373 When used with the
374 .Fl t
375 option,
376 .Nm
377 displays eight whitespace separated fields:
378 the file permissions as displayed by
379 .Xr strmode 3 ,
380 decimal user and group IDs separated by a slash (
381 .Dq / Ns ) ,
382 the file size in bytes, the file modification time in
383 .Xr strftime 3
384 format
385 .Dq "%b %e %H:%M %Y" ,
386 and the name of the file.
387 .It Fl V
388 Print a version string and exit.
389 .It Fl x
390 Extract archive members specified by arguments
391 .Ar
392 into the current directory.
393 If no members have been specified, extract all members of the archive.
394 If the file corresponding to an extracted member does not exist it
395 will be created.
396 If the file corresponding to an extracted member does exist, its owner
397 and group will not be changed while its contents will be overwritten
398 and its permissions will set to that entered in the archive.
399 The file's access and modification time would be that of the time
400 of extraction unless the
401 .Fl o
402 option was specified.
403 .It Fl z
404 This option is accepted but ignored.
405 .El
406 .Ss "MRI Librarian Commands"
407 If the
408 .Fl M
409 option is specified, the
410 .Nm
411 utility will read and execute commands from its standard input.
412 If standard input is a terminal, the
413 .Nm
414 utility will display the prompt
415 .Dq Li "AR >"
416 before reading a line, and will continue operation even if errors are
417 encountered.
418 If standard input is not a terminal, the
419 .Nm
420 utility will not display a prompt and will terminate execution on
421 encountering an error.
422 .Pp
423 Each input line contains a single command.
424 Words in an input line are separated by whitespace characters.
425 The first word of the line is the command, the remaining words are
426 the arguments to the command.
427 The command word may be specified in either case.
428 Arguments may be separated by commas or blanks.
429 .Pp
430 Empty lines are allowed and are ignored.
431 Long lines are continued by ending them with the
432 .Dq Li +
433 character.
434 .Pp
435 The
436 .Dq Li *
437 and
438 .Dq Li "\&;"
439 characters start a comment.
440 Comments extend till the end of the line.
441 .Pp
442 When executing an MRI librarian script the
443 .Nm
444 utility works on a temporary copy of an archive.
445 Changes to the copy are made permanent using the
446 .Ic save
447 command.
448 .Pp
449 Commands understood by the
450 .Nm
451 utility are:
452 .Bl -tag -width indent
453 .It Ic addlib Ar archive | Ic addlib Ar archive Pq Ar member Oo Li , Ar member Oc Ns ...
454 Add the contents of the archive named by argument
455 .Ar archive
456 to the current archive.
457 If specific members are named using the arguments
458 .Ar member ,
459 then those members are added to the current archive.
460 If no members are specified, the entire contents of the archive
461 are added to the current archive.
462 .It Ic addmod Ar member Oo Li , Ar member Oc Ns ...
463 Add the files named by arguments
464 .Ar member
465 to the current archive.
466 .It Ic clear
467 Discard all the contents of the current archive.
468 .It Ic create Ar archive
469 Create a new archive named by the argument
470 .Ar archive ,
471 and makes it the current archive.
472 If the named archive already exists, it will be overwritten
473 when the
474 .Ic save
475 command is issued.
476 .It Ic delete Ar module Oo Li , Ar member Oc Ns ...
477 Delete the modules named by the arguments
478 .Ar member
479 from the current archive.
480 .It Ic directory Ar archive Po Ar member Oo Li , Ar member Oc Ns ... Pc Op Ar outputfile
481 List each named module in the archive.
482 The format of the output depends on the verbosity setting set using
483 the
484 .Ic verbose
485 command.
486 Output is sent to standard output, or to the file specified by
487 argument
488 .Ar outputfile .
489 .It Ic end
490 Exit successfully from the
491 .Nm
492 utility.
493 Any unsaved changes to the current archive will be discarded.
494 .It Ic extract Ar member Oo Li , Ar member Oc Ns ...
495 Extract the members named by the arguments
496 .Ar member
497 from the current archive.
498 .It Ic list
499 Display the contents of the current archive in verbose style.
500 .It Ic open Ar archive
501 Open the archive named by argument
502 .Ar archive
503 and make it the current archive.
504 .It Ic replace Ar member Oo Li , Ar member Oc Ns ...
505 Replace named members in the current archive with the files specified
506 by arguments
507 .Ar member .
508 The files must be present in the current directory and the named
509 modules must already exist in the current archive.
510 .It Ic save
511 Commit all changes to the current archive.
512 .It Ic verbose
513 Toggle the verbosity of the
514 .Ic directory
515 command.
516 .El
517 .Sh EXAMPLES
518 To create a new archive
519 .Pa ex.a
520 containing three files
521 .Pa ex1.o ,
522 .Pa ex2.o
523 and
524 .Pa ex3.o ,
525 use:
526 .Dl "ar -rc ex.a ex1.o ex2.o ex3.o"
527 .Pp
528 To add an archive symbol table to an existing archive
529 .Pa ex.a ,
530 use:
531 .Dl "ar -s ex.a"
532 .Pp
533 To delete file
534 .Pa ex1.o
535 from archive
536 .Pa ex.a ,
537 use:
538 .D1 "ar -d ex.a ex1.o"
539 .Pp
540 To verbosely list the contents of archive
541 .Pa ex.a ,
542 use:
543 .D1 "ar -tv ex.a"
544 .Pp
545 To create a new archive
546 .Pa ex.a
547 containing the files
548 .Pa ex1.o ,
549 and
550 .Pa ex2.o ,
551 using MRI librarian commands, use the following script:
552 .Bd -literal -offset indent
553 create ex.a              * specify the output archive
554 addmod ex1.o ex2.o       * add modules
555 save                     * save pending changes
556 end                      * exit the utility
557 .Ed
558 .Sh DIAGNOSTICS
559 .Ex -std
560 .Sh SEE ALSO
561 .Xr ld 1 ,
562 .Xr archive 3 ,
563 .Xr elf 3 ,
564 .Xr strftime 3 ,
565 .Xr strmode 3 ,
566 .Xr ar 5
567 .Sh STANDARDS COMPLIANCE
568 The
569 .Nm
570 utility's support for the
571 .Fl a ,
572 .Fl b ,
573 .Fl c ,
574 .Fl i ,
575 .Fl m ,
576 .Fl p ,
577 .Fl q ,
578 .Fl r ,
579 .Fl s ,
580 .Fl t ,
581 .Fl u ,
582 .Fl v ,
583 .Fl C
584 and
585 .Fl T
586 options is believed to be compliant with
587 .St -p1003.2 .
588 .Sh HISTORY
589 An
590 .Nm
591 command first appeared in AT&T UNIX Version 1.
592 In
593 .Fx 8.0 ,
594 .An "Kai Wang" Aq kaiw@FreeBSD.org
595 reimplemented
596 .Nm
597 and
598 .Nm ranlib
599 using the
600 .Lb libarchive
601 and the
602 .Lb libelf .