]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/testsuite/lib/gnat.exp
gnat.exp: Fix comments.
[thirdparty/gcc.git] / gcc / testsuite / lib / gnat.exp
CommitLineData
6bad16bb
RO
1# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011
2# Free Software Foundation, Inc.
663230c4
JM
3
4# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
cd976c16 6# the Free Software Foundation; either version 3 of the License, or
663230c4
JM
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
cd976c16
NC
15# along with GCC; see the file COPYING3. If not see
16# <http://www.gnu.org/licenses/>.
663230c4
JM
17
18# This file was written by James A. Morrison (ja2morri@uwaterloo.ca)
19# based on gcc.exp written by Rob Savoye (rob@cygnus.com).
20
21# This file is loaded by the tool init file (eg: unix.exp). It provides
22# default definitions for gnat_start, etc. and other supporting cast members.
23
663230c4
JM
24load_lib prune.exp
25load_lib gcc-defs.exp
3ffcc54f 26load_lib gcc.exp
d4038ca2 27load_lib timeout.exp
663230c4
JM
28
29#
30# GNAT_UNDER_TEST is the compiler under test.
31#
32
33#
34# default_gnat_version -- extract and print the version number of the compiler
35#
36
37proc default_gnat_version { } {
38 global GNAT_UNDER_TEST
39
40 gnat_init
41
42 # ignore any arguments after the command
43 set compiler [lindex $GNAT_UNDER_TEST 0]
44
45 if ![is_remote host] {
46 set compiler_name [which $compiler]
47 } else {
48 set compiler_name $compiler
49 }
50
51 # verify that the compiler exists
52 if { $compiler_name != 0 } then {
6bad16bb 53 set tmp [remote_exec host "$compiler --version"]
663230c4
JM
54 set status [lindex $tmp 0]
55 set output [lindex $tmp 1]
6bad16bb 56 regexp "^GNATMAKE (\[^\n\r\]*)" $output verline version
663230c4 57 if { $status == 0 && [info exists version] } then {
6bad16bb
RO
58 # test_summary expects "version" as second field.
59 clone_output "$compiler_name version $version\n"
663230c4
JM
60 } else {
61 clone_output "Couldn't determine version of $compiler_name: $output\n"
62 }
63 } else {
64 # compiler does not exist (this should have already been detected)
65 warning "$compiler does not exist"
66 }
67}
68
663230c4 69#
6bad16bb
RO
70# gnat_version -- Call default_gnat_version, so we can override it if needed.
71#
72
73proc gnat_version { } {
74 default_gnat_version
75}
76
77#
78# gnat_init -- called at the start of each .exp script.
663230c4
JM
79#
80
81set gnat_initialized 0
82
83proc gnat_init { args } {
84 global rootme
85 global tmpdir
86 global libdir
87 global gluefile wrap_flags
88 global gnat_initialized
89 global GNAT_UNDER_TEST
90 global TOOL_EXECUTABLE
6d63ea75
LG
91 global gnat_target_current
92
93 set gnat_target_current ""
663230c4
JM
94
95 if { $gnat_initialized == 1 } { return }
96
97 if ![info exists GNAT_UNDER_TEST] then {
98 if [info exists TOOL_EXECUTABLE] {
6d63ea75 99 set GNAT_UNDER_TEST "$TOOL_EXECUTABLE"
663230c4 100 } else {
6d63ea75 101 set GNAT_UNDER_TEST "[local_find_gnatmake]"
663230c4
JM
102 }
103 }
104
105 if ![info exists tmpdir] then {
106 set tmpdir /tmp
107 }
663230c4
JM
108}
109
110proc gnat_target_compile { source dest type options } {
111 global rootme
112 global tmpdir
113 global gluefile wrap_flags
114 global srcdir
115 global GNAT_UNDER_TEST
116 global TOOL_OPTIONS
6d63ea75
LG
117 global gnat_target_current
118
3ffcc54f
RO
119 # dg-require-effective-target tests must be compiled as C.
120 if [ string match "*.c" $source ] then {
121 return [gcc_target_compile $source $dest $type $options]
122 }
123
576e4d82
RO
124 # If we detect a change of target, we need to recompute both
125 # GNAT_UNDER_TEST and the appropriate RTS.
6d63ea75
LG
126 if { $gnat_target_current!="[current_target_name]" } {
127 set gnat_target_current "[current_target_name]"
128 if [info exists TOOL_OPTIONS] {
576e4d82 129 set rtsdir "[get_multilibs ${TOOL_OPTIONS}]/libada"
6d63ea75 130 } else {
576e4d82 131 set rtsdir "[get_multilibs]/libada"
6d63ea75 132 }
576e4d82
RO
133 if [info exists TOOL_EXECUTABLE] {
134 set GNAT_UNDER_TEST "$TOOL_EXECUTABLE"
135 } else {
136 set GNAT_UNDER_TEST "[local_find_gnatmake]"
137 }
138 set GNAT_UNDER_TEST "$GNAT_UNDER_TEST --RTS=$rtsdir"
139
140 # gnatlink looks for system.ads itself and has no --RTS option, so
141 # specify via environment
142 setenv ADA_INCLUDE_PATH "$rtsdir/adainclude"
143 setenv ADA_OBJECTS_PATH "$rtsdir/adainclude"
6bad16bb
RO
144 # Always log so compilations can be repeated manually.
145 verbose -log "ADA_INCLUDE_PATH=$rtsdir/adainclude"
146 verbose -log "ADA_OBJECTS_PATH=$rtsdir/adainclude"
6d63ea75 147 }
663230c4 148
0028647e 149 lappend options "compiler=$GNAT_UNDER_TEST -q -f"
32ab0ba4 150 lappend options "timeout=[timeout_value]"
663230c4
JM
151
152 if { [target_info needs_status_wrapper]!="" && [info exists gluefile] } {
153 lappend options "libs=${gluefile}"
154 lappend options "ldflags=$wrap_flags"
155 }
156
157 # TOOL_OPTIONS must come first, so that it doesn't override testcase
158 # specific options.
159 if [info exists TOOL_OPTIONS] {
160 set options [concat "additional_flags=$TOOL_OPTIONS" $options]
161 }
162
663230c4
JM
163 return [target_compile $source $dest $type $options]
164}
165
663230c4
JM
166# Prune messages from GNAT that aren't useful.
167
168proc prune_gnat_output { text } {
169 #send_user "Before:$text\n"
170 regsub -all "(^|\n)\[^\n\]*: In (function|method) \[^\n\]*" $text "" text
171 regsub -all "(^|\n)\[^\n\]*: At top level:\[^\n\]*" $text "" text
172
173 # prune the output from gnatmake.
174 regsub -all "(^|\n)\[^\n\]*gnatmake: [^\n\]*" $text "" text
175
176 # It would be nice to avoid passing anything to gnat that would cause it to
177 # issue these messages (since ignoring them seems like a hack on our part),
178 # but that's too difficult in the general case. For example, sometimes
179 # you need to use -B to point gnat at crt0.o, but there are some targets
180 # that don't have crt0.o.
181 regsub -all "(^|\n)\[^\n\]*file path prefix \[^\n\]* never used" $text "" text
182 regsub -all "(^|\n)\[^\n\]*linker input file unused since linking not done" $text "" text
183
184 #send_user "After:$text\n"
185
186 return $text
187}
188
6d63ea75
LG
189# find_gnatmake for some version of DejaGnu will hardcode a -I...rts/ada flag
190# which prevent multilib from working, so define a new one.
663230c4 191
6d63ea75
LG
192proc local_find_gnatmake {} {
193 global tool_root_dir
743e3e4c 194
6d63ea75
LG
195 if ![is_remote host] {
196 set file [lookfor_file $tool_root_dir gnatmake]
197 if { $file == "" } {
6bad16bb 198 set file [lookfor_file $tool_root_dir gcc/gnatmake]
6d63ea75
LG
199 }
200 if { $file != "" } {
6bad16bb
RO
201 set root [file dirname $file]
202 # Need to pass full --GCC, including multilib flags, to gnatlink,
203 # otherwise gcc from PATH is invoked.
204 set dest [target_info name]
205 set gnatlink_gcc "--GCC=$root/xgcc -B$root [board_info $dest multilib_flags]"
206 # Escape blanks to get them through DejaGnu's exec machinery.
207 regsub -all {\s} "$gnatlink_gcc" {\\&} gnatlink_gcc
208 set CC "$file --GCC=$root/xgcc --GNATBIND=$root/gnatbind --GNATLINK=$root/gnatlink -cargs -B$root -largs $gnatlink_gcc -margs";
6d63ea75 209 } else {
6bad16bb 210 set CC [transform gnatmake]
6d63ea75
LG
211 }
212 } else {
213 set CC [transform gnatmake]
663230c4 214 }
6d63ea75 215 return $CC
663230c4
JM
216}
217
6bad16bb
RO
218proc find_gnatclean {} {
219 global tool_root_dir
663230c4 220
6bad16bb
RO
221 if ![is_remote host] {
222 set file [lookfor_file $tool_root_dir gnatclean]
223 if { $file == "" } {
224 set file [lookfor_file $tool_root_dir gcc/gnatclean]
225 }
226 if { $file != "" } {
227 set gnatclean $file;
228 } else {
229 set gnatclean [transform gnatclean]
230 }
231 } else {
232 set gnatclean [transform gnatclean]
663230c4 233 }
6bad16bb 234 return $gnatclean
663230c4 235}
6bad16bb
RO
236
237# Local Variables:
238# tcl-indent-level:4
239# End: