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