tic54x/ibmc54xdsp target for ld.
[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 Free Software Foundation, Inc.
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 2 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21
22 /* For TI COFF */
23 /* Need to determine load and run pages for output sections */
24
25 #define TARGET_IS_${EMULATION_NAME}
26
27 #include "bfd.h"
28 #include "sysdep.h"
29 #include "bfdlink.h"
30
31 #include "ld.h"
32 #include "ldmain.h"
33 #include "ldemul.h"
34 #include "ldfile.h"
35 #include "ldmisc.h"
36
37 #include "getopt.h"
38
39 static int coff_version;
40
41 static void gld_${EMULATION_NAME}_before_parse PARAMS ((void));
42 static char *gld_${EMULATION_NAME}_get_script PARAMS ((int *));
43 static int gld_${EMULATION_NAME}_parse_args PARAMS ((int, char **));
44 static void gld_${EMULATION_NAME}_list_options PARAMS ((FILE *));
45
46 /* TI COFF extra command line options */
47 #define OPTION_COFF_FORMAT (300 + 1)
48
49 static struct option longopts[] =
50 {
51 /* TI COFF options */
52 {"format", required_argument, NULL, OPTION_COFF_FORMAT },
53 {NULL, no_argument, NULL, 0}
54 };
55
56 static void
57 gld_${EMULATION_NAME}_list_options (file)
58 FILE * file;
59 {
60 fprintf (file, _(" --format 0|1|2 Specify which COFF version to use"));
61 }
62
63 static int
64 gld_${EMULATION_NAME}_parse_args(argc, argv)
65 int argc;
66 char **argv;
67 {
68 int longind;
69 int optc;
70 int prevoptind = optind;
71 int prevopterr = opterr;
72 int wanterror;
73 static int lastoptind = -1;
74
75 if (lastoptind != optind)
76 opterr = 0;
77 wanterror = opterr;
78
79 lastoptind = optind;
80
81 optc = getopt_long_only (argc, argv, "-", longopts, &longind);
82 opterr = prevopterr;
83
84 switch (optc)
85 {
86 default:
87 if (wanterror)
88 xexit (1);
89 optind = prevoptind;
90 return 0;
91
92 case OPTION_COFF_FORMAT:
93 if ((*optarg == '0' || *optarg == '1' || *optarg == '2')
94 && optarg[1] == '\0')
95 {
96 extern void lang_add_output_format
97 PARAMS ((const char *, const char *, const char *, int));
98 static char buf[] = "coffX-${OUTPUT_FORMAT_TEMPLATE}";
99 coff_version = *optarg - '0';
100 buf[4] = *optarg;
101 lang_add_output_format (buf, NULL, NULL, 0);
102 }
103 else
104 {
105 einfo (_("%P%F: invalid COFF format version %s\n"), optarg);
106
107 }
108 break;
109 }
110 return 1;
111 }
112
113 static void
114 gld_${EMULATION_NAME}_before_parse()
115 {
116 #ifndef TARGET_ /* I.e., if not generic. */
117 ldfile_set_output_arch ("`echo ${ARCH}`");
118 #endif /* not TARGET_ */
119 }
120
121 static char *
122 gld_${EMULATION_NAME}_get_script (isfile)
123 int *isfile;
124 EOF
125 if test -n "$COMPILE_IN"
126 then
127 # Scripts compiled in.
128
129 # sed commands to quote an ld script as a C string.
130 sc='s/["\\]/\\&/g
131 s/$/\\n\\/
132 1s/^/"/
133 $s/$/n"/
134 '
135 cat >>e${EMULATION_NAME}.c <<EOF
136 {
137 *isfile = 0;
138 if (link_info.relocateable == true && config.build_constructors == true)
139 return `sed "$sc" ldscripts/${EMULATION_NAME}.xu`;
140 else if (link_info.relocateable == true)
141 return `sed "$sc" ldscripts/${EMULATION_NAME}.xr`;
142 else if (!config.text_read_only)
143 return `sed "$sc" ldscripts/${EMULATION_NAME}.xbn`;
144 else if (!config.magic_demand_paged)
145 return `sed "$sc" ldscripts/${EMULATION_NAME}.xn`;
146 else
147 return `sed "$sc" ldscripts/${EMULATION_NAME}.x`;
148 }
149 EOF
150
151 else
152 # Scripts read from the filesystem.
153
154 cat >>e${EMULATION_NAME}.c <<EOF
155 {
156 *isfile = 1;
157
158 if (link_info.relocateable == true && config.build_constructors == true)
159 return "ldscripts/${EMULATION_NAME}.xu";
160 else if (link_info.relocateable == true)
161 return "ldscripts/${EMULATION_NAME}.xr";
162 else if (!config.text_read_only)
163 return "ldscripts/${EMULATION_NAME}.xbn";
164 else if (!config.magic_demand_paged)
165 return "ldscripts/${EMULATION_NAME}.xn";
166 else
167 return "ldscripts/${EMULATION_NAME}.x";
168 }
169 EOF
170
171 fi
172
173 cat >>e${EMULATION_NAME}.c <<EOF
174 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
175 {
176 gld_${EMULATION_NAME}_before_parse,
177 syslib_default,
178 hll_default,
179 after_parse_default,
180 after_open_default,
181 after_allocation_default,
182 set_output_arch_default,
183 ldemul_default_target,
184 before_allocation_default,
185 gld_${EMULATION_NAME}_get_script,
186 "${EMULATION_NAME}",
187 "${OUTPUT_FORMAT}",
188 NULL, /* finish */
189 NULL, /* create output section statements */
190 NULL, /* open dynamic archive */
191 NULL, /* place orphan */
192 NULL, /* set_symbols */
193 gld_${EMULATION_NAME}_parse_args,
194 NULL, /* unrecognized_file */
195 gld_${EMULATION_NAME}_list_options,
196 NULL, /* recognized file */
197 NULL, /* find_potential_libraries */
198 };
199 EOF
This page took 0.041681 seconds and 5 git commands to generate.