]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/testsuite/lib/gnat.exp
Update copyright years.
[thirdparty/gcc.git] / gcc / testsuite / lib / gnat.exp
CommitLineData
8d9254fc 1# Copyright (C) 2006-2020 Free Software Foundation, Inc.
663230c4
JM
2
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
cd976c16 5# the Free Software Foundation; either version 3 of the License, or
663230c4
JM
6# (at your option) any later version.
7#
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.
12#
13# You should have received a copy of the GNU General Public License
cd976c16
NC
14# along with GCC; see the file COPYING3. If not see
15# <http://www.gnu.org/licenses/>.
663230c4
JM
16
17# This file was written by James A. Morrison (ja2morri@uwaterloo.ca)
18# based on gcc.exp written by Rob Savoye (rob@cygnus.com).
19
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.
22
663230c4
JM
23load_lib prune.exp
24load_lib gcc-defs.exp
3ffcc54f 25load_lib gcc.exp
d4038ca2 26load_lib timeout.exp
663230c4
JM
27
28#
29# GNAT_UNDER_TEST is the compiler under test.
30#
31
32#
33# default_gnat_version -- extract and print the version number of the compiler
34#
35
36proc default_gnat_version { } {
37 global GNAT_UNDER_TEST
38
39 gnat_init
40
41 # ignore any arguments after the command
42 set compiler [lindex $GNAT_UNDER_TEST 0]
43
44 if ![is_remote host] {
45 set compiler_name [which $compiler]
46 } else {
47 set compiler_name $compiler
48 }
49
50 # verify that the compiler exists
51 if { $compiler_name != 0 } then {
6bad16bb 52 set tmp [remote_exec host "$compiler --version"]
663230c4
JM
53 set status [lindex $tmp 0]
54 set output [lindex $tmp 1]
6bad16bb 55 regexp "^GNATMAKE (\[^\n\r\]*)" $output verline version
663230c4 56 if { $status == 0 && [info exists version] } then {
6bad16bb
RO
57 # test_summary expects "version" as second field.
58 clone_output "$compiler_name version $version\n"
663230c4
JM
59 } else {
60 clone_output "Couldn't determine version of $compiler_name: $output\n"
61 }
62 } else {
63 # compiler does not exist (this should have already been detected)
64 warning "$compiler does not exist"
65 }
66}
67
663230c4 68#
6bad16bb
RO
69# gnat_version -- Call default_gnat_version, so we can override it if needed.
70#
71
72proc gnat_version { } {
73 default_gnat_version
74}
75
76#
77# gnat_init -- called at the start of each .exp script.
663230c4
JM
78#
79
80set gnat_initialized 0
81
82proc gnat_init { args } {
83 global rootme
84 global tmpdir
85 global libdir
86 global gluefile wrap_flags
87 global gnat_initialized
88 global GNAT_UNDER_TEST
89 global TOOL_EXECUTABLE
6d63ea75
LG
90 global gnat_target_current
91
92 set gnat_target_current ""
663230c4
JM
93
94 if { $gnat_initialized == 1 } { return }
95
96 if ![info exists GNAT_UNDER_TEST] then {
97 if [info exists TOOL_EXECUTABLE] {
6d63ea75 98 set GNAT_UNDER_TEST "$TOOL_EXECUTABLE"
663230c4 99 } else {
6d63ea75 100 set GNAT_UNDER_TEST "[local_find_gnatmake]"
663230c4
JM
101 }
102 }
103
104 if ![info exists tmpdir] then {
105 set tmpdir /tmp
106 }
663230c4
JM
107}
108
109proc gnat_target_compile { source dest type options } {
110 global rootme
111 global tmpdir
112 global gluefile wrap_flags
113 global srcdir
114 global GNAT_UNDER_TEST
115 global TOOL_OPTIONS
6d63ea75 116 global gnat_target_current
c875f596 117 global TEST_ALWAYS_FLAGS
6d63ea75 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
c875f596
DN
157 # TEST_ALWAYS_FLAGS are flags that should be passed to every
158 # compilation. They are passed first to allow individual
159 # tests to override them.
160 if [info exists TEST_ALWAYS_FLAGS] {
161 set options [concat "{additional_flags=$TEST_ALWAYS_FLAGS}" $options]
162 }
163
663230c4
JM
164 # TOOL_OPTIONS must come first, so that it doesn't override testcase
165 # specific options.
166 if [info exists TOOL_OPTIONS] {
167 set options [concat "additional_flags=$TOOL_OPTIONS" $options]
168 }
169
0ca2b1f3
MR
170 set options [concat "{ada}" $options]
171
663230c4
JM
172 return [target_compile $source $dest $type $options]
173}
174
663230c4
JM
175# Prune messages from GNAT that aren't useful.
176
177proc prune_gnat_output { text } {
178 #send_user "Before:$text\n"
179 regsub -all "(^|\n)\[^\n\]*: In (function|method) \[^\n\]*" $text "" text
180 regsub -all "(^|\n)\[^\n\]*: At top level:\[^\n\]*" $text "" text
181
182 # prune the output from gnatmake.
183 regsub -all "(^|\n)\[^\n\]*gnatmake: [^\n\]*" $text "" text
184
185 # It would be nice to avoid passing anything to gnat that would cause it to
186 # issue these messages (since ignoring them seems like a hack on our part),
187 # but that's too difficult in the general case. For example, sometimes
188 # you need to use -B to point gnat at crt0.o, but there are some targets
189 # that don't have crt0.o.
190 regsub -all "(^|\n)\[^\n\]*file path prefix \[^\n\]* never used" $text "" text
191 regsub -all "(^|\n)\[^\n\]*linker input file unused since linking not done" $text "" text
192
193 #send_user "After:$text\n"
194
195 return $text
196}
197
6d63ea75
LG
198# find_gnatmake for some version of DejaGnu will hardcode a -I...rts/ada flag
199# which prevent multilib from working, so define a new one.
663230c4 200
6d63ea75
LG
201proc local_find_gnatmake {} {
202 global tool_root_dir
743e3e4c 203
6d63ea75
LG
204 if ![is_remote host] {
205 set file [lookfor_file $tool_root_dir gnatmake]
206 if { $file == "" } {
6bad16bb 207 set file [lookfor_file $tool_root_dir gcc/gnatmake]
6d63ea75
LG
208 }
209 if { $file != "" } {
6bad16bb
RO
210 set root [file dirname $file]
211 # Need to pass full --GCC, including multilib flags, to gnatlink,
212 # otherwise gcc from PATH is invoked.
213 set dest [target_info name]
214 set gnatlink_gcc "--GCC=$root/xgcc -B$root [board_info $dest multilib_flags]"
215 # Escape blanks to get them through DejaGnu's exec machinery.
216 regsub -all {\s} "$gnatlink_gcc" {\\&} gnatlink_gcc
217 set CC "$file --GCC=$root/xgcc --GNATBIND=$root/gnatbind --GNATLINK=$root/gnatlink -cargs -B$root -largs $gnatlink_gcc -margs";
6d63ea75 218 } else {
6bad16bb 219 set CC [transform gnatmake]
6d63ea75
LG
220 }
221 } else {
222 set CC [transform gnatmake]
663230c4 223 }
6d63ea75 224 return $CC
663230c4
JM
225}
226
6bad16bb
RO
227proc find_gnatclean {} {
228 global tool_root_dir
663230c4 229
6bad16bb
RO
230 if ![is_remote host] {
231 set file [lookfor_file $tool_root_dir gnatclean]
232 if { $file == "" } {
233 set file [lookfor_file $tool_root_dir gcc/gnatclean]
234 }
235 if { $file != "" } {
236 set gnatclean $file;
237 } else {
238 set gnatclean [transform gnatclean]
239 }
240 } else {
241 set gnatclean [transform gnatclean]
663230c4 242 }
6bad16bb 243 return $gnatclean
663230c4 244}
6bad16bb
RO
245
246# Local Variables:
247# tcl-indent-level:4
248# End: