1 # Copyright 2004, 2007 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 3 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, see <http://www.gnu.org/licenses/>.
18 # FIXME:brobecker/2004-03-31:
19 # The following function should eventually be part of dejagnu. Even after
20 # this function becomes available in dejagnu, we will keep for a while
21 # a copy of this function here in order to avoid increasing the dejagnu
22 # version requirement.
24 proc gdb_find_gnatmake {} {
27 set root "$tool_root_dir/gcc"
30 if ![is_remote host] {
31 set file [lookfor_file $root gnatmake]
33 set GM "$file -I$root/ada/rts --GCC=$root/xgcc --GNATBIND=$root/gnatbind --GNATLINK=$root/gnatlink -cargs -B$root -largs --GCC=$root/xgcc -margs";
38 set GM [transform gnatmake]
44 # FIXME:brobecker/2004-03-31:
45 # The following function is a copy of the function of the same name provided
46 # by dejagnu, except that it has been modified to add support for building
47 # Ada programs. This copy is temporarily placed here until the changes
48 # are merged into the dejagnu official release. Once the changes are merged,
49 # we will likely keep this local copy for a while to avoid increasing the
50 # dejagnu version requirement.
52 proc gdb_default_target_compile {source destfile type options} {
55 global CFLAGS_FOR_TARGET
58 if { $destfile == "" && $type != "preprocess" && $type != "none" } {
59 error "Must supply an output filename for the compile to default_target_compile"
67 set dest [target_info name]
69 if [info exists CFLAGS_FOR_TARGET] {
70 append add_flags " $CFLAGS_FOR_TARGET"
73 if [info exists target_info(host,name)] {
74 set host [host_info name];
81 set compiler_type "ada"
82 if [board_info $dest exists adaflags] {
83 append add_flags " [target_info adaflags]"
85 # append add_flags " [gnatmake_include_flags]";
86 if [board_info $dest exists gnatmake] {
87 set compiler [target_info gnatmake];
89 set compiler [find_gnatmake];
94 set compiler_type "c++"
95 if [board_info $dest exists cxxflags] {
96 append add_flags " [target_info cxxflags]"
98 append add_flags " [g++_include_flags]";
99 if [board_info $dest exists c++compiler] {
100 set compiler [target_info c++compiler];
102 set compiler [find_g++];
107 set compiler_type "f77"
108 if [board_info $dest exists f77flags] {
109 append add_flags " [target_info f77flags]"
111 # append add_flags " [f77_include_flags]"
112 if [board_info $dest exists f77compiler] {
113 set compiler [target_info f77compiler]
115 set compiler [find_g77]
119 if [regexp "^dest=" $i] {
120 regsub "^dest=" $i "" tmp
121 if [board_info $tmp exists name] {
122 set dest [board_info $tmp name];
127 if [regexp "^compiler=" $i] {
128 regsub "^compiler=" $i "" tmp
131 if [regexp "^additional_flags=" $i] {
132 regsub "^additional_flags=" $i "" tmp
133 append add_flags " $tmp"
135 if [regexp "^ldflags=" $i] {
136 regsub "^ldflags=" $i "" tmp
137 append ldflags " $tmp"
139 if [regexp "^libs=" $i] {
140 regsub "^libs=" $i "" tmp
143 if [regexp "^incdir=" $i] {
144 regsub "^incdir=" $i "-I" tmp
145 append add_flags " $tmp"
147 if [regexp "^libdir=" $i] {
148 regsub "^libdir=" $i "-L" tmp
149 append add_flags " $tmp"
151 if [regexp "^ldscript=" $i] {
152 regsub "^ldscript=" $i "" ldscript
154 if [regexp "^redirect=" $i] {
155 regsub "^redirect=" $i "" redirect
157 if [regexp "^optimize=" $i] {
158 regsub "^optimize=" $i "" optimize
160 if [regexp "^timeout=" $i] {
161 regsub "^timeout=" $i "" timeout
165 if [board_info $host exists cflags_for_target] {
166 append add_flags " [board_info $host cflags_for_target]";
170 global CXX_FOR_TARGET
171 global F77_FOR_TARGET
172 global GNATMAKE_FOR_TARGET
174 if [info exists CC_FOR_TARGET] {
175 if { $compiler == "" } {
176 set compiler $CC_FOR_TARGET
180 if [info exists CXX_FOR_TARGET] {
181 if { $compiler_type == "c++" } {
182 set compiler $CXX_FOR_TARGET
186 if [info exists F77_FOR_TARGET] {
187 if { $compiler_type == "f77" } {
188 set compiler $F77_FOR_TARGET
192 if [info exists GNATMAKE_FOR_TARGET] {
193 if { $compiler_type == "ada" } {
194 set compiler $GNATMAKE_FOR_TARGET
198 if { $compiler == "" } {
199 set compiler [board_info $dest compiler];
200 if { $compiler == "" } {
201 return "default_target_compile: No compiler to compile with";
205 if ![is_remote host] {
206 if { [which $compiler] == 0 } {
207 return "default_target_compile: Can't find $compiler."
211 if {$type == "object"} {
212 append add_flags " -c"
215 if { $type == "preprocess" } {
216 append add_flags " -E"
219 if { $type == "assembly" } {
220 append add_flags " -S"
223 if [board_info $dest exists cflags] {
224 append add_flags " [board_info $dest cflags]"
227 if { $type == "executable" } {
228 # This must be added here.
229 # if [board_info $dest exists ldscript] {
230 # append add_flags " [board_info $dest ldscript]"
233 if [board_info $dest exists ldflags] {
234 append add_flags " [board_info $dest ldflags]"
236 if { $compiler_type == "c++" } {
237 append add_flags " [g++_link_flags]";
241 catch "glob -nocomplain $tool_root_dir/libstdc++/libstdc++.so* $tool_root_dir/libstdc++/libstdc++.sl" tmp
242 if { ${tmp} != "" } {
243 if [regexp ".*solaris2.*" $target_triplet] {
245 append add_flags " -R$tool_root_dir/libstdc++"
246 } elseif [regexp ".*(osf|irix5|linux).*" $target_triplet] {
248 append add_flags " -Wl,-rpath,$tool_root_dir/libstdc++"
249 } elseif [regexp ".*hppa.*" $target_triplet] {
251 append add_flags " -Wl,-a,shared_archive"
257 if ![info exists ldscript] {
258 set ldscript [board_info $dest ldscript]
262 if { $i == "debug" } {
263 if [board_info $dest exists debug_flags] {
264 append add_flags " [board_info $dest debug_flags]";
266 append add_flags " -g"
271 if [info exists optimize] {
272 append add_flags " $optimize";
275 if { $type == "executable" } {
276 append add_flags " $ldflags"
278 if [file exists $x] {
281 append add_flags " $x";
285 if [board_info $dest exists libs] {
286 append add_flags " [board_info $dest libs]"
289 # This probably isn't such a good idea, but it avoids nasty
290 # hackiness in the testsuites.
291 # The math library must be linked in before the C library. The C
292 # library is linked in by the linker script, so this must be before
294 if [board_info $dest exists mathlib] {
295 append add_flags " [board_info $dest mathlib]"
297 append add_flags " -lm"
300 # This must be added here.
301 append add_flags " $ldscript";
303 if [board_info $dest exists remote_link] {
305 append add_flags " -Wl,-r"
307 if [board_info $dest exists output_format] {
308 append add_flags " -Wl,-oformat,[board_info $dest output_format]";
312 if [board_info $dest exists multilib_flags] {
313 append add_flags " [board_info $dest multilib_flags]";
316 verbose "doing compile"
319 if [is_remote host] {
321 set file [remote_download host $x];
323 warning "Unable to download $x to host."
324 return "Unable to download $x to host."
326 append sources " $file";
333 if [is_remote host] {
334 append add_flags " -o a.out"
335 remote_file host delete a.out;
337 if { $destfile != "" } {
338 append add_flags " -o $destfile";
342 # This is obscure: we put SOURCES at the end when building an
343 # object, because otherwise, in some situations, libtool will
344 # become confused about the name of the actual source file.
345 if {$type == "object"} {
346 set opts "$add_flags $sources"
348 set opts "$sources $add_flags"
351 if [is_remote host] {
352 if [host_info exists use_at] {
353 set fid [open "atfile" "w"];
356 set opts "@[remote_download host atfile]"
357 remote_file build delete atfile
361 verbose "Invoking the compiler as $compiler $opts" 2
363 if [info exists redirect] {
364 verbose "Redirecting output to $redirect" 2
365 set status [remote_exec host "$compiler $opts" "" "" $redirect];
367 if [info exists timeout] {
368 verbose "Setting timeout to $timeout" 2
369 set status [remote_exec host "$compiler $opts" "" "" "" $timeout];
371 set status [remote_exec host "$compiler $opts"];
375 set compiler_flags $opts
376 if [is_remote host] {
377 remote_upload host a.out $destfile;
378 remote_file host delete a.out;
380 set comp_output [prune_warnings [lindex $status 1]];
381 regsub "^\[\r\n\]+" $comp_output "" comp_output;
382 if { [lindex $status 0] != 0 } {
383 verbose -log "compiler exited with status [lindex $status 0]";
385 if { [lindex $status 1] != "" } {
386 verbose -log "output is:\n[lindex $status 1]" 2;
388 if { [lindex $status 0] != 0 && "${comp_output}" == "" } {
389 set comp_output "exit status is [lindex $status 0]";
391 return ${comp_output};
394 # See if the version of dejaGNU being used to run the testsuite is
395 # recent enough to contain support for building Ada programs or not.
396 # If not, then use the functions above in place of the ones provided
397 # by dejaGNU. This is only temporary (brobecker/2004-03-31).
399 if {[info procs find_gnatmake] == ""} {
400 proc find_gnatmake { } { return [gdb_find_gnatmake] }
401 proc default_target_compile { source destfile type options } {
402 return [gdb_default_target_compile $source $destfile $type $options]
406 # Compile some Ada code.
408 proc gdb_compile_ada {source dest type options} {
410 set srcdir [file dirname $source]
411 set gprdir [file dirname $srcdir]
412 set objdir [file dirname $dest]
414 append options " ada"
415 append options " additional_flags=-P$gprdir/gnat_ada"
416 append options " additional_flags=-XSRC=[file tail $srcdir]"
417 append options " additional_flags=-XOBJ=$objdir"
419 set result [target_compile [file tail $source] $dest $type $options]
421 # The Ada build always produces some output, even when the build
422 # succeeds. Thus, we can not use the output the same way we do in
423 # gdb_compile to determine whether the build has succeeded or not.
424 # We therefore simply check whether the dest file has been created
425 # or not. Unless not present, the build has succeeded.
426 if ![file exists $dest] {
427 unsupported "Ada compilation failed: $result"
428 return "Ada compilation failed."