1 # Copyright (C) 2006, 2007, 2008, 2009, 2010 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 GCC; see the file COPYING3. If not see
15 # <http://www.gnu.org/licenses/>.
17 # This file was written by James A. Morrison (ja2morri@uwaterloo.ca)
18 # based on gcc.exp written by Rob Savoye (rob@cygnus.com).
20 # This file is loaded by the tool init file (eg: unix.exp). It provides
21 # default definitions for gnat_start, etc. and other supporting cast members.
23 # These globals are used if no compiler arguments are provided.
24 # They are also used by the various testsuites to define the environment:
25 # where to find stdio.h, libc.a, etc.
33 # GNAT_UNDER_TEST is the compiler under test.
37 # default_gnat_version -- extract and print the version number of the compiler
40 proc default_gnat_version { } {
41 global GNAT_UNDER_TEST
45 # ignore any arguments after the command
46 set compiler [lindex $GNAT_UNDER_TEST 0]
48 if ![is_remote host] {
49 set compiler_name [which $compiler]
51 set compiler_name $compiler
54 # verify that the compiler exists
55 if { $compiler_name != 0 } then {
56 set tmp [remote_exec host "$compiler -v"]
57 set status [lindex $tmp 0]
58 set output [lindex $tmp 1]
59 regexp " version \[^\n\r\]*" $output version
60 if { $status == 0 && [info exists version] } then {
61 clone_output "$compiler_name $version\n"
63 clone_output "Couldn't determine version of $compiler_name: $output\n"
66 # compiler does not exist (this should have already been detected)
67 warning "$compiler does not exist"
71 # gnat_init -- called at the start of each .exp script.
73 # There currently isn't much to do, but always using it allows us to
74 # make some enhancements without having to go back and rewrite the scripts.
77 set gnat_initialized 0
79 proc gnat_init { args } {
83 global gluefile wrap_flags
84 global gnat_initialized
85 global GNAT_UNDER_TEST
86 global TOOL_EXECUTABLE
87 global gnat_libgcc_s_path
88 global gnat_target_current
90 set gnat_target_current ""
92 if { $gnat_initialized == 1 } { return }
94 if ![info exists GNAT_UNDER_TEST] then {
95 if [info exists TOOL_EXECUTABLE] {
96 set GNAT_UNDER_TEST "$TOOL_EXECUTABLE"
98 set GNAT_UNDER_TEST "[local_find_gnatmake]"
102 if ![info exists tmpdir] then {
106 set gnat_libgcc_s_path "${rootme}"
107 # Leave this here since Ada should support multilibs at some point.
108 set compiler [lindex $GNAT_UNDER_TEST 0]
109 # if { [is_remote host] == 0 && [which $compiler] != 0 } {
110 # foreach i "[exec $compiler --print-multi-lib]" {
112 # regexp -- "\[a-z0-9=/\.-\]*;" $i mldir
113 # set mldir [string trimright $mldir "\;@"]
114 # if { "$mldir" == "." } {
117 # if { [llength [glob -nocomplain ${rootme}/${mldir}/libgcc_s*.so.*]] >= 1 } {
118 # append gnat_libgcc_s_path ":${rootme}/${mldir}"
124 proc gnat_target_compile { source dest type options } {
127 global gluefile wrap_flags
129 global GNAT_UNDER_TEST
131 global ld_library_path
132 global gnat_libgcc_s_path
133 global gnat_target_current
135 # If we detect a change of target, we need to recompute both
136 # GNAT_UNDER_TEST and the appropriate RTS.
137 if { $gnat_target_current!="[current_target_name]" } {
138 set gnat_target_current "[current_target_name]"
139 if [info exists TOOL_OPTIONS] {
140 set rtsdir "[get_multilibs ${TOOL_OPTIONS}]/libada"
142 set rtsdir "[get_multilibs]/libada"
144 if [info exists TOOL_EXECUTABLE] {
145 set GNAT_UNDER_TEST "$TOOL_EXECUTABLE"
147 set GNAT_UNDER_TEST "[local_find_gnatmake]"
149 set GNAT_UNDER_TEST "$GNAT_UNDER_TEST --RTS=$rtsdir"
151 # gnatlink looks for system.ads itself and has no --RTS option, so
152 # specify via environment
153 setenv ADA_INCLUDE_PATH "$rtsdir/adainclude"
154 setenv ADA_OBJECTS_PATH "$rtsdir/adainclude"
157 set ld_library_path ".:${gnat_libgcc_s_path}"
158 lappend options "compiler=$GNAT_UNDER_TEST -q -f"
159 lappend options "timeout=[timeout_value]"
161 if { [target_info needs_status_wrapper]!="" && [info exists gluefile] } {
162 lappend options "libs=${gluefile}"
163 lappend options "ldflags=$wrap_flags"
166 # TOOL_OPTIONS must come first, so that it doesn't override testcase
168 if [info exists TOOL_OPTIONS] {
169 set options [concat "additional_flags=$TOOL_OPTIONS" $options]
172 # If we have built libada along with the compiler, point the test harness
173 # at it (and associated headers).
175 # set sourcename [string range $source 0 [expr [string length $source] - 5]]
178 return [target_compile $source $dest $type $options]
182 # gnat_pass -- utility to record a testcase passed
185 proc gnat_pass { testcase cflags } {
186 if { "$cflags" == "" } {
189 pass "$testcase, $cflags"
194 # gnat_fail -- utility to record a testcase failed
197 proc gnat_fail { testcase cflags } {
198 if { "$cflags" == "" } {
201 fail "$testcase, $cflags"
206 # gnat_finish -- called at the end of every .exp script that calls gnat_init
208 # The purpose of this proc is to hide all quirks of the testing environment
209 # from the testsuites. It also exists to undo anything that gnat_init did
210 # (that needs undoing).
213 proc gnat_finish { } {
214 # The testing harness apparently requires this.
217 if [info exists errorInfo] then {
221 # Might as well reset these (keeps our caller from wondering whether
222 # s/he has to or not).
223 global prms_id bug_id
231 if [info exists gluefile] {
232 file_on_build delete $gluefile
237 # Prune messages from GNAT that aren't useful.
239 proc prune_gnat_output { text } {
240 #send_user "Before:$text\n"
241 regsub -all "(^|\n)\[^\n\]*: In (function|method) \[^\n\]*" $text "" text
242 regsub -all "(^|\n)\[^\n\]*: At top level:\[^\n\]*" $text "" text
244 # prune the output from gnatmake.
245 regsub -all "(^|\n)\[^\n\]*gnatmake: [^\n\]*" $text "" text
247 # It would be nice to avoid passing anything to gnat that would cause it to
248 # issue these messages (since ignoring them seems like a hack on our part),
249 # but that's too difficult in the general case. For example, sometimes
250 # you need to use -B to point gnat at crt0.o, but there are some targets
251 # that don't have crt0.o.
252 regsub -all "(^|\n)\[^\n\]*file path prefix \[^\n\]* never used" $text "" text
253 regsub -all "(^|\n)\[^\n\]*linker input file unused since linking not done" $text "" text
255 #send_user "After:$text\n"
260 # find_gnatmake for some version of DejaGnu will hardcode a -I...rts/ada flag
261 # which prevent multilib from working, so define a new one.
263 proc local_find_gnatmake {} {
266 if ![is_remote host] {
267 set file [lookfor_file $tool_root_dir gnatmake]
269 set file [lookfor_file $tool_root_dir gcc/gnatmake]
272 set root [file dirname $file]
273 # Need to pass full --GCC, including multilib flags, to gnatlink,
274 # otherwise gcc from PATH is invoked.
275 set dest [target_info name]
276 set gnatlink_gcc "--GCC=$root/xgcc -B$root [board_info $dest multilib_flags]"
277 # Escape blanks to get them through DejaGnu's exec machinery.
278 regsub -all {\s} "$gnatlink_gcc" {\\&} gnatlink_gcc
279 set CC "$file --GCC=$root/xgcc --GNATBIND=$root/gnatbind --GNATLINK=$root/gnatlink -cargs -B$root -largs $gnatlink_gcc -margs";
281 set CC [transform gnatmake]
284 set CC [transform gnatmake]
289 # If this is an older version of DejaGnu (without runtest_file_p),
290 # provide one and assume the old syntax: foo1.exp bar1.c foo2.exp bar2.c.
291 # This can be deleted after next DejaGnu release.
293 if { [info procs runtest_file_p] == "" } then {
294 proc runtest_file_p { runtests testcase } {
295 if { $runtests != "" && [regexp "\[.\]\[cC\]" $runtests] } then {
296 if { [lsearch $runtests [file tail $testcase]] >= 0 } then {
306 # Provide a definition of this if missing (delete after next DejaGnu release).
308 if { [info procs prune_warnings] == "" } then {
309 proc prune_warnings { text } {