Correct spelling of "relocatable".
[deliverable/binutils-gdb.git] / ld / emultempl / lnk960.em
CommitLineData
252b5132
RH
1# This shell script emits a C file. -*- C -*-
2# It does some substitutions.
3cat >e${EMULATION_NAME}.c <<EOF
4/* intel coff loader emulation specific stuff
3bcf5557 5 Copyright 1991, 1992, 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2003
b71e2778 6 Free Software Foundation, Inc.
252b5132
RH
7 Written by Steve Chamberlain steve@cygnus.com
8
9This file is part of GLD, the Gnu Linker.
10
11GLD is free software; you can redistribute it and/or modify
12it under the terms of the GNU General Public License as published by
13the Free Software Foundation; either version 2, or (at your option)
14any later version.
15
16GLD is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19GNU General Public License for more details.
20
21You should have received a copy of the GNU General Public License
22along with GLD; see the file COPYING. If not, write to
23the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
24
25#include "libiberty.h"
26#include "bfd.h"
27#include "sysdep.h"
28#include "bfdlink.h"
29
30/*#include "archures.h"*/
31#include "ld.h"
b71e2778 32#include "ldmain.h"
252b5132
RH
33#include "ldmisc.h"
34#include "ldexp.h"
35#include "ldlang.h"
36#include "ldfile.h"
b71e2778 37#include "ldemul.h"
252b5132
RH
38
39typedef struct lib_list {
40 char *name;
41 struct lib_list *next;
42} lib_list_type;
43
44static lib_list_type *hll_list;
45static lib_list_type **hll_list_tail = &hll_list;
46
47static lib_list_type *syslib_list;
48static lib_list_type **syslib_list_tail = &syslib_list;
49
48f6162b
AJ
50static void append PARAMS ((lib_list_type ***, char *));
51static void lnk960_hll PARAMS ((char *));
52static void lnk960_syslib PARAMS ((char *));
53static void lnk960_before_parse PARAMS ((void));
54static void add_on PARAMS ((lib_list_type *, lang_input_file_enum_type));
55static void lnk960_after_parse PARAMS ((void));
56static void lnk960_before_allocation PARAMS ((void));
57static void lnk960_after_allocation PARAMS ((void));
58static void lnk960_set_output_arch PARAMS ((void));
4e5bae56 59static char *lnk960_choose_target PARAMS ((int, char **));
48f6162b
AJ
60static char *lnk960_get_script PARAMS ((int *));
61
252b5132
RH
62
63static void
b34976b6 64append (list, name)
252b5132
RH
65 lib_list_type ***list;
66 char *name;
67{
b34976b6 68 lib_list_type *element = (lib_list_type *) xmalloc (sizeof (lib_list_type));
252b5132
RH
69
70 element->name = name;
b34976b6 71 element->next = (lib_list_type *) NULL;
252b5132
RH
72 **list = element;
73 *list = &element->next;
74
75}
76
b34976b6
AM
77static bfd_boolean had_hll = FALSE;
78static bfd_boolean had_hll_name = FALSE;
252b5132
RH
79
80static void
b34976b6 81lnk960_hll (name)
252b5132
RH
82 char *name;
83{
b34976b6
AM
84 had_hll = TRUE;
85 if (name != (char *) NULL)
86 {
87 had_hll_name = TRUE;
88 append (&hll_list_tail, name);
89 }
252b5132
RH
90}
91
92static void
b34976b6 93lnk960_syslib (name)
252b5132
RH
94 char *name;
95{
b34976b6 96 append (&syslib_list_tail, name);
252b5132
RH
97}
98
99
100#ifdef GNU960
101
102static void
b34976b6 103lnk960_before_parse ()
252b5132
RH
104{
105 static char *env_variables[] = { "G960LIB", "G960BASE", 0 };
106 char **p;
107 char *env ;
108
b34976b6
AM
109 for (p = env_variables; *p; p++)
110 {
111 env = (char *) getenv (*p);
112 if (env)
113 ldfile_add_library_path (concat (env, "/lib/libcoff", ""), FALSE);
252b5132 114 }
252b5132 115
b34976b6
AM
116 env = (char *) getenv ("I960BASE");
117 if (env)
118 ldfile_add_library_path(concat (env, "/lib", ""), FALSE);
252b5132
RH
119
120 ldfile_output_architecture = bfd_arch_i960;
121 ldfile_output_machine = bfd_mach_i960_core;
122}
123
124#else /* not GNU960 */
125
126static void
b34976b6 127lnk960_before_parse ()
252b5132 128{
b34976b6 129 char *name = getenv ("I960BASE");
252b5132 130
b34976b6
AM
131 if (name == (char *) NULL)
132 {
133 name = getenv("G960BASE");
134 if (name == (char *) NULL)
135 einfo ("%P%F I960BASE and G960BASE not set\n");
252b5132 136 }
252b5132
RH
137
138
b34976b6 139 ldfile_add_library_path (concat (name, "/lib", ""), FALSE);
252b5132
RH
140 ldfile_output_architecture = bfd_arch_i960;
141 ldfile_output_machine = bfd_mach_i960_core;
142}
143
144#endif /* GNU960 */
145
146
147static void
b34976b6 148add_on (list, search)
252b5132
RH
149 lib_list_type *list;
150 lang_input_file_enum_type search;
151{
b34976b6
AM
152 while (list)
153 {
154 lang_add_input_file (list->name, search, (char *) NULL);
155 list = list->next;
156 }
252b5132
RH
157}
158static void
b34976b6 159lnk960_after_parse ()
252b5132
RH
160{
161 /* If there has been no arch, default to -KB */
b34976b6
AM
162 if (ldfile_output_machine_name[0] == 0)
163 ldfile_add_arch ("KB");
252b5132
RH
164
165 /* if there has been no hll list then add our own */
166
b34976b6
AM
167 if (had_hll && !had_hll_name)
168 {
169 append (&hll_list_tail, "cg");
170 if (ldfile_output_machine == bfd_mach_i960_ka_sa
171 || ldfile_output_machine == bfd_mach_i960_ca)
172 append (&hll_list_tail, "fpg");
252b5132 173 }
252b5132 174
b34976b6
AM
175 add_on (hll_list, lang_input_file_is_l_enum);
176 add_on (syslib_list, lang_input_file_is_search_file_enum);
252b5132
RH
177}
178
179static void
b34976b6 180lnk960_before_allocation ()
252b5132
RH
181{
182}
183
184static void
b34976b6 185lnk960_after_allocation ()
252b5132 186{
1049f94e 187 if (!link_info.relocatable)
b34976b6
AM
188 {
189 lang_abs_symbol_at_end_of (".text", "_etext");
190 lang_abs_symbol_at_end_of (".data", "_edata");
191 lang_abs_symbol_at_beginning_of (".bss", "_bss_start");
192 lang_abs_symbol_at_end_of (".bss", "_end");
193 }
252b5132
RH
194}
195
196
197static struct
198 {
199 unsigned long number;
200 char *name;
201 }
202machine_table[] =
203{
204 { bfd_mach_i960_core ,"CORE" },
205 { bfd_mach_i960_kb_sb ,"KB" },
206 { bfd_mach_i960_kb_sb ,"SB" },
207 { bfd_mach_i960_mc ,"MC" },
208 { bfd_mach_i960_xa ,"XA" },
209 { bfd_mach_i960_ca ,"CA" },
210 { bfd_mach_i960_ka_sa ,"KA" },
211 { bfd_mach_i960_ka_sa ,"SA" },
212 { bfd_mach_i960_jx ,"JX" },
213 { bfd_mach_i960_hx ,"HX" },
214
215 { bfd_mach_i960_core ,"core" },
216 { bfd_mach_i960_kb_sb ,"kb" },
217 { bfd_mach_i960_kb_sb ,"sb" },
218 { bfd_mach_i960_mc ,"mc" },
219 { bfd_mach_i960_xa ,"xa" },
220 { bfd_mach_i960_ca ,"ca" },
221 { bfd_mach_i960_ka_sa ,"ka" },
222 { bfd_mach_i960_ka_sa ,"sa" },
223 { bfd_mach_i960_jx ,"jx" },
224 { bfd_mach_i960_hx ,"hx" },
225
226 { 0, (char *) NULL }
227};
228
229static void
b34976b6 230lnk960_set_output_arch ()
252b5132
RH
231{
232 /* Set the output architecture and machine if possible */
233 unsigned int i;
234 ldfile_output_machine = bfd_mach_i960_core;
b34976b6
AM
235 for (i= 0; machine_table[i].name != (char*) NULL; i++)
236 {
237 if (strcmp (ldfile_output_machine_name, machine_table[i].name) == 0)
238 {
239 ldfile_output_machine = machine_table[i].number;
240 break;
241 }
252b5132 242 }
b34976b6
AM
243 bfd_set_arch_mach (output_bfd, ldfile_output_architecture,
244 ldfile_output_machine);
252b5132
RH
245}
246
247static char *
4e5bae56
DJ
248lnk960_choose_target (argc, argv)
249 int argc ATTRIBUTE_UNUSED;
250 char **argv ATTRIBUTE_UNUSED;
252b5132
RH
251{
252#ifdef GNU960
253
b34976b6 254 return bfd_make_targ_name (BFD_COFF_FORMAT, 0);
252b5132
RH
255
256#else
257
b34976b6
AM
258 char *from_outside = getenv (TARGET_ENVIRON);
259 if (from_outside != (char *) NULL)
252b5132
RH
260 return from_outside;
261#ifdef LNK960_LITTLE
262 return "coff-Intel-little";
263#else
264 return "coff-Intel-big";
265#endif
266#endif
267
268}
269
270static char *
b34976b6 271lnk960_get_script (isfile)
252b5132
RH
272 int *isfile;
273EOF
274
275if test -n "$COMPILE_IN"
276then
277# Scripts compiled in.
278
279# sed commands to quote an ld script as a C string.
597e2591 280sc="-f stringify.sed"
252b5132
RH
281
282cat >>e${EMULATION_NAME}.c <<EOF
597e2591 283{
252b5132
RH
284 *isfile = 0;
285
1049f94e 286 if (link_info.relocatable && config.build_constructors)
597e2591 287 return
252b5132 288EOF
b34976b6 289sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
1049f94e 290echo ' ; else if (link_info.relocatable) return' >> e${EMULATION_NAME}.c
b34976b6
AM
291sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
292echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
293sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
294echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
295sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
296echo ' ; else return' >> e${EMULATION_NAME}.c
297sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
298echo '; }' >> e${EMULATION_NAME}.c
252b5132
RH
299
300else
301# Scripts read from the filesystem.
302
303cat >>e${EMULATION_NAME}.c <<EOF
304{
305 *isfile = 1;
306
1049f94e 307 if (link_info.relocatable && config.build_constructors)
252b5132 308 return "ldscripts/${EMULATION_NAME}.xu";
1049f94e 309 else if (link_info.relocatable)
252b5132
RH
310 return "ldscripts/${EMULATION_NAME}.xr";
311 else if (!config.text_read_only)
312 return "ldscripts/${EMULATION_NAME}.xbn";
313 else if (!config.magic_demand_paged)
314 return "ldscripts/${EMULATION_NAME}.xn";
315 else
316 return "ldscripts/${EMULATION_NAME}.x";
317}
318EOF
319
320fi
321
322cat >>e${EMULATION_NAME}.c <<EOF
323
324struct ld_emulation_xfer_struct ld_lnk960_emulation =
325{
326 lnk960_before_parse,
327 lnk960_syslib,
328 lnk960_hll,
329 lnk960_after_parse,
330 NULL, /* after_open */
331 lnk960_after_allocation,
332 lnk960_set_output_arch,
333 lnk960_choose_target,
334 lnk960_before_allocation,
335 lnk960_get_script,
336 "lnk960",
e1c47aa4
AM
337 "",
338 NULL, /* finish */
339 NULL, /* create output section statements */
340 NULL, /* open dynamic archive */
341 NULL, /* place orphan */
342 NULL, /* set symbols */
343 NULL, /* parse args */
3bcf5557
AM
344 NULL, /* add_options */
345 NULL, /* handle_option */
e1c47aa4
AM
346 NULL, /* unrecognized file */
347 NULL, /* list options */
40d109bf 348 NULL, /* recognized file */
fac1652d
AM
349 NULL, /* find_potential_libraries */
350 NULL /* new_vers_pattern */
252b5132
RH
351};
352EOF
This page took 0.191371 seconds and 4 git commands to generate.