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. | |
5e2f1575 | 6 | Copyright 1999, 2000, 2002, 2003, 2004 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 */ | |
5e2f1575 AM |
23 | /* Need to determine load and run pages for output sections */ |
24 | ||
74459f0e TW |
25 | #define TARGET_IS_${EMULATION_NAME} |
26 | ||
27 | #include "bfd.h" | |
28 | #include "sysdep.h" | |
29 | #include "bfdlink.h" | |
fcf65871 | 30 | #include "getopt.h" |
74459f0e TW |
31 | |
32 | #include "ld.h" | |
33 | #include "ldmain.h" | |
74459f0e | 34 | #include "ldmisc.h" |
b71e2778 AM |
35 | #include "ldexp.h" |
36 | #include "ldlang.h" | |
37 | #include "ldfile.h" | |
38 | #include "ldemul.h" | |
39 | ||
74459f0e TW |
40 | static int coff_version; |
41 | ||
74459f0e TW |
42 | /* TI COFF extra command line options */ |
43 | #define OPTION_COFF_FORMAT (300 + 1) | |
44 | ||
3bcf5557 | 45 | static void |
0c7a8e5a AM |
46 | gld${EMULATION_NAME}_add_options |
47 | (int ns ATTRIBUTE_UNUSED, char **shortopts ATTRIBUTE_UNUSED, int nl, | |
48 | struct option **longopts, int nrl ATTRIBUTE_UNUSED, | |
49 | struct option **really_longopts ATTRIBUTE_UNUSED) | |
74459f0e | 50 | { |
3bcf5557 AM |
51 | static const struct option xtra_long[] = { |
52 | /* TI COFF options */ | |
53 | {"format", required_argument, NULL, OPTION_COFF_FORMAT }, | |
54 | {NULL, no_argument, NULL, 0} | |
55 | }; | |
56 | ||
57 | *longopts = (struct option *) | |
58 | xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long)); | |
59 | memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long)); | |
60 | } | |
74459f0e TW |
61 | |
62 | static void | |
0c7a8e5a | 63 | gld_${EMULATION_NAME}_list_options (FILE * file) |
74459f0e | 64 | { |
c2411cd2 | 65 | fprintf (file, _(" --format 0|1|2 Specify which COFF version to use\n")); |
5e2f1575 | 66 | } |
74459f0e | 67 | |
3bcf5557 | 68 | static bfd_boolean |
0c7a8e5a | 69 | gld${EMULATION_NAME}_handle_option (int optc) |
74459f0e | 70 | { |
74459f0e TW |
71 | switch (optc) |
72 | { | |
73 | default: | |
3bcf5557 | 74 | return FALSE; |
74459f0e TW |
75 | |
76 | case OPTION_COFF_FORMAT: | |
77 | if ((*optarg == '0' || *optarg == '1' || *optarg == '2') | |
78 | && optarg[1] == '\0') | |
79 | { | |
74459f0e TW |
80 | static char buf[] = "coffX-${OUTPUT_FORMAT_TEMPLATE}"; |
81 | coff_version = *optarg - '0'; | |
82 | buf[4] = *optarg; | |
5e2f1575 | 83 | lang_add_output_format (buf, NULL, NULL, 0); |
74459f0e TW |
84 | } |
85 | else | |
86 | { | |
87 | einfo (_("%P%F: invalid COFF format version %s\n"), optarg); | |
74459f0e TW |
88 | } |
89 | break; | |
90 | } | |
3bcf5557 | 91 | return FALSE; |
74459f0e TW |
92 | } |
93 | ||
94 | static void | |
0c7a8e5a | 95 | gld_${EMULATION_NAME}_before_parse(void) |
74459f0e TW |
96 | { |
97 | #ifndef TARGET_ /* I.e., if not generic. */ | |
5e2f1575 | 98 | ldfile_set_output_arch ("`echo ${ARCH}`", bfd_arch_unknown); |
74459f0e TW |
99 | #endif /* not TARGET_ */ |
100 | } | |
101 | ||
102 | static char * | |
0c7a8e5a | 103 | gld_${EMULATION_NAME}_get_script (int *isfile) |
74459f0e TW |
104 | EOF |
105 | if test -n "$COMPILE_IN" | |
106 | then | |
107 | # Scripts compiled in. | |
108 | ||
109 | # sed commands to quote an ld script as a C string. | |
110 | sc='s/["\\]/\\&/g | |
111 | s/$/\\n\\/ | |
112 | 1s/^/"/ | |
113 | $s/$/n"/ | |
114 | ' | |
115 | cat >>e${EMULATION_NAME}.c <<EOF | |
5e2f1575 | 116 | { |
74459f0e | 117 | *isfile = 0; |
1049f94e | 118 | if (link_info.relocatable && config.build_constructors) |
74459f0e | 119 | return `sed "$sc" ldscripts/${EMULATION_NAME}.xu`; |
1049f94e | 120 | else if (link_info.relocatable) |
74459f0e TW |
121 | return `sed "$sc" ldscripts/${EMULATION_NAME}.xr`; |
122 | else if (!config.text_read_only) | |
123 | return `sed "$sc" ldscripts/${EMULATION_NAME}.xbn`; | |
124 | else if (!config.magic_demand_paged) | |
125 | return `sed "$sc" ldscripts/${EMULATION_NAME}.xn`; | |
126 | else | |
127 | return `sed "$sc" ldscripts/${EMULATION_NAME}.x`; | |
128 | } | |
129 | EOF | |
130 | ||
131 | else | |
132 | # Scripts read from the filesystem. | |
133 | ||
134 | cat >>e${EMULATION_NAME}.c <<EOF | |
5e2f1575 | 135 | { |
74459f0e TW |
136 | *isfile = 1; |
137 | ||
1049f94e | 138 | if (link_info.relocatable && config.build_constructors) |
74459f0e | 139 | return "ldscripts/${EMULATION_NAME}.xu"; |
1049f94e | 140 | else if (link_info.relocatable) |
74459f0e TW |
141 | return "ldscripts/${EMULATION_NAME}.xr"; |
142 | else if (!config.text_read_only) | |
143 | return "ldscripts/${EMULATION_NAME}.xbn"; | |
144 | else if (!config.magic_demand_paged) | |
145 | return "ldscripts/${EMULATION_NAME}.xn"; | |
146 | else | |
147 | return "ldscripts/${EMULATION_NAME}.x"; | |
148 | } | |
149 | EOF | |
150 | ||
151 | fi | |
152 | ||
153 | cat >>e${EMULATION_NAME}.c <<EOF | |
5e2f1575 | 154 | struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = |
74459f0e TW |
155 | { |
156 | gld_${EMULATION_NAME}_before_parse, | |
157 | syslib_default, | |
158 | hll_default, | |
159 | after_parse_default, | |
160 | after_open_default, | |
161 | after_allocation_default, | |
162 | set_output_arch_default, | |
163 | ldemul_default_target, | |
164 | before_allocation_default, | |
165 | gld_${EMULATION_NAME}_get_script, | |
166 | "${EMULATION_NAME}", | |
167 | "${OUTPUT_FORMAT}", | |
168 | NULL, /* finish */ | |
169 | NULL, /* create output section statements */ | |
170 | NULL, /* open dynamic archive */ | |
171 | NULL, /* place orphan */ | |
172 | NULL, /* set_symbols */ | |
3bcf5557 AM |
173 | NULL, /* parse_args */ |
174 | gld${EMULATION_NAME}_add_options, | |
175 | gld${EMULATION_NAME}_handle_option, | |
74459f0e TW |
176 | NULL, /* unrecognized_file */ |
177 | gld_${EMULATION_NAME}_list_options, | |
178 | NULL, /* recognized file */ | |
fac1652d AM |
179 | NULL, /* find_potential_libraries */ |
180 | NULL /* new_vers_pattern */ | |
74459f0e TW |
181 | }; |
182 | EOF |