]>
Commit | Line | Data |
---|---|---|
74459f0e TW |
1 | # This shell script emits a C file. -*- C -*- |
2 | # It does some substitutions. | |
3 | (echo;echo;echo;echo)>e${EMULATION_NAME}.c # there, now line numbers match ;-) | |
4 | cat >>e${EMULATION_NAME}.c <<EOF | |
5 | /* This file is part of GLD, the Gnu Linker. | |
3bcf5557 | 6 | Copyright 1999, 2000, 2002, 2003 Free Software Foundation, Inc. |
74459f0e TW |
7 | |
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with this program; if not, write to the Free Software | |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
21 | ||
22 | /* For TI COFF */ | |
23 | /* Need to determine load and run pages for output sections */ | |
24 | ||
25 | #define TARGET_IS_${EMULATION_NAME} | |
26 | ||
27 | #include "bfd.h" | |
28 | #include "sysdep.h" | |
29 | #include "bfdlink.h" | |
30 | ||
31 | #include "ld.h" | |
32 | #include "ldmain.h" | |
74459f0e TW |
33 | #include "ldmisc.h" |
34 | ||
b71e2778 AM |
35 | #include "ldexp.h" |
36 | #include "ldlang.h" | |
37 | #include "ldfile.h" | |
38 | #include "ldemul.h" | |
39 | ||
74459f0e TW |
40 | #include "getopt.h" |
41 | ||
42 | static int coff_version; | |
43 | ||
44 | static void gld_${EMULATION_NAME}_before_parse PARAMS ((void)); | |
45 | static char *gld_${EMULATION_NAME}_get_script PARAMS ((int *)); | |
3bcf5557 AM |
46 | static void gld${EMULATION_NAME}_add_options |
47 | PARAMS ((int, char **, int, struct option **, int, struct option **)); | |
48 | static bfd_boolean gld${EMULATION_NAME}_handle_option PARAMS ((int)); | |
74459f0e TW |
49 | static void gld_${EMULATION_NAME}_list_options PARAMS ((FILE *)); |
50 | ||
51 | /* TI COFF extra command line options */ | |
52 | #define OPTION_COFF_FORMAT (300 + 1) | |
53 | ||
3bcf5557 AM |
54 | static void |
55 | gld${EMULATION_NAME}_add_options (ns, shortopts, nl, longopts, nrl, really_longopts) | |
56 | int ns ATTRIBUTE_UNUSED; | |
57 | char **shortopts ATTRIBUTE_UNUSED; | |
58 | int nl; | |
59 | struct option **longopts; | |
60 | int nrl ATTRIBUTE_UNUSED; | |
61 | struct option **really_longopts ATTRIBUTE_UNUSED; | |
74459f0e | 62 | { |
3bcf5557 AM |
63 | static const struct option xtra_long[] = { |
64 | /* TI COFF options */ | |
65 | {"format", required_argument, NULL, OPTION_COFF_FORMAT }, | |
66 | {NULL, no_argument, NULL, 0} | |
67 | }; | |
68 | ||
69 | *longopts = (struct option *) | |
70 | xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long)); | |
71 | memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long)); | |
72 | } | |
74459f0e TW |
73 | |
74 | static void | |
75 | gld_${EMULATION_NAME}_list_options (file) | |
76 | FILE * file; | |
77 | { | |
78 | fprintf (file, _(" --format 0|1|2 Specify which COFF version to use")); | |
79 | } | |
80 | ||
3bcf5557 AM |
81 | static bfd_boolean |
82 | gld${EMULATION_NAME}_handle_option (optc) | |
83 | int optc; | |
74459f0e | 84 | { |
74459f0e TW |
85 | switch (optc) |
86 | { | |
87 | default: | |
3bcf5557 | 88 | return FALSE; |
74459f0e TW |
89 | |
90 | case OPTION_COFF_FORMAT: | |
91 | if ((*optarg == '0' || *optarg == '1' || *optarg == '2') | |
92 | && optarg[1] == '\0') | |
93 | { | |
94 | extern void lang_add_output_format | |
95 | PARAMS ((const char *, const char *, const char *, int)); | |
96 | static char buf[] = "coffX-${OUTPUT_FORMAT_TEMPLATE}"; | |
97 | coff_version = *optarg - '0'; | |
98 | buf[4] = *optarg; | |
99 | lang_add_output_format (buf, NULL, NULL, 0); | |
100 | } | |
101 | else | |
102 | { | |
103 | einfo (_("%P%F: invalid COFF format version %s\n"), optarg); | |
74459f0e TW |
104 | } |
105 | break; | |
106 | } | |
3bcf5557 | 107 | return FALSE; |
74459f0e TW |
108 | } |
109 | ||
110 | static void | |
111 | gld_${EMULATION_NAME}_before_parse() | |
112 | { | |
113 | #ifndef TARGET_ /* I.e., if not generic. */ | |
114 | ldfile_set_output_arch ("`echo ${ARCH}`"); | |
115 | #endif /* not TARGET_ */ | |
116 | } | |
117 | ||
118 | static char * | |
119 | gld_${EMULATION_NAME}_get_script (isfile) | |
120 | int *isfile; | |
121 | EOF | |
122 | if test -n "$COMPILE_IN" | |
123 | then | |
124 | # Scripts compiled in. | |
125 | ||
126 | # sed commands to quote an ld script as a C string. | |
127 | sc='s/["\\]/\\&/g | |
128 | s/$/\\n\\/ | |
129 | 1s/^/"/ | |
130 | $s/$/n"/ | |
131 | ' | |
132 | cat >>e${EMULATION_NAME}.c <<EOF | |
133 | { | |
134 | *isfile = 0; | |
b34976b6 | 135 | if (link_info.relocateable && config.build_constructors) |
74459f0e | 136 | return `sed "$sc" ldscripts/${EMULATION_NAME}.xu`; |
b34976b6 | 137 | else if (link_info.relocateable) |
74459f0e TW |
138 | return `sed "$sc" ldscripts/${EMULATION_NAME}.xr`; |
139 | else if (!config.text_read_only) | |
140 | return `sed "$sc" ldscripts/${EMULATION_NAME}.xbn`; | |
141 | else if (!config.magic_demand_paged) | |
142 | return `sed "$sc" ldscripts/${EMULATION_NAME}.xn`; | |
143 | else | |
144 | return `sed "$sc" ldscripts/${EMULATION_NAME}.x`; | |
145 | } | |
146 | EOF | |
147 | ||
148 | else | |
149 | # Scripts read from the filesystem. | |
150 | ||
151 | cat >>e${EMULATION_NAME}.c <<EOF | |
152 | { | |
153 | *isfile = 1; | |
154 | ||
b34976b6 | 155 | if (link_info.relocateable && config.build_constructors) |
74459f0e | 156 | return "ldscripts/${EMULATION_NAME}.xu"; |
b34976b6 | 157 | else if (link_info.relocateable) |
74459f0e TW |
158 | return "ldscripts/${EMULATION_NAME}.xr"; |
159 | else if (!config.text_read_only) | |
160 | return "ldscripts/${EMULATION_NAME}.xbn"; | |
161 | else if (!config.magic_demand_paged) | |
162 | return "ldscripts/${EMULATION_NAME}.xn"; | |
163 | else | |
164 | return "ldscripts/${EMULATION_NAME}.x"; | |
165 | } | |
166 | EOF | |
167 | ||
168 | fi | |
169 | ||
170 | cat >>e${EMULATION_NAME}.c <<EOF | |
171 | struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = | |
172 | { | |
173 | gld_${EMULATION_NAME}_before_parse, | |
174 | syslib_default, | |
175 | hll_default, | |
176 | after_parse_default, | |
177 | after_open_default, | |
178 | after_allocation_default, | |
179 | set_output_arch_default, | |
180 | ldemul_default_target, | |
181 | before_allocation_default, | |
182 | gld_${EMULATION_NAME}_get_script, | |
183 | "${EMULATION_NAME}", | |
184 | "${OUTPUT_FORMAT}", | |
185 | NULL, /* finish */ | |
186 | NULL, /* create output section statements */ | |
187 | NULL, /* open dynamic archive */ | |
188 | NULL, /* place orphan */ | |
189 | NULL, /* set_symbols */ | |
3bcf5557 AM |
190 | NULL, /* parse_args */ |
191 | gld${EMULATION_NAME}_add_options, | |
192 | gld${EMULATION_NAME}_handle_option, | |
74459f0e TW |
193 | NULL, /* unrecognized_file */ |
194 | gld_${EMULATION_NAME}_list_options, | |
195 | NULL, /* recognized file */ | |
fac1652d AM |
196 | NULL, /* find_potential_libraries */ |
197 | NULL /* new_vers_pattern */ | |
74459f0e TW |
198 | }; |
199 | EOF |