Commit | Line | Data |
---|---|---|
eb1e0e80 | 1 | /* Binutils emulation layer. |
13485ea2 AM |
2 | Copyright 2002, 2003, 2005, 2007, 2008, 2010 |
3 | Free Software Foundation, Inc. | |
ad94be02 | 4 | Written by Tom Rix, Red Hat Inc. |
eb1e0e80 NC |
5 | |
6 | This file is part of GNU Binutils. | |
7 | ||
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
32866df7 | 10 | the Free Software Foundation; either version 3 of the License, or |
eb1e0e80 NC |
11 | (at your option) any later version. |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with this program; if not, write to the Free Software | |
32866df7 NC |
20 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
21 | MA 02110-1301, USA. */ | |
eb1e0e80 NC |
22 | |
23 | #include "binemul.h" | |
24 | ||
25 | extern bin_emulation_xfer_type bin_dummy_emulation; | |
26 | ||
27 | void | |
2da42df6 | 28 | ar_emul_usage (FILE *fp) |
eb1e0e80 NC |
29 | { |
30 | if (bin_dummy_emulation.ar_usage) | |
31 | bin_dummy_emulation.ar_usage (fp); | |
32 | } | |
33 | ||
34 | void | |
2da42df6 | 35 | ar_emul_default_usage (FILE *fp) |
eb1e0e80 NC |
36 | { |
37 | AR_EMUL_USAGE_PRINT_OPTION_HEADER (fp); | |
38 | /* xgettext:c-format */ | |
39 | fprintf (fp, _(" No emulation specific options\n")); | |
40 | } | |
41 | ||
b34976b6 | 42 | bfd_boolean |
492d5973 L |
43 | ar_emul_append (bfd **after_bfd, char *file_name, const char *target, |
44 | bfd_boolean verbose, bfd_boolean flatten) | |
eb1e0e80 NC |
45 | { |
46 | if (bin_dummy_emulation.ar_append) | |
492d5973 L |
47 | return bin_dummy_emulation.ar_append (after_bfd, file_name, target, |
48 | verbose, flatten); | |
eb1e0e80 | 49 | |
b34976b6 | 50 | return FALSE; |
eb1e0e80 NC |
51 | } |
52 | ||
a8da6403 | 53 | static bfd_boolean |
13485ea2 AM |
54 | any_ok (bfd *new_bfd ATTRIBUTE_UNUSED) |
55 | { | |
56 | return TRUE; | |
57 | } | |
58 | ||
59 | bfd_boolean | |
60 | do_ar_emul_append (bfd **after_bfd, bfd *new_bfd, | |
61 | bfd_boolean verbose, bfd_boolean flatten, | |
62 | bfd_boolean (*check) (bfd *)) | |
63 | { | |
a8da6403 NC |
64 | /* When flattening, add the members of an archive instead of the |
65 | archive itself. */ | |
66 | if (flatten && bfd_check_format (new_bfd, bfd_archive)) | |
67 | { | |
68 | bfd *elt; | |
69 | bfd_boolean added = FALSE; | |
70 | ||
71 | for (elt = bfd_openr_next_archived_file (new_bfd, NULL); | |
72 | elt; | |
73 | elt = bfd_openr_next_archived_file (new_bfd, elt)) | |
74 | { | |
13485ea2 | 75 | if (do_ar_emul_append (after_bfd, elt, verbose, TRUE, check)) |
a8da6403 NC |
76 | { |
77 | added = TRUE; | |
78 | after_bfd = &((*after_bfd)->archive_next); | |
79 | } | |
80 | } | |
81 | ||
82 | return added; | |
83 | } | |
84 | ||
13485ea2 AM |
85 | if (!check (new_bfd)) |
86 | return FALSE; | |
87 | ||
a8da6403 NC |
88 | AR_EMUL_APPEND_PRINT_VERBOSE (verbose, new_bfd->filename); |
89 | ||
90 | new_bfd->archive_next = *after_bfd; | |
91 | *after_bfd = new_bfd; | |
92 | ||
93 | return TRUE; | |
94 | } | |
95 | ||
b34976b6 | 96 | bfd_boolean |
2da42df6 | 97 | ar_emul_default_append (bfd **after_bfd, char *file_name, |
492d5973 L |
98 | const char *target, bfd_boolean verbose, |
99 | bfd_boolean flatten) | |
eb1e0e80 | 100 | { |
a8da6403 | 101 | bfd *new_bfd; |
eb1e0e80 | 102 | |
492d5973 | 103 | new_bfd = bfd_openr (file_name, target); |
a8da6403 | 104 | AR_EMUL_ELEMENT_CHECK (new_bfd, file_name); |
13485ea2 | 105 | return do_ar_emul_append (after_bfd, new_bfd, verbose, flatten, any_ok); |
eb1e0e80 NC |
106 | } |
107 | ||
b34976b6 | 108 | bfd_boolean |
492d5973 L |
109 | ar_emul_replace (bfd **after_bfd, char *file_name, const char *target, |
110 | bfd_boolean verbose) | |
eb1e0e80 NC |
111 | { |
112 | if (bin_dummy_emulation.ar_replace) | |
492d5973 L |
113 | return bin_dummy_emulation.ar_replace (after_bfd, file_name, |
114 | target, verbose); | |
eb1e0e80 | 115 | |
b34976b6 | 116 | return FALSE; |
eb1e0e80 NC |
117 | } |
118 | ||
b34976b6 | 119 | bfd_boolean |
2da42df6 | 120 | ar_emul_default_replace (bfd **after_bfd, char *file_name, |
492d5973 | 121 | const char *target, bfd_boolean verbose) |
eb1e0e80 | 122 | { |
13485ea2 | 123 | bfd *new_bfd; |
eb1e0e80 | 124 | |
13485ea2 AM |
125 | new_bfd = bfd_openr (file_name, target); |
126 | AR_EMUL_ELEMENT_CHECK (new_bfd, file_name); | |
eb1e0e80 | 127 | |
eb1e0e80 NC |
128 | AR_EMUL_REPLACE_PRINT_VERBOSE (verbose, file_name); |
129 | ||
13485ea2 AM |
130 | new_bfd->archive_next = *after_bfd; |
131 | *after_bfd = new_bfd; | |
eb1e0e80 | 132 | |
b34976b6 | 133 | return TRUE; |
eb1e0e80 NC |
134 | } |
135 | ||
b34976b6 | 136 | bfd_boolean |
2da42df6 | 137 | ar_emul_parse_arg (char *arg) |
eb1e0e80 NC |
138 | { |
139 | if (bin_dummy_emulation.ar_parse_arg) | |
140 | return bin_dummy_emulation.ar_parse_arg (arg); | |
141 | ||
b34976b6 | 142 | return FALSE; |
eb1e0e80 NC |
143 | } |
144 | ||
b34976b6 | 145 | bfd_boolean |
2da42df6 | 146 | ar_emul_default_parse_arg (char *arg ATTRIBUTE_UNUSED) |
eb1e0e80 | 147 | { |
b34976b6 | 148 | return FALSE; |
eb1e0e80 | 149 | } |