]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/lib/gfortran.exp
Merge tree-ssa-20020619-branch into mainline.
[thirdparty/gcc.git] / gcc / testsuite / lib / gfortran.exp
1 # Copyright (C) 2003 Free Software Foundation, Inc.
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
5 # the Free Software Foundation; either version 2 of the License, or
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
14 # along with this program; if not, write to the Free Software
15 # Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
17 # This file is just 'sed -e 's/77/fortran/g' \
18 # -e 's/f2c/gfortran' g77.exp > gfortran.exp'
19 #
20 # with some minor modifications to make it work.
21
22 #
23 # gfortran support library routines
24 #
25 load_lib prune.exp
26 load_lib gcc-defs.exp
27
28 #
29 # GFORTRAN_UNDER_TEST is the compiler under test.
30 #
31
32
33 set gpp_compile_options ""
34
35
36 #
37 # gfortran_version -- extract and print the version number of the compiler
38 #
39
40 proc gfortran_version { } {
41 global GFORTRAN_UNDER_TEST
42
43 gfortran_init
44
45 # ignore any arguments after the command
46 set compiler [lindex $GFORTRAN_UNDER_TEST 0]
47
48 # verify that the compiler exists
49 if { [is_remote host] || [which $compiler] != 0 } then {
50 set tmp [remote_exec host "$compiler -v"]
51 set status [lindex $tmp 0];
52 set output [lindex $tmp 1];
53 regexp "version.*$" $output version
54 if { $status == 0 && [info exists version] } then {
55 if [is_remote host] {
56 clone_output "$compiler $version\n"
57 } else {
58 clone_output "[which $compiler] $version\n"
59 }
60 } else {
61 clone_output "Couldn't determine version of [which $compiler]\n"
62 }
63 } else {
64 # compiler does not exist (this should have already been detected)
65 warning "$compiler does not exist"
66 }
67 }
68
69 #
70 # gfortran_link_flags -- provide new version of gfortran_link_flags
71 # (originally from libgloss.exp) which knows about the gcc tree structure
72 #
73
74 proc gfortran_link_flags { paths } {
75 global rootme
76 global srcdir
77 global ld_library_path
78 global GFORTRAN_UNDER_TEST
79
80 set gccpath ${paths}
81 set libio_dir ""
82 set flags ""
83 set ld_library_path "."
84
85 if { $gccpath != "" } {
86 if [file exists "${gccpath}/libgfortran/.libs/libgfortran.a"] {
87 append flags "-L${gccpath}/libgfortran/.libs "
88 append ld_library_path ":${gccpath}/libgfortran/.libs"
89 }
90 if [file exists "${gccpath}/libgfortran/libgforbegin.a"] {
91 append flags "-L${gccpath}/libgfortran "
92 }
93 if [file exists "${gccpath}/libiberty/libiberty.a"] {
94 append flags "-L${gccpath}/libiberty "
95 }
96 append ld_library_path ":${rootme}"
97 set compiler [lindex $GFORTRAN_UNDER_TEST 0]
98 if { [is_remote host] == 0 && [which $compiler] != 0 } {
99 foreach i "[exec $compiler --print-multi-lib]" {
100 set mldir ""
101 regexp -- "\[a-z0-9=/\.-\]*;" $i mldir
102 set mldir [string trimright $mldir "\;@"]
103 if { "$mldir" == "." } {
104 continue
105 }
106 if { [llength [glob -nocomplain ${rootme}/${mldir}/libgcc_s*.so.*]] == 1 } {
107 append ld_library_path ":${rootme}/${mldir}"
108 }
109 }
110 }
111 }
112
113 # On IRIX 6, we have to set variables akin to LD_LIBRARY_PATH, but
114 # called LD_LIBRARYN32_PATH (for the N32 ABI) and LD_LIBRARY64_PATH
115 # (for the 64-bit ABI). The right way to do this would be to modify
116 # unix.exp -- but that's not an option since it's part of DejaGNU
117 # proper, so we do it here.
118 # The same applies to Darwin (DYLD_LIBRARY_PATH), Solaris 32 bit
119 # (LD_LIBRARY_PATH_32), Solaris 64 bit (LD_LIBRARY_PATH_64), and HP-UX
120 # (SHLIB_PATH).
121 # Doing this does cause trouble when testing cross-compilers.
122 if {![is_remote target]} {
123 global env;
124 if { [info exists env(LD_LIBRARY_PATH)]
125 && $env(LD_LIBRARY_PATH) != "" } {
126 append ld_library_path ":$env(LD_LIBRARY_PATH)";
127 }
128 setenv LD_LIBRARY_PATH $ld_library_path
129 setenv SHLIB_PATH $ld_library_path
130 setenv LD_LIBRARYN32_PATH $ld_library_path
131 setenv LD_LIBRARY64_PATH $ld_library_path
132 setenv LD_LIBRARY_PATH_32 $ld_library_path
133 setenv LD_LIBRARY_PATH_64 $ld_library_path
134 setenv DYLD_LIBRARY_PATH $ld_library_path
135 }
136
137 return "$flags"
138 }
139
140 #
141 # gfortran_init -- called at the start of each subdir of tests
142 #
143
144 proc gfortran_init { args } {
145 global subdir
146 global gpp_initialized
147 global base_dir
148 global tmpdir
149 global libdir
150 global gluefile wrap_flags;
151 global objdir srcdir
152 global ALWAYS_GFORTRANFLAGS
153 global TOOL_EXECUTABLE TOOL_OPTIONS
154 global GFORTRAN_UNDER_TEST
155 global TESTING_IN_BUILD_TREE
156
157 if ![info exists GFORTRAN_UNDER_TEST] then {
158 if [info exists TOOL_EXECUTABLE] {
159 set GFORTRAN_UNDER_TEST $TOOL_EXECUTABLE;
160 } else {
161 if { [is_remote host] || ! [info exists TESTING_IN_BUILD_TREE] } {
162 set GFORTRAN_UNDER_TEST [transform gfortran]
163 } else {
164 set GFORTRAN_UNDER_TEST [findfile $base_dir/../gfortran "$base_dir/../gfortran -B$base_dir/../" [findfile $base_dir/gfortran "$base_dir/gfortran -B$base_dir/" [transform gfortran]]]
165 }
166 }
167 }
168
169 if ![is_remote host] {
170 if { [which $GFORTRAN_UNDER_TEST] == 0 } then {
171 perror "GFORTRAN_UNDER_TEST ($GFORTRAN_UNDER_TEST) does not exist"
172 exit 1
173 }
174 }
175 if ![info exists tmpdir] {
176 set tmpdir "/tmp"
177 }
178
179 if [info exists gluefile] {
180 unset gluefile
181 }
182
183 if { [target_info needs_status_wrapper] != "" } {
184 set gluefile ${tmpdir}/gfortran-testglue.o;
185 set result [build_wrapper $gluefile];
186 if { $result != "" } {
187 set gluefile [lindex $result 0];
188 set wrap_flags [lindex $result 1];
189 } else {
190 unset gluefile
191 }
192 }
193
194 set ALWAYS_GFORTRANFLAGS ""
195
196 if ![is_remote host] {
197 if [info exists TOOL_OPTIONS] {
198 lappend ALWAYS_GFORTRANFLAGS "ldflags=[gfortran_link_flags [get_multilibs ${TOOL_OPTIONS}] ]";
199 } else {
200 lappend ALWAYS_GFORTRANFLAGS "ldflags=[gfortran_link_flags [get_multilibs] ]";
201 }
202 }
203
204 if [info exists TOOL_OPTIONS] {
205 lappend ALWAYS_GFORTRANFLAGS "additional_flags=$TOOL_OPTIONS";
206 }
207
208 verbose -log "ALWAYS_GFORTRANFLAGS set to $ALWAYS_GFORTRANFLAGS"
209
210 verbose "gfortran is initialized" 3
211 }
212
213 #
214 # gfortran_target_compile -- compile a source file
215 #
216
217 proc gfortran_target_compile { source dest type options } {
218 global tmpdir;
219 global gluefile wrap_flags
220 global ALWAYS_GFORTRANFLAGS;
221 global GFORTRAN_UNDER_TEST;
222
223 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
224 lappend options "libs=${gluefile}"
225 lappend options "ldflags=${wrap_flags}"
226 }
227
228 lappend options "compiler=$GFORTRAN_UNDER_TEST";
229
230 set options [concat "$ALWAYS_GFORTRANFLAGS" $options];
231
232 return [target_compile $source $dest $type $options]
233 }