]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - ld/emultempl/gld960c.em
bfd/
[thirdparty/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
aef6203b 4/* Copyright 1991, 1993, 1994, 1996, 1999, 2000, 2001, 2002, 2003, 2004,
3db64b00 5 2005, 2007 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
75be928b
NC
21Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
2202110-1301, USA. */
252b5132 23
5e2f1575 24/*
252b5132
RH
25 * emulate the Intels port of gld
26 */
27
28
252b5132 29#include "sysdep.h"
3db64b00 30#include "bfd.h"
252b5132 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
0c7a8e5a 44static void gld960_before_parse (void)
252b5132
RH
45{
46 char *env ;
47 env = getenv("G960LIB");
48 if (env) {
b34976b6 49 ldfile_add_library_path(env, FALSE);
252b5132
RH
50 }
51 env = getenv("G960BASE");
52 if (env)
53 ldfile_add_library_path (concat (env, "/lib", (const char *) NULL),
b34976b6 54 FALSE);
252b5132
RH
55 ldfile_output_architecture = bfd_arch_i960;
56}
57
252b5132 58static void
0c7a8e5a 59gld960_set_output_arch (void)
252b5132
RH
60{
61 if (ldfile_output_machine_name != NULL
62 && *ldfile_output_machine_name != '\0')
63 {
64 char *s, *s1;
65
66 s = concat ("i960:", ldfile_output_machine_name, (char *) NULL);
67 for (s1 = s; *s1 != '\0'; s1++)
3882b010 68 *s1 = TOLOWER (*s1);
5e2f1575 69 ldfile_set_output_arch (s, bfd_arch_unknown);
252b5132
RH
70 free (s);
71 }
72
73 set_output_arch_default ();
74}
75
76static char *
0c7a8e5a 77gld960_choose_target (int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
252b5132 78{
252b5132
RH
79 char *from_outside = getenv(TARGET_ENVIRON);
80 output_filename = "b.out";
81
82 if (from_outside != (char *)NULL)
83 return from_outside;
84
85 return "coff-Intel-little";
252b5132
RH
86}
87
88static char *
0c7a8e5a 89gld960_get_script (int *isfile)
252b5132
RH
90EOF
91
92if test -n "$COMPILE_IN"
93then
94# Scripts compiled in.
95
96# sed commands to quote an ld script as a C string.
597e2591 97sc="-f stringify.sed"
252b5132
RH
98
99cat >>e${EMULATION_NAME}.c <<EOF
5e2f1575 100{
252b5132
RH
101 *isfile = 0;
102
1049f94e 103 if (link_info.relocatable && config.build_constructors)
597e2591 104 return
252b5132 105EOF
b34976b6 106sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
1049f94e 107echo ' ; else if (link_info.relocatable) return' >> e${EMULATION_NAME}.c
b34976b6
AM
108sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
109echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
110sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
111echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
112sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
113echo ' ; else return' >> e${EMULATION_NAME}.c
114sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
115echo '; }' >> e${EMULATION_NAME}.c
252b5132
RH
116
117else
118# Scripts read from the filesystem.
119
120cat >>e${EMULATION_NAME}.c <<EOF
5e2f1575 121{
252b5132
RH
122 *isfile = 1;
123
1049f94e 124 if (link_info.relocatable && config.build_constructors)
252b5132 125 return "ldscripts/${EMULATION_NAME}.xu";
1049f94e 126 else if (link_info.relocatable)
252b5132
RH
127 return "ldscripts/${EMULATION_NAME}.xr";
128 else if (!config.text_read_only)
129 return "ldscripts/${EMULATION_NAME}.xbn";
130 else if (!config.magic_demand_paged)
131 return "ldscripts/${EMULATION_NAME}.xn";
132 else
133 return "ldscripts/${EMULATION_NAME}.x";
134}
135EOF
136
137fi
138
139cat >>e${EMULATION_NAME}.c <<EOF
140
5e2f1575 141struct ld_emulation_xfer_struct ld_gld960coff_emulation =
252b5132
RH
142{
143 gld960_before_parse,
144 syslib_default,
145 hll_default,
146 after_parse_default,
147 after_open_default,
148 after_allocation_default,
149 gld960_set_output_arch,
150 gld960_choose_target,
151 before_allocation_default,
152 gld960_get_script,
153 "960coff",
e1c47aa4 154 "",
1e035701 155 finish_default,
e1c47aa4
AM
156 NULL, /* create output section statements */
157 NULL, /* open dynamic archive */
158 NULL, /* place orphan */
159 NULL, /* set symbols */
160 NULL, /* parse args */
3bcf5557
AM
161 NULL, /* add_options */
162 NULL, /* handle_option */
e1c47aa4
AM
163 NULL, /* unrecognized file */
164 NULL, /* list options */
40d109bf 165 NULL, /* recognized file */
fac1652d
AM
166 NULL, /* find_potential_libraries */
167 NULL /* new_vers_pattern */
252b5132
RH
168};
169EOF