1 # Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011
2 # Free Software Foundation, Inc.
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
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
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.
14 # You should have received a copy of the GNU General Public License
15 # along with GCC; see the file COPYING3. If not see
16 # <http://www.gnu.org/licenses/>.
18 # This file was written by James A. Morrison (ja2morri@uwaterloo.ca)
19 # based on gcc.exp written by Rob Savoye (rob@cygnus.com).
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.
30 # GNAT_UNDER_TEST is the compiler under test.
34 # default_gnat_version -- extract and print the version number of the compiler
37 proc default_gnat_version { } {
38 global GNAT_UNDER_TEST
42 # ignore any arguments after the command
43 set compiler [lindex $GNAT_UNDER_TEST 0]
45 if ![is_remote host] {
46 set compiler_name [which $compiler]
48 set compiler_name $compiler
51 # verify that the compiler exists
52 if { $compiler_name != 0 } then {
53 set tmp [remote_exec host "$compiler --version"]
54 set status [lindex $tmp 0]
55 set output [lindex $tmp 1]
56 regexp "^GNATMAKE (\[^\n\r\]*)" $output verline version
57 if { $status == 0 && [info exists version] } then {
58 # test_summary expects "version" as second field.
59 clone_output "$compiler_name version $version\n"
61 clone_output "Couldn't determine version of $compiler_name: $output\n"
64 # compiler does not exist (this should have already been detected)
65 warning "$compiler does not exist"
70 # gnat_version -- Call default_gnat_version, so we can override it if needed.
73 proc gnat_version { } {
78 # gnat_init -- called at the start of each .exp script.
81 set gnat_initialized 0
83 proc gnat_init { args } {
87 global gluefile wrap_flags
88 global gnat_initialized
89 global GNAT_UNDER_TEST
90 global TOOL_EXECUTABLE
91 global gnat_target_current
93 set gnat_target_current ""
95 if { $gnat_initialized == 1 } { return }
97 if ![info exists GNAT_UNDER_TEST] then {
98 if [info exists TOOL_EXECUTABLE] {
99 set GNAT_UNDER_TEST "$TOOL_EXECUTABLE"
101 set GNAT_UNDER_TEST "[local_find_gnatmake]"
105 if ![info exists tmpdir] then {
110 proc gnat_target_compile { source dest type options } {
113 global gluefile wrap_flags
115 global GNAT_UNDER_TEST
117 global gnat_target_current
118 global TEST_ALWAYS_FLAGS
120 # dg-require-effective-target tests must be compiled as C.
121 if [ string match "*.c" $source ] then {
122 return [gcc_target_compile $source $dest $type $options]
125 # If we detect a change of target, we need to recompute both
126 # GNAT_UNDER_TEST and the appropriate RTS.
127 if { $gnat_target_current!="[current_target_name]" } {
128 set gnat_target_current "[current_target_name]"
129 if [info exists TOOL_OPTIONS] {
130 set rtsdir "[get_multilibs ${TOOL_OPTIONS}]/libada"
132 set rtsdir "[get_multilibs]/libada"
134 if [info exists TOOL_EXECUTABLE] {
135 set GNAT_UNDER_TEST "$TOOL_EXECUTABLE"
137 set GNAT_UNDER_TEST "[local_find_gnatmake]"
139 set GNAT_UNDER_TEST "$GNAT_UNDER_TEST --RTS=$rtsdir"
141 # gnatlink looks for system.ads itself and has no --RTS option, so
142 # specify via environment
143 setenv ADA_INCLUDE_PATH "$rtsdir/adainclude"
144 setenv ADA_OBJECTS_PATH "$rtsdir/adainclude"
145 # Always log so compilations can be repeated manually.
146 verbose -log "ADA_INCLUDE_PATH=$rtsdir/adainclude"
147 verbose -log "ADA_OBJECTS_PATH=$rtsdir/adainclude"
150 lappend options "compiler=$GNAT_UNDER_TEST -q -f"
151 lappend options "timeout=[timeout_value]"
153 if { [target_info needs_status_wrapper]!="" && [info exists gluefile] } {
154 lappend options "libs=${gluefile}"
155 lappend options "ldflags=$wrap_flags"
158 # TEST_ALWAYS_FLAGS are flags that should be passed to every
159 # compilation. They are passed first to allow individual
160 # tests to override them.
161 if [info exists TEST_ALWAYS_FLAGS] {
162 set options [concat "{additional_flags=$TEST_ALWAYS_FLAGS}" $options]
165 # TOOL_OPTIONS must come first, so that it doesn't override testcase
167 if [info exists TOOL_OPTIONS] {
168 set options [concat "additional_flags=$TOOL_OPTIONS" $options]
171 return [target_compile $source $dest $type $options]
174 # Prune messages from GNAT that aren't useful.
176 proc prune_gnat_output { text } {
177 #send_user "Before:$text\n"
178 regsub -all "(^|\n)\[^\n\]*: In (function|method) \[^\n\]*" $text "" text
179 regsub -all "(^|\n)\[^\n\]*: At top level:\[^\n\]*" $text "" text
181 # prune the output from gnatmake.
182 regsub -all "(^|\n)\[^\n\]*gnatmake: [^\n\]*" $text "" text
184 # It would be nice to avoid passing anything to gnat that would cause it to
185 # issue these messages (since ignoring them seems like a hack on our part),
186 # but that's too difficult in the general case. For example, sometimes
187 # you need to use -B to point gnat at crt0.o, but there are some targets
188 # that don't have crt0.o.
189 regsub -all "(^|\n)\[^\n\]*file path prefix \[^\n\]* never used" $text "" text
190 regsub -all "(^|\n)\[^\n\]*linker input file unused since linking not done" $text "" text
192 #send_user "After:$text\n"
197 # find_gnatmake for some version of DejaGnu will hardcode a -I...rts/ada flag
198 # which prevent multilib from working, so define a new one.
200 proc local_find_gnatmake {} {
203 if ![is_remote host] {
204 set file [lookfor_file $tool_root_dir gnatmake]
206 set file [lookfor_file $tool_root_dir gcc/gnatmake]
209 set root [file dirname $file]
210 # Need to pass full --GCC, including multilib flags, to gnatlink,
211 # otherwise gcc from PATH is invoked.
212 set dest [target_info name]
213 set gnatlink_gcc "--GCC=$root/xgcc -B$root [board_info $dest multilib_flags]"
214 # Escape blanks to get them through DejaGnu's exec machinery.
215 regsub -all {\s} "$gnatlink_gcc" {\\&} gnatlink_gcc
216 set CC "$file --GCC=$root/xgcc --GNATBIND=$root/gnatbind --GNATLINK=$root/gnatlink -cargs -B$root -largs $gnatlink_gcc -margs";
218 set CC [transform gnatmake]
221 set CC [transform gnatmake]
226 proc find_gnatclean {} {
229 if ![is_remote host] {
230 set file [lookfor_file $tool_root_dir gnatclean]
232 set file [lookfor_file $tool_root_dir gcc/gnatclean]
237 set gnatclean [transform gnatclean]
240 set gnatclean [transform gnatclean]