This commit was manufactured by cvs2svn to create branch 'binutils-
[external/binutils.git] / binutils / emul_aix.c
1 /* Binutils emulation layer.
2    Copyright 2002, 2003, 2005, 2006, 2007, 2008, 2010
3    Free Software Foundation, Inc.
4    Written by Tom Rix, Red Hat Inc.
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
10    the Free Software Foundation; either version 3 of the License, or
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
20    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21    MA 02110-1301, USA.  */
22
23 #include "binemul.h"
24 #include "bfdlink.h"
25 #include "coff/internal.h"
26 #include "coff/xcoff.h"
27 #include "libcoff.h"
28 #include "libxcoff.h"
29
30 /* Default to <bigaf>.  */
31 /* FIXME: write only variable.  */
32 static bfd_boolean big_archive = TRUE;
33
34 /* Whether to include 32 bit objects.  */
35 static bfd_boolean X32 = TRUE;
36
37 /* Whether to include 64 bit objects.  */
38 static bfd_boolean X64 = FALSE;
39
40 static void
41 ar_emul_aix_usage (FILE *fp)
42 {
43   AR_EMUL_USAGE_PRINT_OPTION_HEADER (fp);
44   /* xgettext:c-format */
45   fprintf (fp, _("  [-g]         - 32 bit small archive\n"));
46   fprintf (fp, _("  [-X32]       - ignores 64 bit objects\n"));
47   fprintf (fp, _("  [-X64]       - ignores 32 bit objects\n"));
48   fprintf (fp, _("  [-X32_64]    - accepts 32 and 64 bit objects\n"));
49 }
50
51 static bfd_boolean
52 check_aix (bfd *try_bfd)
53 {
54   extern const bfd_target rs6000coff_vec;
55   extern const bfd_target rs6000coff64_vec;
56   extern const bfd_target aix5coff64_vec;
57
58   if (bfd_check_format (try_bfd, bfd_object))
59     {
60       if (!X32 && try_bfd->xvec == &rs6000coff_vec)
61         return FALSE;
62
63       if (!X64 && (try_bfd->xvec == &rs6000coff64_vec
64                    || try_bfd->xvec == &aix5coff64_vec))
65         return FALSE;
66     }
67   return TRUE;
68 }
69
70 static bfd_boolean
71 ar_emul_aix_append (bfd **after_bfd, char *file_name, const char *target,
72                     bfd_boolean verbose, bfd_boolean flatten)
73 {
74   bfd *new_bfd;
75
76   new_bfd = bfd_openr (file_name, target);
77   AR_EMUL_ELEMENT_CHECK (new_bfd, file_name);
78
79   return do_ar_emul_append (after_bfd, new_bfd, verbose, flatten, check_aix);
80 }
81
82 static bfd_boolean
83 ar_emul_aix_replace (bfd **after_bfd, char *file_name, const char *target,
84                      bfd_boolean verbose)
85 {
86   bfd *new_bfd;
87
88   new_bfd = bfd_openr (file_name, target);
89   AR_EMUL_ELEMENT_CHECK (new_bfd, file_name);
90
91   if (!check_aix (new_bfd))
92     return FALSE;
93
94   AR_EMUL_REPLACE_PRINT_VERBOSE (verbose, file_name);
95
96   new_bfd->archive_next = *after_bfd;
97   *after_bfd = new_bfd;
98
99   return TRUE;
100 }
101
102 static bfd_boolean
103 ar_emul_aix_parse_arg (char *arg)
104 {
105   if (CONST_STRNEQ (arg, "-X32_64"))
106     {
107       big_archive = TRUE;
108       X32 = TRUE;
109       X64 = TRUE;
110     }
111   else if (CONST_STRNEQ (arg, "-X32"))
112     {
113       big_archive = TRUE;
114       X32 = TRUE;
115       X64 = FALSE;
116     }
117   else if (CONST_STRNEQ (arg, "-X64"))
118     {
119       big_archive = TRUE;
120       X32 = FALSE;
121       X64 = TRUE;
122     }
123   else if (CONST_STRNEQ (arg, "-g"))
124     {
125       big_archive = FALSE;
126       X32 = TRUE;
127       X64 = FALSE;
128     }
129   else
130     return FALSE;
131
132   return TRUE;
133 }
134
135 struct bin_emulation_xfer_struct bin_aix_emulation =
136 {
137   ar_emul_aix_usage,
138   ar_emul_aix_append,
139   ar_emul_aix_replace,
140   ar_emul_aix_parse_arg,
141 };