Commit | Line | Data |
---|---|---|
252b5132 RH |
1 | # This shell script emits a C file. -*- C -*- |
2 | # It does some substitutions. | |
3 | cat >e${EMULATION_NAME}.c <<EOF | |
b71e2778 AM |
4 | /* Copyright (C) 1991, 93, 94, 95, 96, 99, 2000 |
5 | Free Software Foundation, Inc. | |
252b5132 RH |
6 | |
7 | This file is part of GLD, the Gnu Linker. | |
8 | ||
9 | GLD is free software; you can redistribute it and/or modify | |
10 | it under the terms of the GNU General Public License as published by | |
11 | the Free Software Foundation; either version 1, or (at your option) | |
12 | any later version. | |
13 | ||
14 | GLD is distributed in the hope that it will be useful, | |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
20 | along with GLD; see the file COPYING. If not, write to the Free | |
21 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA | |
22 | 02111-1307, USA. */ | |
23 | ||
24 | /* | |
25 | * emulate the Intels port of gld | |
26 | */ | |
27 | ||
28 | ||
29 | #include <ctype.h> | |
30 | #include "bfd.h" | |
31 | #include "sysdep.h" | |
32 | #include "libiberty.h" | |
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 | ||
46 | static void | |
47 | gld960_before_parse() | |
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), | |
59 | false); | |
60 | } | |
61 | } | |
62 | ldfile_output_architecture = bfd_arch_i960; | |
63 | } | |
64 | ||
65 | #else /* not GNU960 */ | |
66 | ||
67 | static void gld960_before_parse() | |
68 | { | |
69 | char *env ; | |
70 | env = getenv("G960LIB"); | |
71 | if (env) { | |
72 | ldfile_add_library_path(env, false); | |
73 | } | |
74 | env = getenv("G960BASE"); | |
75 | if (env) | |
76 | ldfile_add_library_path (concat (env, "/lib", (const char *) NULL), | |
77 | false); | |
78 | ldfile_output_architecture = bfd_arch_i960; | |
79 | } | |
80 | ||
81 | #endif /* GNU960 */ | |
82 | ||
83 | ||
84 | static void | |
85 | gld960_set_output_arch() | |
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++) | |
94 | if (isupper ((unsigned char) *s1)) | |
95 | *s1 = tolower ((unsigned char) *s1); | |
96 | ldfile_set_output_arch (s); | |
97 | free (s); | |
98 | } | |
99 | ||
100 | set_output_arch_default (); | |
101 | } | |
102 | ||
103 | static char * | |
104 | gld960_choose_target() | |
105 | { | |
106 | #ifdef GNU960 | |
107 | ||
108 | output_filename = "b.out"; | |
109 | return bfd_make_targ_name(BFD_BOUT_FORMAT, 0); | |
110 | ||
111 | #else | |
112 | ||
113 | char *from_outside = getenv(TARGET_ENVIRON); | |
114 | output_filename = "b.out"; | |
115 | ||
116 | if (from_outside != (char *)NULL) | |
117 | return from_outside; | |
118 | ||
119 | return "coff-Intel-little"; | |
120 | ||
121 | #endif | |
122 | } | |
123 | ||
124 | static char * | |
125 | gld960_get_script(isfile) | |
126 | int *isfile; | |
127 | EOF | |
128 | ||
129 | if test -n "$COMPILE_IN" | |
130 | then | |
131 | # Scripts compiled in. | |
132 | ||
133 | # sed commands to quote an ld script as a C string. | |
597e2591 | 134 | sc="-f stringify.sed" |
252b5132 RH |
135 | |
136 | cat >>e${EMULATION_NAME}.c <<EOF | |
137 | { | |
138 | *isfile = 0; | |
139 | ||
140 | if (link_info.relocateable == true && config.build_constructors == true) | |
597e2591 | 141 | return |
252b5132 | 142 | EOF |
597e2591 ILT |
143 | sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c |
144 | echo ' ; else if (link_info.relocateable == true) return' >> e${EMULATION_NAME}.c | |
145 | sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c | |
146 | echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c | |
147 | sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c | |
148 | echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c | |
149 | sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c | |
150 | echo ' ; else return' >> e${EMULATION_NAME}.c | |
151 | sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c | |
152 | echo '; }' >> e${EMULATION_NAME}.c | |
252b5132 RH |
153 | |
154 | else | |
155 | # Scripts read from the filesystem. | |
156 | ||
157 | cat >>e${EMULATION_NAME}.c <<EOF | |
158 | { | |
159 | *isfile = 1; | |
160 | ||
161 | if (link_info.relocateable == true && config.build_constructors == true) | |
162 | return "ldscripts/${EMULATION_NAME}.xu"; | |
163 | else if (link_info.relocateable == true) | |
164 | return "ldscripts/${EMULATION_NAME}.xr"; | |
165 | else if (!config.text_read_only) | |
166 | return "ldscripts/${EMULATION_NAME}.xbn"; | |
167 | else if (!config.magic_demand_paged) | |
168 | return "ldscripts/${EMULATION_NAME}.xn"; | |
169 | else | |
170 | return "ldscripts/${EMULATION_NAME}.x"; | |
171 | } | |
172 | EOF | |
173 | ||
174 | fi | |
175 | ||
176 | cat >>e${EMULATION_NAME}.c <<EOF | |
177 | ||
178 | struct ld_emulation_xfer_struct ld_gld960coff_emulation = | |
179 | { | |
180 | gld960_before_parse, | |
181 | syslib_default, | |
182 | hll_default, | |
183 | after_parse_default, | |
184 | after_open_default, | |
185 | after_allocation_default, | |
186 | gld960_set_output_arch, | |
187 | gld960_choose_target, | |
188 | before_allocation_default, | |
189 | gld960_get_script, | |
190 | "960coff", | |
e1c47aa4 AM |
191 | "", |
192 | NULL, /* finish */ | |
193 | NULL, /* create output section statements */ | |
194 | NULL, /* open dynamic archive */ | |
195 | NULL, /* place orphan */ | |
196 | NULL, /* set symbols */ | |
197 | NULL, /* parse args */ | |
198 | NULL, /* unrecognized file */ | |
199 | NULL, /* list options */ | |
40d109bf AM |
200 | NULL, /* recognized file */ |
201 | NULL /* find_potential_libraries */ | |
252b5132 RH |
202 | }; |
203 | EOF |