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
9 proc gdb_find_gnatmake {} {
12 set root "$tool_root_dir/gcc"
15 if ![is_remote host] {
16 set file [lookfor_file $root gnatmake]
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";
23 set GM [transform gnatmake]
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.
37 proc gdb_default_target_compile {source destfile type options} {
40 global CFLAGS_FOR_TARGET
43 if { $destfile == "" && $type != "preprocess" && $type != "none" } {
44 error "Must supply an output filename for the compile to default_target_compile"
52 set dest [target_info name]
54 if [info exists CFLAGS_FOR_TARGET] {
55 append add_flags " $CFLAGS_FOR_TARGET"
58 if [info exists target_info(host,name)] {
59 set host [host_info name];
66 set compiler_type "ada"
67 if [board_info $dest exists adaflags] {
68 append add_flags " [target_info adaflags]"
70 # append add_flags " [gnatmake_include_flags]";
71 if [board_info $dest exists gnatmake] {
72 set compiler [target_info gnatmake];
74 set compiler [find_gnatmake];
79 set compiler_type "c++"
80 if [board_info $dest exists cxxflags] {
81 append add_flags " [target_info cxxflags]"
83 append add_flags " [g++_include_flags]";
84 if [board_info $dest exists c++compiler] {
85 set compiler [target_info c++compiler];
87 set compiler [find_g++];
92 set compiler_type "f77"
93 if [board_info $dest exists f77flags] {
94 append add_flags " [target_info f77flags]"
96 # append add_flags " [f77_include_flags]"
97 if [board_info $dest exists f77compiler] {
98 set compiler [target_info f77compiler]
100 set compiler [find_g77]
104 if [regexp "^dest=" $i] {
105 regsub "^dest=" $i "" tmp
106 if [board_info $tmp exists name] {
107 set dest [board_info $tmp name];
112 if [regexp "^compiler=" $i] {
113 regsub "^compiler=" $i "" tmp
116 if [regexp "^additional_flags=" $i] {
117 regsub "^additional_flags=" $i "" tmp
118 append add_flags " $tmp"
120 if [regexp "^ldflags=" $i] {
121 regsub "^ldflags=" $i "" tmp
122 append ldflags " $tmp"
124 if [regexp "^libs=" $i] {
125 regsub "^libs=" $i "" tmp
128 if [regexp "^incdir=" $i] {
129 regsub "^incdir=" $i "-I" tmp
130 append add_flags " $tmp"
132 if [regexp "^libdir=" $i] {
133 regsub "^libdir=" $i "-L" tmp
134 append add_flags " $tmp"
136 if [regexp "^ldscript=" $i] {
137 regsub "^ldscript=" $i "" ldscript
139 if [regexp "^redirect=" $i] {
140 regsub "^redirect=" $i "" redirect
142 if [regexp "^optimize=" $i] {
143 regsub "^optimize=" $i "" optimize
145 if [regexp "^timeout=" $i] {
146 regsub "^timeout=" $i "" timeout
150 if [board_info $host exists cflags_for_target] {
151 append add_flags " [board_info $host cflags_for_target]";
155 global CXX_FOR_TARGET
156 global F77_FOR_TARGET
157 global GNATMAKE_FOR_TARGET
159 if [info exists CC_FOR_TARGET] {
160 if { $compiler == "" } {
161 set compiler $CC_FOR_TARGET
165 if [info exists CXX_FOR_TARGET] {
166 if { $compiler_type == "c++" } {
167 set compiler $CXX_FOR_TARGET
171 if [info exists F77_FOR_TARGET] {
172 if { $compiler_type == "f77" } {
173 set compiler $F77_FOR_TARGET
177 if [info exists GNATMAKE_FOR_TARGET] {
178 if { $compiler_type == "ada" } {
179 set compiler $GNATMAKE_FOR_TARGET
183 if { $compiler == "" } {
184 set compiler [board_info $dest compiler];
185 if { $compiler == "" } {
186 return "default_target_compile: No compiler to compile with";
190 if ![is_remote host] {
191 if { [which $compiler] == 0 } {
192 return "default_target_compile: Can't find $compiler."
196 if {$type == "object"} {
197 append add_flags " -c"
200 if { $type == "preprocess" } {
201 append add_flags " -E"
204 if { $type == "assembly" } {
205 append add_flags " -S"
208 if [board_info $dest exists cflags] {
209 append add_flags " [board_info $dest cflags]"
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]"
218 if [board_info $dest exists ldflags] {
219 append add_flags " [board_info $dest ldflags]"
221 if { $compiler_type == "c++" } {
222 append add_flags " [g++_link_flags]";
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] {
230 append add_flags " -R$tool_root_dir/libstdc++"
231 } elseif [regexp ".*(osf|irix5|linux).*" $target_triplet] {
233 append add_flags " -Wl,-rpath,$tool_root_dir/libstdc++"
234 } elseif [regexp ".*hppa.*" $target_triplet] {
236 append add_flags " -Wl,-a,shared_archive"
242 if ![info exists ldscript] {
243 set ldscript [board_info $dest ldscript]
247 if { $i == "debug" } {
248 if [board_info $dest exists debug_flags] {
249 append add_flags " [board_info $dest debug_flags]";
251 append add_flags " -g"
256 if [info exists optimize] {
257 append add_flags " $optimize";
260 if { $type == "executable" } {
261 append add_flags " $ldflags"
263 if [file exists $x] {
266 append add_flags " $x";
270 if [board_info $dest exists libs] {
271 append add_flags " [board_info $dest libs]"
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
279 if [board_info $dest exists mathlib] {
280 append add_flags " [board_info $dest mathlib]"
282 append add_flags " -lm"
285 # This must be added here.
286 append add_flags " $ldscript";
288 if [board_info $dest exists remote_link] {
290 append add_flags " -Wl,-r"
292 if [board_info $dest exists output_format] {
293 append add_flags " -Wl,-oformat,[board_info $dest output_format]";
297 if [board_info $dest exists multilib_flags] {
298 append add_flags " [board_info $dest multilib_flags]";
301 verbose "doing compile"
304 if [is_remote host] {
306 set file [remote_download host $x];
308 warning "Unable to download $x to host."
309 return "Unable to download $x to host."
311 append sources " $file";
318 if [is_remote host] {
319 append add_flags " -o a.out"
320 remote_file host delete a.out;
322 if { $destfile != "" } {
323 append add_flags " -o $destfile";
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"
333 set opts "$sources $add_flags"
336 if [is_remote host] {
337 if [host_info exists use_at] {
338 set fid [open "atfile" "w"];
341 set opts "@[remote_download host atfile]"
342 remote_file build delete atfile
346 verbose "Invoking the compiler as $compiler $opts" 2
348 if [info exists redirect] {
349 verbose "Redirecting output to $redirect" 2
350 set status [remote_exec host "$compiler $opts" "" "" $redirect];
352 if [info exists timeout] {
353 verbose "Setting timeout to $timeout" 2
354 set status [remote_exec host "$compiler $opts" "" "" "" $timeout];
356 set status [remote_exec host "$compiler $opts"];
360 set compiler_flags $opts
361 if [is_remote host] {
362 remote_upload host a.out $destfile;
363 remote_file host delete a.out;
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]";
370 if { [lindex $status 1] != "" } {
371 verbose -log "output is:\n[lindex $status 1]" 2;
373 if { [lindex $status 0] != 0 && "${comp_output}" == "" } {
374 set comp_output "exit status is [lindex $status 0]";
376 return ${comp_output};
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).
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]
391 # Compile some Ada code.
393 proc gdb_compile_ada {source dest type options} {
395 set objdir [file dirname $dest]
397 append options " ada"
398 append options " additional_flags=-P$objdir/gnat_ada"
400 set result [target_compile $source $dest $type $options]
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."