bfd/
[deliverable/binutils-gdb.git] / ld / emultempl / ticoff.em
CommitLineData
74459f0e
TW
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 ;-)
4cat >>e${EMULATION_NAME}.c <<EOF
5/* This file is part of GLD, the Gnu Linker.
3db64b00
AM
6 Copyright 1999, 2000, 2002, 2003, 2004, 2007
7 Free Software Foundation, Inc.
74459f0e
TW
8
9This program is free software; you can redistribute it and/or modify
10it under the terms of the GNU General Public License as published by
11the Free Software Foundation; either version 2 of the License, or
12(at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
75be928b 21Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
74459f0e
TW
22
23/* For TI COFF */
5e2f1575
AM
24/* Need to determine load and run pages for output sections */
25
74459f0e
TW
26#define TARGET_IS_${EMULATION_NAME}
27
74459f0e 28#include "sysdep.h"
3db64b00 29#include "bfd.h"
74459f0e 30#include "bfdlink.h"
fcf65871 31#include "getopt.h"
74459f0e
TW
32
33#include "ld.h"
34#include "ldmain.h"
74459f0e 35#include "ldmisc.h"
b71e2778
AM
36#include "ldexp.h"
37#include "ldlang.h"
38#include "ldfile.h"
39#include "ldemul.h"
40
74459f0e
TW
41static int coff_version;
42
74459f0e
TW
43/* TI COFF extra command line options */
44#define OPTION_COFF_FORMAT (300 + 1)
45
3bcf5557 46static void
0c7a8e5a
AM
47gld${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)
74459f0e 51{
3bcf5557
AM
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}
74459f0e
TW
62
63static void
0c7a8e5a 64gld_${EMULATION_NAME}_list_options (FILE * file)
74459f0e 65{
c2411cd2 66 fprintf (file, _(" --format 0|1|2 Specify which COFF version to use\n"));
5e2f1575 67}
74459f0e 68
3bcf5557 69static bfd_boolean
0c7a8e5a 70gld${EMULATION_NAME}_handle_option (int optc)
74459f0e 71{
74459f0e
TW
72 switch (optc)
73 {
74 default:
3bcf5557 75 return FALSE;
74459f0e
TW
76
77 case OPTION_COFF_FORMAT:
78 if ((*optarg == '0' || *optarg == '1' || *optarg == '2')
79 && optarg[1] == '\0')
80 {
74459f0e
TW
81 static char buf[] = "coffX-${OUTPUT_FORMAT_TEMPLATE}";
82 coff_version = *optarg - '0';
83 buf[4] = *optarg;
5e2f1575 84 lang_add_output_format (buf, NULL, NULL, 0);
74459f0e
TW
85 }
86 else
87 {
88 einfo (_("%P%F: invalid COFF format version %s\n"), optarg);
74459f0e
TW
89 }
90 break;
91 }
3bcf5557 92 return FALSE;
74459f0e
TW
93}
94
95static void
0c7a8e5a 96gld_${EMULATION_NAME}_before_parse(void)
74459f0e
TW
97{
98#ifndef TARGET_ /* I.e., if not generic. */
5e2f1575 99 ldfile_set_output_arch ("`echo ${ARCH}`", bfd_arch_unknown);
74459f0e
TW
100#endif /* not TARGET_ */
101}
102
103static char *
0c7a8e5a 104gld_${EMULATION_NAME}_get_script (int *isfile)
74459f0e
TW
105EOF
106if test -n "$COMPILE_IN"
107then
108# Scripts compiled in.
109
110# sed commands to quote an ld script as a C string.
111sc='s/["\\]/\\&/g
112s/$/\\n\\/
1131s/^/"/
114$s/$/n"/
115'
116cat >>e${EMULATION_NAME}.c <<EOF
5e2f1575 117{
74459f0e 118 *isfile = 0;
1049f94e 119 if (link_info.relocatable && config.build_constructors)
74459f0e 120 return `sed "$sc" ldscripts/${EMULATION_NAME}.xu`;
1049f94e 121 else if (link_info.relocatable)
74459f0e
TW
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}
130EOF
131
132else
133# Scripts read from the filesystem.
134
135cat >>e${EMULATION_NAME}.c <<EOF
5e2f1575 136{
74459f0e
TW
137 *isfile = 1;
138
1049f94e 139 if (link_info.relocatable && config.build_constructors)
74459f0e 140 return "ldscripts/${EMULATION_NAME}.xu";
1049f94e 141 else if (link_info.relocatable)
74459f0e
TW
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}
150EOF
151
152fi
153
154cat >>e${EMULATION_NAME}.c <<EOF
5e2f1575 155struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
74459f0e
TW
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}",
1e035701 169 finish_default,
74459f0e
TW
170 NULL, /* create output section statements */
171 NULL, /* open dynamic archive */
172 NULL, /* place orphan */
173 NULL, /* set_symbols */
3bcf5557
AM
174 NULL, /* parse_args */
175 gld${EMULATION_NAME}_add_options,
176 gld${EMULATION_NAME}_handle_option,
74459f0e
TW
177 NULL, /* unrecognized_file */
178 gld_${EMULATION_NAME}_list_options,
179 NULL, /* recognized file */
fac1652d
AM
180 NULL, /* find_potential_libraries */
181 NULL /* new_vers_pattern */
74459f0e
TW
182};
183EOF
This page took 0.293278 seconds and 4 git commands to generate.