2009-09-02 Tristan Gingold <gingold@adacore.com>
[binutils.git] / binutils / emul_aix.c
blob256bfd11da09c8b0156d4c6b9d61ab9551845bdb
1 /* Binutils emulation layer.
2 Copyright 2002, 2003, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
3 Written by Tom Rix, Red Hat Inc.
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 3 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., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
22 #include "binemul.h"
23 #include "bfdlink.h"
24 #include "coff/internal.h"
25 #include "coff/xcoff.h"
26 #include "libcoff.h"
27 #include "libxcoff.h"
29 /* Default to <bigaf>. */
30 static bfd_boolean big_archive = TRUE;
32 /* Whether to include 32 bit objects. */
33 static bfd_boolean X32 = TRUE;
35 /* Whether to include 64 bit objects. */
36 static bfd_boolean X64 = FALSE;
38 static void
39 ar_emul_aix_usage (FILE *fp)
41 AR_EMUL_USAGE_PRINT_OPTION_HEADER (fp);
42 /* xgettext:c-format */
43 fprintf (fp, _(" [-g] - 32 bit small archive\n"));
44 fprintf (fp, _(" [-X32] - ignores 64 bit objects\n"));
45 fprintf (fp, _(" [-X64] - ignores 32 bit objects\n"));
46 fprintf (fp, _(" [-X32_64] - accepts 32 and 64 bit objects\n"));
49 static bfd_boolean
50 ar_emul_aix_internal (bfd ** after_bfd,
51 char * file_name,
52 bfd_boolean verbose,
53 const char * target_name,
54 bfd_boolean is_append,
55 bfd_boolean flatten ATTRIBUTE_UNUSED)
57 bfd *temp;
58 bfd *try_bfd;
60 temp = *after_bfd;
62 /* Try 64 bit. */
63 try_bfd = bfd_openr (file_name, target_name);
65 /* Failed or the object is possibly 32 bit. */
66 if (NULL == try_bfd || ! bfd_check_format (try_bfd, bfd_object))
67 try_bfd = bfd_openr (file_name, "aixcoff-rs6000");
69 AR_EMUL_ELEMENT_CHECK (try_bfd, file_name);
71 if (bfd_xcoff_is_xcoff64 (try_bfd) && (! X64))
72 return FALSE;
74 if (bfd_xcoff_is_xcoff32 (try_bfd)
75 && bfd_check_format (try_bfd, bfd_object) && (! X32))
76 return FALSE;
78 if (is_append)
80 AR_EMUL_APPEND_PRINT_VERBOSE (verbose, file_name);
82 else
84 AR_EMUL_REPLACE_PRINT_VERBOSE (verbose, file_name);
87 *after_bfd = try_bfd;
88 (*after_bfd)->archive_next = temp;
90 return TRUE;
94 static bfd_boolean
95 ar_emul_aix_append (bfd **after_bfd, char *file_name, bfd_boolean verbose,
96 bfd_boolean flatten)
98 return ar_emul_aix_internal (after_bfd, file_name, verbose,
99 "aixcoff64-rs6000", TRUE, flatten);
102 static bfd_boolean
103 ar_emul_aix5_append (bfd **after_bfd, char *file_name, bfd_boolean verbose,
104 bfd_boolean flatten)
106 return ar_emul_aix_internal (after_bfd, file_name, verbose,
107 "aix5coff64-rs6000", TRUE, flatten);
110 static bfd_boolean
111 ar_emul_aix_replace (bfd **after_bfd, char *file_name, bfd_boolean verbose)
113 return ar_emul_aix_internal (after_bfd, file_name, verbose,
114 "aixcoff64-rs6000", FALSE, FALSE);
117 static bfd_boolean
118 ar_emul_aix5_replace (bfd **after_bfd, char *file_name, bfd_boolean verbose)
120 return ar_emul_aix_internal (after_bfd, file_name, verbose,
121 "aix5coff64-rs6000", FALSE, FALSE);
124 static bfd_boolean
125 ar_emul_aix_parse_arg (char *arg)
127 if (CONST_STRNEQ (arg, "-X32_64"))
129 big_archive = TRUE;
130 X32 = TRUE;
131 X64 = TRUE;
133 else if (CONST_STRNEQ (arg, "-X32"))
135 big_archive = TRUE;
136 X32 = TRUE;
137 X64 = FALSE;
139 else if (CONST_STRNEQ (arg, "-X64"))
141 big_archive = TRUE;
142 X32 = FALSE;
143 X64 = TRUE;
145 else if (CONST_STRNEQ (arg, "-g"))
147 big_archive = FALSE;
148 X32 = TRUE;
149 X64 = FALSE;
151 else
152 return FALSE;
154 return TRUE;
157 struct bin_emulation_xfer_struct bin_aix_emulation =
159 ar_emul_aix_usage,
160 ar_emul_aix_append,
161 ar_emul_aix_replace,
162 ar_emul_aix_parse_arg,
165 struct bin_emulation_xfer_struct bin_aix5_emulation =
167 ar_emul_aix_usage,
168 ar_emul_aix5_append,
169 ar_emul_aix5_replace,
170 ar_emul_aix_parse_arg,