1 # Copyright 2004 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 # FIXME:brobecker/2004-03-31:
21 # The following function should eventually be part of dejagnu. Even after
22 # this function becomes available in dejagnu, we will keep for a while
23 # a copy of this function here in order to avoid increasing the dejagnu
24 # version requirement.
26 proc gdb_find_gnatmake {} {
29 set root "$tool_root_dir/gcc"
32 if ![is_remote host] {
33 set file [lookfor_file $root gnatmake]
35 set GM "$file -I$root/ada/rts --GCC=$root/xgcc --GNATBIND=$root/gnatbind --GNATLINK=$root/gnatlink -cargs -B$root -largs --GCC=$root/xgcc -margs";
40 set GM [transform gnatmake]
46 # FIXME:brobecker/2004-03-31:
47 # The following function is a copy of the function of the same name provided
48 # by dejagnu, except that it has been modified to add support for building
49 # Ada programs. This copy is temporarily placed here until the changes
50 # are merged into the dejagnu official release. Once the changes are merged,
51 # we will likely keep this local copy for a while to avoid increasing the
52 # dejagnu version requirement.
54 proc gdb_default_target_compile {source destfile type options} {
57 global CFLAGS_FOR_TARGET
60 if { $destfile == "" && $type != "preprocess" && $type != "none" } {
61 error "Must supply an output filename for the compile to default_target_compile"
69 set dest [target_info name]
71 if [info exists CFLAGS_FOR_TARGET] {
72 append add_flags " $CFLAGS_FOR_TARGET"
75 if [info exists target_info(host,name)] {
76 set host [host_info name];
83 set compiler_type "ada"
84 if [board_info $dest exists adaflags] {
85 append add_flags " [target_info adaflags]"
87 # append add_flags " [gnatmake_include_flags]";
88 if [board_info $dest exists gnatmake] {
89 set compiler [target_info gnatmake];
91 set compiler [find_gnatmake];
96 set compiler_type "c++"
97 if [board_info $dest exists cxxflags] {
98 append add_flags " [target_info cxxflags]"
100 append add_flags " [g++_include_flags]";
101 if [board_info $dest exists c++compiler] {
102 set compiler [target_info c++compiler];
104 set compiler [find_g++];
109 set compiler_type "f77"
110 if [board_info $dest exists f77flags] {
111 append add_flags " [target_info f77flags]"
113 # append add_flags " [f77_include_flags]"
114 if [board_info $dest exists f77compiler] {
115 set compiler [target_info f77compiler]
117 set compiler [find_g77]
121 if [regexp "^dest=" $i] {
122 regsub "^dest=" $i "" tmp
123 if [board_info $tmp exists name] {
124 set dest [board_info $tmp name];
129 if [regexp "^compiler=" $i] {
130 regsub "^compiler=" $i "" tmp
133 if [regexp "^additional_flags=" $i] {
134 regsub "^additional_flags=" $i "" tmp
135 append add_flags " $tmp"
137 if [regexp "^ldflags=" $i] {
138 regsub "^ldflags=" $i "" tmp
139 append ldflags " $tmp"
141 if [regexp "^libs=" $i] {
142 regsub "^libs=" $i "" tmp
145 if [regexp "^incdir=" $i] {
146 regsub "^incdir=" $i "-I" tmp
147 append add_flags " $tmp"
149 if [regexp "^libdir=" $i] {
150 regsub "^libdir=" $i "-L" tmp
151 append add_flags " $tmp"
153 if [regexp "^ldscript=" $i] {
154 regsub "^ldscript=" $i "" ldscript
156 if [regexp "^redirect=" $i] {
157 regsub "^redirect=" $i "" redirect
159 if [regexp "^optimize=" $i] {
160 regsub "^optimize=" $i "" optimize
162 if [regexp "^timeout=" $i] {
163 regsub "^timeout=" $i "" timeout
167 if [board_info $host exists cflags_for_target] {
168 append add_flags " [board_info $host cflags_for_target]";
172 global CXX_FOR_TARGET
173 global F77_FOR_TARGET
174 global GNATMAKE_FOR_TARGET
176 if [info exists CC_FOR_TARGET] {
177 if { $compiler == "" } {
178 set compiler $CC_FOR_TARGET
182 if [info exists CXX_FOR_TARGET] {
183 if { $compiler_type == "c++" } {
184 set compiler $CXX_FOR_TARGET
188 if [info exists F77_FOR_TARGET] {
189 if { $compiler_type == "f77" } {
190 set compiler $F77_FOR_TARGET
194 if [info exists GNATMAKE_FOR_TARGET] {
195 if { $compiler_type == "ada" } {
196 set compiler $GNATMAKE_FOR_TARGET
200 if { $compiler == "" } {
201 set compiler [board_info $dest compiler];
202 if { $compiler == "" } {
203 return "default_target_compile: No compiler to compile with";
207 if ![is_remote host] {
208 if { [which $compiler] == 0 } {
209 return "default_target_compile: Can't find $compiler."
213 if {$type == "object"} {
214 append add_flags " -c"
217 if { $type == "preprocess" } {
218 append add_flags " -E"
221 if { $type == "assembly" } {
222 append add_flags " -S"
225 if [board_info $dest exists cflags] {
226 append add_flags " [board_info $dest cflags]"
229 if { $type == "executable" } {
230 # This must be added here.
231 # if [board_info $dest exists ldscript] {
232 # append add_flags " [board_info $dest ldscript]"
235 if [board_info $dest exists ldflags] {
236 append add_flags " [board_info $dest ldflags]"
238 if { $compiler_type == "c++" } {
239 append add_flags " [g++_link_flags]";
243 catch "glob -nocomplain $tool_root_dir/libstdc++/libstdc++.so* $tool_root_dir/libstdc++/libstdc++.sl" tmp
244 if { ${tmp} != "" } {
245 if [regexp ".*solaris2.*" $target_triplet] {
247 append add_flags " -R$tool_root_dir/libstdc++"
248 } elseif [regexp ".*(osf|irix5|linux).*" $target_triplet] {
250 append add_flags " -Wl,-rpath,$tool_root_dir/libstdc++"
251 } elseif [regexp ".*hppa.*" $target_triplet] {
253 append add_flags " -Wl,-a,shared_archive"
259 if ![info exists ldscript] {
260 set ldscript [board_info $dest ldscript]
264 if { $i == "debug" } {
265 if [board_info $dest exists debug_flags] {
266 append add_flags " [board_info $dest debug_flags]";
268 append add_flags " -g"
273 if [info exists optimize] {
274 append add_flags " $optimize";
277 if { $type == "executable" } {
278 append add_flags " $ldflags"
280 if [file exists $x] {
283 append add_flags " $x";
287 if [board_info $dest exists libs] {
288 append add_flags " [board_info $dest libs]"
291 # This probably isn't such a good idea, but it avoids nasty
292 # hackiness in the testsuites.
293 # The math library must be linked in before the C library. The C
294 # library is linked in by the linker script, so this must be before
296 if [board_info $dest exists mathlib] {
297 append add_flags " [board_info $dest mathlib]"
299 append add_flags " -lm"
302 # This must be added here.
303 append add_flags " $ldscript";
305 if [board_info $dest exists remote_link] {
307 append add_flags " -Wl,-r"
309 if [board_info $dest exists output_format] {
310 append add_flags " -Wl,-oformat,[board_info $dest output_format]";
314 if [board_info $dest exists multilib_flags] {
315 append add_flags " [board_info $dest multilib_flags]";
318 verbose "doing compile"
321 if [is_remote host] {
323 set file [remote_download host $x];
325 warning "Unable to download $x to host."
326 return "Unable to download $x to host."
328 append sources " $file";
335 if [is_remote host] {
336 append add_flags " -o a.out"
337 remote_file host delete a.out;
339 if { $destfile != "" } {
340 append add_flags " -o $destfile";
344 # This is obscure: we put SOURCES at the end when building an
345 # object, because otherwise, in some situations, libtool will
346 # become confused about the name of the actual source file.
347 if {$type == "object"} {
348 set opts "$add_flags $sources"
350 set opts "$sources $add_flags"
353 if [is_remote host] {
354 if [host_info exists use_at] {
355 set fid [open "atfile" "w"];
358 set opts "@[remote_download host atfile]"
359 remote_file build delete atfile
363 verbose "Invoking the compiler as $compiler $opts" 2
365 if [info exists redirect] {
366 verbose "Redirecting output to $redirect" 2
367 set status [remote_exec host "$compiler $opts" "" "" $redirect];
369 if [info exists timeout] {
370 verbose "Setting timeout to $timeout" 2
371 set status [remote_exec host "$compiler $opts" "" "" "" $timeout];
373 set status [remote_exec host "$compiler $opts"];
377 set compiler_flags $opts
378 if [is_remote host] {
379 remote_upload host a.out $destfile;
380 remote_file host delete a.out;
382 set comp_output [prune_warnings [lindex $status 1]];
383 regsub "^\[\r\n\]+" $comp_output "" comp_output;
384 if { [lindex $status 0] != 0 } {
385 verbose -log "compiler exited with status [lindex $status 0]";
387 if { [lindex $status 1] != "" } {
388 verbose -log "output is:\n[lindex $status 1]" 2;
390 if { [lindex $status 0] != 0 && "${comp_output}" == "" } {
391 set comp_output "exit status is [lindex $status 0]";
393 return ${comp_output};
396 # See if the version of dejaGNU being used to run the testsuite is
397 # recent enough to contain support for building Ada programs or not.
398 # If not, then use the functions above in place of the ones provided
399 # by dejaGNU. This is only temporary (brobecker/2004-03-31).
401 if {[info procs find_gnatmake] == ""} {
402 proc find_gnatmake { } { return [gdb_find_gnatmake] }
403 proc default_target_compile { source destfile type options } {
404 return [gdb_default_target_compile $source $destfile $type $options]
408 # Compile some Ada code.
410 proc gdb_compile_ada {source dest type options} {
412 set srcdir [file dirname $source]
413 set gprdir [file dirname $srcdir]
414 set objdir [file dirname $dest]
416 append options " ada"
417 append options " additional_flags=-P$gprdir/gnat_ada"
418 append options " additional_flags=-XSRC=[file tail $srcdir]"
419 append options " additional_flags=-XOBJ=$objdir"
421 set result [target_compile [file tail $source] $dest $type $options]
423 # The Ada build always produces some output, even when the build
424 # succeeds. Thus, we can not use the output the same way we do in
425 # gdb_compile to determine whether the build has succeeded or not.
426 # We therefore simply check whether the dest file has been created
427 # or not. Unless not present, the build has succeeded.
428 if ![file exists $dest] {
429 unsupported "Ada compilation failed: $result"
430 return "Ada compilation failed."