* ldfile.c (ldfile_set_output_arch): Add defarch param.
[deliverable/binutils-gdb.git] / ld / emultempl / gld960c.em
CommitLineData
252b5132
RH
1# This shell script emits a C file. -*- C -*-
2# It does some substitutions.
3cat >e${EMULATION_NAME}.c <<EOF
5e2f1575 4/* Copyright 1991, 1993, 1994, 1996, 1999, 2000, 2001, 2002, 2003, 2004
b71e2778 5 Free Software Foundation, Inc.
252b5132
RH
6
7This file is part of GLD, the Gnu Linker.
8
9GLD 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 1, or (at your option)
12any later version.
13
14GLD 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 GLD; see the file COPYING. If not, write to the Free
21Software Foundation, 59 Temple Place - Suite 330, Boston, MA
2202111-1307, USA. */
23
5e2f1575 24/*
252b5132
RH
25 * emulate the Intels port of gld
26 */
27
28
252b5132
RH
29#include "bfd.h"
30#include "sysdep.h"
31#include "libiberty.h"
3882b010 32#include "safe-ctype.h"
252b5132
RH
33#include "bfdlink.h"
34
35#include "ld.h"
252b5132
RH
36#include "ldmisc.h"
37#include "ldmain.h"
38
b71e2778
AM
39#include "ldexp.h"
40#include "ldlang.h"
41#include "ldfile.h"
42#include "ldemul.h"
43
252b5132
RH
44#ifdef GNU960
45
46static void
0c7a8e5a 47gld960_before_parse (void)
252b5132
RH
48{
49 static char *env_variables[] = { "G960LIB", "G960BASE", 0 };
50 char **p;
51 char *env ;
52
53 for ( p = env_variables; *p; p++ ){
54 env = (char *) getenv(*p);
55 if (env) {
56 ldfile_add_library_path (concat (env,
57 "/lib/libcoff",
58 (const char *) NULL),
b34976b6 59 FALSE);
252b5132
RH
60 }
61 }
62 ldfile_output_architecture = bfd_arch_i960;
63}
64
65#else /* not GNU960 */
66
0c7a8e5a 67static void gld960_before_parse (void)
252b5132
RH
68{
69 char *env ;
70 env = getenv("G960LIB");
71 if (env) {
b34976b6 72 ldfile_add_library_path(env, FALSE);
252b5132
RH
73 }
74 env = getenv("G960BASE");
75 if (env)
76 ldfile_add_library_path (concat (env, "/lib", (const char *) NULL),
b34976b6 77 FALSE);
252b5132
RH
78 ldfile_output_architecture = bfd_arch_i960;
79}
80
81#endif /* GNU960 */
82
83
84static void
0c7a8e5a 85gld960_set_output_arch (void)
252b5132
RH
86{
87 if (ldfile_output_machine_name != NULL
88 && *ldfile_output_machine_name != '\0')
89 {
90 char *s, *s1;
91
92 s = concat ("i960:", ldfile_output_machine_name, (char *) NULL);
93 for (s1 = s; *s1 != '\0'; s1++)
3882b010 94 *s1 = TOLOWER (*s1);
5e2f1575 95 ldfile_set_output_arch (s, bfd_arch_unknown);
252b5132
RH
96 free (s);
97 }
98
99 set_output_arch_default ();
100}
101
102static char *
0c7a8e5a 103gld960_choose_target (int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
252b5132
RH
104{
105#ifdef GNU960
106
107 output_filename = "b.out";
108 return bfd_make_targ_name(BFD_BOUT_FORMAT, 0);
109
110#else
111
112 char *from_outside = getenv(TARGET_ENVIRON);
113 output_filename = "b.out";
114
115 if (from_outside != (char *)NULL)
116 return from_outside;
117
118 return "coff-Intel-little";
119
120#endif
121}
122
123static char *
0c7a8e5a 124gld960_get_script (int *isfile)
252b5132
RH
125EOF
126
127if test -n "$COMPILE_IN"
128then
129# Scripts compiled in.
130
131# sed commands to quote an ld script as a C string.
597e2591 132sc="-f stringify.sed"
252b5132
RH
133
134cat >>e${EMULATION_NAME}.c <<EOF
5e2f1575 135{
252b5132
RH
136 *isfile = 0;
137
1049f94e 138 if (link_info.relocatable && config.build_constructors)
597e2591 139 return
252b5132 140EOF
b34976b6 141sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
1049f94e 142echo ' ; else if (link_info.relocatable) return' >> e${EMULATION_NAME}.c
b34976b6
AM
143sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
144echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
145sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
146echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
147sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
148echo ' ; else return' >> e${EMULATION_NAME}.c
149sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
150echo '; }' >> e${EMULATION_NAME}.c
252b5132
RH
151
152else
153# Scripts read from the filesystem.
154
155cat >>e${EMULATION_NAME}.c <<EOF
5e2f1575 156{
252b5132
RH
157 *isfile = 1;
158
1049f94e 159 if (link_info.relocatable && config.build_constructors)
252b5132 160 return "ldscripts/${EMULATION_NAME}.xu";
1049f94e 161 else if (link_info.relocatable)
252b5132
RH
162 return "ldscripts/${EMULATION_NAME}.xr";
163 else if (!config.text_read_only)
164 return "ldscripts/${EMULATION_NAME}.xbn";
165 else if (!config.magic_demand_paged)
166 return "ldscripts/${EMULATION_NAME}.xn";
167 else
168 return "ldscripts/${EMULATION_NAME}.x";
169}
170EOF
171
172fi
173
174cat >>e${EMULATION_NAME}.c <<EOF
175
5e2f1575 176struct ld_emulation_xfer_struct ld_gld960coff_emulation =
252b5132
RH
177{
178 gld960_before_parse,
179 syslib_default,
180 hll_default,
181 after_parse_default,
182 after_open_default,
183 after_allocation_default,
184 gld960_set_output_arch,
185 gld960_choose_target,
186 before_allocation_default,
187 gld960_get_script,
188 "960coff",
e1c47aa4
AM
189 "",
190 NULL, /* finish */
191 NULL, /* create output section statements */
192 NULL, /* open dynamic archive */
193 NULL, /* place orphan */
194 NULL, /* set symbols */
195 NULL, /* parse args */
3bcf5557
AM
196 NULL, /* add_options */
197 NULL, /* handle_option */
e1c47aa4
AM
198 NULL, /* unrecognized file */
199 NULL, /* list options */
40d109bf 200 NULL, /* recognized file */
fac1652d
AM
201 NULL, /* find_potential_libraries */
202 NULL /* new_vers_pattern */
252b5132
RH
203};
204EOF
This page took 0.204476 seconds and 4 git commands to generate.