* lib/ada.exp (gdb_compile_ada): Emit UNSUPPORTED if we failed
[binutils-gdb.git] / gdb / testsuite / lib / ada.exp
1 load_lib libgloss.exp
2
3 # FIXME:brobecker/2004-03-31:
4 # The following function should eventually be part of dejagnu. Even after
5 # this function becomes available in dejagnu, we will keep for a while
6 # a copy of this function here in order to avoid increasing the dejagnu
7 # version requirement.
8
9 proc gdb_find_gnatmake {} {
10 global tool_root_dir
11
12 set root "$tool_root_dir/gcc"
13 set GM ""
14
15 if ![is_remote host] {
16 set file [lookfor_file $root gnatmake]
17 if { $file != "" } {
18 set GM "$file -I$root/ada/rts --GCC=$root/xgcc --GNATBIND=$root/gnatbind --GNATLINK=$root/gnatlink -cargs -B$root -largs --GCC=$root/xgcc -margs";
19 }
20 }
21
22 if {$GM == ""} {
23 set GM [transform gnatmake]
24 }
25
26 return $GM
27 }
28
29 # FIXME:brobecker/2004-03-31:
30 # The following function is a copy of the function of the same name provided
31 # by dejagnu, except that it has been modified to add support for building
32 # Ada programs. This copy is temporarily placed here until the changes
33 # are merged into the dejagnu official release. Once the changes are merged,
34 # we will likely keep this local copy for a while to avoid increasing the
35 # dejagnu version requirement.
36
37 proc gdb_default_target_compile {source destfile type options} {
38 global target_triplet
39 global tool_root_dir
40 global CFLAGS_FOR_TARGET
41 global compiler_flags
42
43 if { $destfile == "" && $type != "preprocess" && $type != "none" } {
44 error "Must supply an output filename for the compile to default_target_compile"
45 }
46
47 set add_flags ""
48 set libs ""
49 set compiler_type "c"
50 set compiler ""
51 set ldflags ""
52 set dest [target_info name]
53
54 if [info exists CFLAGS_FOR_TARGET] {
55 append add_flags " $CFLAGS_FOR_TARGET"
56 }
57
58 if [info exists target_info(host,name)] {
59 set host [host_info name];
60 } else {
61 set host "unix";
62 }
63
64 foreach i $options {
65 if { $i == "ada" } {
66 set compiler_type "ada"
67 if [board_info $dest exists adaflags] {
68 append add_flags " [target_info adaflags]"
69 }
70 # append add_flags " [gnatmake_include_flags]";
71 if [board_info $dest exists gnatmake] {
72 set compiler [target_info gnatmake];
73 } else {
74 set compiler [find_gnatmake];
75 }
76 }
77
78 if { $i == "c++" } {
79 set compiler_type "c++"
80 if [board_info $dest exists cxxflags] {
81 append add_flags " [target_info cxxflags]"
82 }
83 append add_flags " [g++_include_flags]";
84 if [board_info $dest exists c++compiler] {
85 set compiler [target_info c++compiler];
86 } else {
87 set compiler [find_g++];
88 }
89 }
90
91 if { $i == "f77" } {
92 set compiler_type "f77"
93 if [board_info $dest exists f77flags] {
94 append add_flags " [target_info f77flags]"
95 }
96 # append add_flags " [f77_include_flags]"
97 if [board_info $dest exists f77compiler] {
98 set compiler [target_info f77compiler]
99 } else {
100 set compiler [find_g77]
101 }
102 }
103
104 if [regexp "^dest=" $i] {
105 regsub "^dest=" $i "" tmp
106 if [board_info $tmp exists name] {
107 set dest [board_info $tmp name];
108 } else {
109 set dest $tmp;
110 }
111 }
112 if [regexp "^compiler=" $i] {
113 regsub "^compiler=" $i "" tmp
114 set compiler $tmp
115 }
116 if [regexp "^additional_flags=" $i] {
117 regsub "^additional_flags=" $i "" tmp
118 append add_flags " $tmp"
119 }
120 if [regexp "^ldflags=" $i] {
121 regsub "^ldflags=" $i "" tmp
122 append ldflags " $tmp"
123 }
124 if [regexp "^libs=" $i] {
125 regsub "^libs=" $i "" tmp
126 append libs " $tmp"
127 }
128 if [regexp "^incdir=" $i] {
129 regsub "^incdir=" $i "-I" tmp
130 append add_flags " $tmp"
131 }
132 if [regexp "^libdir=" $i] {
133 regsub "^libdir=" $i "-L" tmp
134 append add_flags " $tmp"
135 }
136 if [regexp "^ldscript=" $i] {
137 regsub "^ldscript=" $i "" ldscript
138 }
139 if [regexp "^redirect=" $i] {
140 regsub "^redirect=" $i "" redirect
141 }
142 if [regexp "^optimize=" $i] {
143 regsub "^optimize=" $i "" optimize
144 }
145 if [regexp "^timeout=" $i] {
146 regsub "^timeout=" $i "" timeout
147 }
148 }
149
150 if [board_info $host exists cflags_for_target] {
151 append add_flags " [board_info $host cflags_for_target]";
152 }
153
154 global CC_FOR_TARGET
155 global CXX_FOR_TARGET
156 global F77_FOR_TARGET
157 global GNATMAKE_FOR_TARGET
158
159 if [info exists CC_FOR_TARGET] {
160 if { $compiler == "" } {
161 set compiler $CC_FOR_TARGET
162 }
163 }
164
165 if [info exists CXX_FOR_TARGET] {
166 if { $compiler_type == "c++" } {
167 set compiler $CXX_FOR_TARGET
168 }
169 }
170
171 if [info exists F77_FOR_TARGET] {
172 if { $compiler_type == "f77" } {
173 set compiler $F77_FOR_TARGET
174 }
175 }
176
177 if [info exists GNATMAKE_FOR_TARGET] {
178 if { $compiler_type == "ada" } {
179 set compiler $GNATMAKE_FOR_TARGET
180 }
181 }
182
183 if { $compiler == "" } {
184 set compiler [board_info $dest compiler];
185 if { $compiler == "" } {
186 return "default_target_compile: No compiler to compile with";
187 }
188 }
189
190 if ![is_remote host] {
191 if { [which $compiler] == 0 } {
192 return "default_target_compile: Can't find $compiler."
193 }
194 }
195
196 if {$type == "object"} {
197 append add_flags " -c"
198 }
199
200 if { $type == "preprocess" } {
201 append add_flags " -E"
202 }
203
204 if { $type == "assembly" } {
205 append add_flags " -S"
206 }
207
208 if [board_info $dest exists cflags] {
209 append add_flags " [board_info $dest cflags]"
210 }
211
212 if { $type == "executable" } {
213 # This must be added here.
214 # if [board_info $dest exists ldscript] {
215 # append add_flags " [board_info $dest ldscript]"
216 # }
217
218 if [board_info $dest exists ldflags] {
219 append add_flags " [board_info $dest ldflags]"
220 }
221 if { $compiler_type == "c++" } {
222 append add_flags " [g++_link_flags]";
223 }
224 if [isnative] {
225 # This is a lose.
226 catch "glob -nocomplain $tool_root_dir/libstdc++/libstdc++.so* $tool_root_dir/libstdc++/libstdc++.sl" tmp
227 if { ${tmp} != "" } {
228 if [regexp ".*solaris2.*" $target_triplet] {
229 # Solaris 2
230 append add_flags " -R$tool_root_dir/libstdc++"
231 } elseif [regexp ".*(osf|irix5|linux).*" $target_triplet] {
232 # OSF/1 or Irix5
233 append add_flags " -Wl,-rpath,$tool_root_dir/libstdc++"
234 } elseif [regexp ".*hppa.*" $target_triplet] {
235 # HP/UX
236 append add_flags " -Wl,-a,shared_archive"
237 }
238 }
239 }
240 }
241
242 if ![info exists ldscript] {
243 set ldscript [board_info $dest ldscript]
244 }
245
246 foreach i $options {
247 if { $i == "debug" } {
248 if [board_info $dest exists debug_flags] {
249 append add_flags " [board_info $dest debug_flags]";
250 } else {
251 append add_flags " -g"
252 }
253 }
254 }
255
256 if [info exists optimize] {
257 append add_flags " $optimize";
258 }
259
260 if { $type == "executable" } {
261 append add_flags " $ldflags"
262 foreach x $libs {
263 if [file exists $x] {
264 append source " $x"
265 } else {
266 append add_flags " $x";
267 }
268 }
269
270 if [board_info $dest exists libs] {
271 append add_flags " [board_info $dest libs]"
272 }
273
274 # This probably isn't such a good idea, but it avoids nasty
275 # hackiness in the testsuites.
276 # The math library must be linked in before the C library. The C
277 # library is linked in by the linker script, so this must be before
278 # the linker script.
279 if [board_info $dest exists mathlib] {
280 append add_flags " [board_info $dest mathlib]"
281 } else {
282 append add_flags " -lm"
283 }
284
285 # This must be added here.
286 append add_flags " $ldscript";
287
288 if [board_info $dest exists remote_link] {
289 # Relink option.
290 append add_flags " -Wl,-r"
291 }
292 if [board_info $dest exists output_format] {
293 append add_flags " -Wl,-oformat,[board_info $dest output_format]";
294 }
295 }
296
297 if [board_info $dest exists multilib_flags] {
298 append add_flags " [board_info $dest multilib_flags]";
299 }
300
301 verbose "doing compile"
302
303 set sources ""
304 if [is_remote host] {
305 foreach x $source {
306 set file [remote_download host $x];
307 if { $file == "" } {
308 warning "Unable to download $x to host."
309 return "Unable to download $x to host."
310 } else {
311 append sources " $file";
312 }
313 }
314 } else {
315 set sources $source
316 }
317
318 if [is_remote host] {
319 append add_flags " -o a.out"
320 remote_file host delete a.out;
321 } else {
322 if { $destfile != "" } {
323 append add_flags " -o $destfile";
324 }
325 }
326
327 # This is obscure: we put SOURCES at the end when building an
328 # object, because otherwise, in some situations, libtool will
329 # become confused about the name of the actual source file.
330 if {$type == "object"} {
331 set opts "$add_flags $sources"
332 } else {
333 set opts "$sources $add_flags"
334 }
335
336 if [is_remote host] {
337 if [host_info exists use_at] {
338 set fid [open "atfile" "w"];
339 puts $fid "$opts";
340 close $fid;
341 set opts "@[remote_download host atfile]"
342 remote_file build delete atfile
343 }
344 }
345
346 verbose "Invoking the compiler as $compiler $opts" 2
347
348 if [info exists redirect] {
349 verbose "Redirecting output to $redirect" 2
350 set status [remote_exec host "$compiler $opts" "" "" $redirect];
351 } else {
352 if [info exists timeout] {
353 verbose "Setting timeout to $timeout" 2
354 set status [remote_exec host "$compiler $opts" "" "" "" $timeout];
355 } else {
356 set status [remote_exec host "$compiler $opts"];
357 }
358 }
359
360 set compiler_flags $opts
361 if [is_remote host] {
362 remote_upload host a.out $destfile;
363 remote_file host delete a.out;
364 }
365 set comp_output [prune_warnings [lindex $status 1]];
366 regsub "^\[\r\n\]+" $comp_output "" comp_output;
367 if { [lindex $status 0] != 0 } {
368 verbose -log "compiler exited with status [lindex $status 0]";
369 }
370 if { [lindex $status 1] != "" } {
371 verbose -log "output is:\n[lindex $status 1]" 2;
372 }
373 if { [lindex $status 0] != 0 && "${comp_output}" == "" } {
374 set comp_output "exit status is [lindex $status 0]";
375 }
376 return ${comp_output};
377 }
378
379 # See if the version of dejaGNU being used to run the testsuite is
380 # recent enough to contain support for building Ada programs or not.
381 # If not, then use the functions above in place of the ones provided
382 # by dejaGNU. This is only temporary (brobecker/2004-03-31).
383
384 if {[info procs find_gnatmake] == ""} {
385 proc find_gnatmake { } { return [gdb_find_gnatmake] }
386 proc default_target_compile { source destfile type options } {
387 return [gdb_default_target_compile $source $destfile $type $options]
388 }
389 }
390
391 # Compile some Ada code.
392
393 proc gdb_compile_ada {source dest type options} {
394
395 set objdir [file dirname $dest]
396
397 append options " ada"
398 append options " additional_flags=-P$objdir/gnat_ada"
399
400 set result [target_compile $source $dest $type $options]
401
402 # The Ada build always produces some output, even when the build
403 # succeeds. Thus, we can not use the output the same way we do in
404 # gdb_compile to determine whether the build has succeeded or not.
405 # We therefore simply check whether the dest file has been created
406 # or not. Unless not present, the build has succeeded.
407 if ![file exists $dest] {
408 unsupported "Ada compilation failed: $result"
409 return "Ada compilation failed."
410 }
411 }
412