bfd/
[deliverable/binutils-gdb.git] / ld / emultempl / ticoff.em
1 # This shell script emits a C file. -*- C -*-
2 # It does some substitutions.
3 (echo;echo;echo;echo)>e${EMULATION_NAME}.c # there, now line numbers match ;-)
4 cat >>e${EMULATION_NAME}.c <<EOF
5 /* This file is part of GLD, the Gnu Linker.
6 Copyright 1999, 2000, 2002, 2003, 2004, 2007
7 Free Software Foundation, Inc.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
22
23 /* For TI COFF */
24 /* Need to determine load and run pages for output sections */
25
26 #define TARGET_IS_${EMULATION_NAME}
27
28 #include "sysdep.h"
29 #include "bfd.h"
30 #include "bfdlink.h"
31 #include "getopt.h"
32
33 #include "ld.h"
34 #include "ldmain.h"
35 #include "ldmisc.h"
36 #include "ldexp.h"
37 #include "ldlang.h"
38 #include "ldfile.h"
39 #include "ldemul.h"
40
41 static int coff_version;
42
43 /* TI COFF extra command line options */
44 #define OPTION_COFF_FORMAT (300 + 1)
45
46 static void
47 gld${EMULATION_NAME}_add_options
48 (int ns ATTRIBUTE_UNUSED, char **shortopts ATTRIBUTE_UNUSED, int nl,
49 struct option **longopts, int nrl ATTRIBUTE_UNUSED,
50 struct option **really_longopts ATTRIBUTE_UNUSED)
51 {
52 static const struct option xtra_long[] = {
53 /* TI COFF options */
54 {"format", required_argument, NULL, OPTION_COFF_FORMAT },
55 {NULL, no_argument, NULL, 0}
56 };
57
58 *longopts = (struct option *)
59 xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
60 memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
61 }
62
63 static void
64 gld_${EMULATION_NAME}_list_options (FILE * file)
65 {
66 fprintf (file, _(" --format 0|1|2 Specify which COFF version to use\n"));
67 }
68
69 static bfd_boolean
70 gld${EMULATION_NAME}_handle_option (int optc)
71 {
72 switch (optc)
73 {
74 default:
75 return FALSE;
76
77 case OPTION_COFF_FORMAT:
78 if ((*optarg == '0' || *optarg == '1' || *optarg == '2')
79 && optarg[1] == '\0')
80 {
81 static char buf[] = "coffX-${OUTPUT_FORMAT_TEMPLATE}";
82 coff_version = *optarg - '0';
83 buf[4] = *optarg;
84 lang_add_output_format (buf, NULL, NULL, 0);
85 }
86 else
87 {
88 einfo (_("%P%F: invalid COFF format version %s\n"), optarg);
89 }
90 break;
91 }
92 return FALSE;
93 }
94
95 static void
96 gld_${EMULATION_NAME}_before_parse(void)
97 {
98 #ifndef TARGET_ /* I.e., if not generic. */
99 ldfile_set_output_arch ("`echo ${ARCH}`", bfd_arch_unknown);
100 #endif /* not TARGET_ */
101 }
102
103 static char *
104 gld_${EMULATION_NAME}_get_script (int *isfile)
105 EOF
106 if test -n "$COMPILE_IN"
107 then
108 # Scripts compiled in.
109
110 # sed commands to quote an ld script as a C string.
111 sc='s/["\\]/\\&/g
112 s/$/\\n\\/
113 1s/^/"/
114 $s/$/n"/
115 '
116 cat >>e${EMULATION_NAME}.c <<EOF
117 {
118 *isfile = 0;
119 if (link_info.relocatable && config.build_constructors)
120 return `sed "$sc" ldscripts/${EMULATION_NAME}.xu`;
121 else if (link_info.relocatable)
122 return `sed "$sc" ldscripts/${EMULATION_NAME}.xr`;
123 else if (!config.text_read_only)
124 return `sed "$sc" ldscripts/${EMULATION_NAME}.xbn`;
125 else if (!config.magic_demand_paged)
126 return `sed "$sc" ldscripts/${EMULATION_NAME}.xn`;
127 else
128 return `sed "$sc" ldscripts/${EMULATION_NAME}.x`;
129 }
130 EOF
131
132 else
133 # Scripts read from the filesystem.
134
135 cat >>e${EMULATION_NAME}.c <<EOF
136 {
137 *isfile = 1;
138
139 if (link_info.relocatable && config.build_constructors)
140 return "ldscripts/${EMULATION_NAME}.xu";
141 else if (link_info.relocatable)
142 return "ldscripts/${EMULATION_NAME}.xr";
143 else if (!config.text_read_only)
144 return "ldscripts/${EMULATION_NAME}.xbn";
145 else if (!config.magic_demand_paged)
146 return "ldscripts/${EMULATION_NAME}.xn";
147 else
148 return "ldscripts/${EMULATION_NAME}.x";
149 }
150 EOF
151
152 fi
153
154 cat >>e${EMULATION_NAME}.c <<EOF
155 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
156 {
157 gld_${EMULATION_NAME}_before_parse,
158 syslib_default,
159 hll_default,
160 after_parse_default,
161 after_open_default,
162 after_allocation_default,
163 set_output_arch_default,
164 ldemul_default_target,
165 before_allocation_default,
166 gld_${EMULATION_NAME}_get_script,
167 "${EMULATION_NAME}",
168 "${OUTPUT_FORMAT}",
169 finish_default,
170 NULL, /* create output section statements */
171 NULL, /* open dynamic archive */
172 NULL, /* place orphan */
173 NULL, /* set_symbols */
174 NULL, /* parse_args */
175 gld${EMULATION_NAME}_add_options,
176 gld${EMULATION_NAME}_handle_option,
177 NULL, /* unrecognized_file */
178 gld_${EMULATION_NAME}_list_options,
179 NULL, /* recognized file */
180 NULL, /* find_potential_libraries */
181 NULL /* new_vers_pattern */
182 };
183 EOF
This page took 0.034467 seconds and 4 git commands to generate.