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