* gas/ppc/altivec_xcoff64.d: Adjust for aix5 target.
[binutils.git] / binutils / emul_aix.c
blob4caf6529a26057a4611f8953d56e21976cfd6d6b
1 /* Binutils emulation layer.
2 Copyright (C) 2002 Free Software Foundation, Inc.
3 Written by Tom Rix, Redhat.
5 This file is part of GNU Binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 #include "binemul.h"
22 #include "bfdlink.h"
23 #include "coff/internal.h"
24 #include "coff/xcoff.h"
25 #include "libcoff.h"
26 #include "libxcoff.h"
28 /* Default to <bigaf>. */
29 static boolean big_archive = true;
31 /* Whether to include 32 bit objects. */
32 static boolean X32 = true;
34 /* Whether to include 64 bit objects. */
35 static boolean X64 = false;
37 static void ar_emul_aix_usage PARAMS ((FILE *));
38 static boolean ar_emul_aix_append PARAMS ((bfd **, char *, boolean));
39 static boolean ar_emul_aix5_append PARAMS ((bfd **, char *, boolean));
40 static boolean ar_emul_aix_replace PARAMS ((bfd **, char *, boolean));
41 static boolean ar_emul_aix5_replace PARAMS ((bfd **, char *, boolean));
42 static boolean ar_emul_aix_parse_arg PARAMS ((char *));
43 static boolean ar_emul_aix_internal PARAMS ((bfd **, char *, boolean,
44 const char *, boolean));
46 static void
47 ar_emul_aix_usage (fp)
48 FILE *fp;
50 AR_EMUL_USAGE_PRINT_OPTION_HEADER (fp);
51 /* xgettext:c-format */
52 fprintf (fp, _(" [-g] - 32 bit small archive\n"));
53 fprintf (fp, _(" [-X32] - ignores 64 bit objects\n"));
54 fprintf (fp, _(" [-X64] - ignores 32 bit objects\n"));
55 fprintf (fp, _(" [-X32_64] - accepts 32 and 64 bit objects\n"));
58 static boolean
59 ar_emul_aix_internal (after_bfd, file_name, verbose, target_name, is_append)
60 bfd **after_bfd;
61 char *file_name;
62 boolean verbose;
63 const char * target_name;
64 boolean is_append;
66 bfd *temp;
67 bfd *try_bfd;
69 temp = *after_bfd;
71 /* Try 64 bit. */
72 try_bfd = bfd_openr (file_name, target_name);
74 /* Failed or the object is possibly 32 bit. */
75 if (NULL == try_bfd || ! bfd_check_format (try_bfd, bfd_object))
76 try_bfd = bfd_openr (file_name, "aixcoff-rs6000");
78 AR_EMUL_ELEMENT_CHECK (try_bfd, file_name);
80 if (bfd_xcoff_is_xcoff64 (try_bfd) && (! X64))
81 return false;
83 if (bfd_xcoff_is_xcoff32 (try_bfd)
84 && bfd_check_format (try_bfd, bfd_object) && (! X32))
85 return false;
87 if (is_append)
89 AR_EMUL_APPEND_PRINT_VERBOSE (verbose, file_name);
91 else
93 AR_EMUL_REPLACE_PRINT_VERBOSE (verbose, file_name);
96 *after_bfd = try_bfd;
97 (*after_bfd)->next = temp;
99 return true;
103 static boolean
104 ar_emul_aix_append (after_bfd, file_name, verbose)
105 bfd **after_bfd;
106 char *file_name;
107 boolean verbose;
109 return ar_emul_aix_internal (after_bfd, file_name, verbose,
110 "aixcoff64-rs6000", true);
113 static boolean
114 ar_emul_aix5_append (after_bfd, file_name, verbose)
115 bfd **after_bfd;
116 char *file_name;
117 boolean verbose;
119 return ar_emul_aix_internal (after_bfd, file_name, verbose,
120 "aix5coff64-rs6000", true);
123 static boolean
124 ar_emul_aix_replace (after_bfd, file_name, verbose)
125 bfd **after_bfd;
126 char *file_name;
127 boolean verbose;
129 return ar_emul_aix_internal (after_bfd, file_name, verbose,
130 "aixcoff64-rs6000", false);
133 static boolean
134 ar_emul_aix5_replace (after_bfd, file_name, verbose)
135 bfd **after_bfd;
136 char *file_name;
137 boolean verbose;
139 return ar_emul_aix_internal (after_bfd, file_name, verbose,
140 "aix5coff64-rs6000", false);
143 boolean
144 ar_emul_aix_create (abfd_out, archive_file_name, file_name)
145 bfd **abfd_out;
146 char *archive_file_name;
147 char *file_name ATTRIBUTE_UNUSED;
149 char *target = "aixcoff-rs6000";
151 /* Create an empty archive. */
152 *abfd_out = bfd_openw (archive_file_name, target);
154 if (*abfd_out == NULL)
155 bfd_fatal (archive_file_name);
157 /* set to small or big format. */
158 /* not done. */
159 return true;
162 static boolean
163 ar_emul_aix_parse_arg (arg)
164 char *arg;
166 if (strncmp (arg, "-X32_64", 6) == 0)
168 big_archive = true;
169 X32 = true;
170 X64 = true;
172 else if (strncmp (arg, "-X32", 3) == 0)
174 big_archive = true;
175 X32 = true;
176 X64 = false;
178 else if (strncmp (arg, "-X64", 3) == 0)
180 big_archive = true;
181 X32 = false;
182 X64 = true;
184 else if (strncmp (arg, "-g", 2) == 0)
186 big_archive = false;
187 X32 = true;
188 X64 = false;
190 else
191 return false;
193 return true;
196 struct bin_emulation_xfer_struct bin_aix_emulation =
198 ar_emul_aix_usage,
199 ar_emul_aix_append,
200 ar_emul_aix_replace,
201 ar_emul_default_create,
202 ar_emul_aix_parse_arg,
205 struct bin_emulation_xfer_struct bin_aix5_emulation =
207 ar_emul_aix_usage,
208 ar_emul_aix5_append,
209 ar_emul_aix5_replace,
210 ar_emul_default_create,
211 ar_emul_aix_parse_arg,