OSDN Git Service

1207d2b572bf64ac6bd8b7722c581b85e18a46e2
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / lib / gfortran.exp
1 # Copyright (C) 2003, 2004 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 \[^\n\r\]*" $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             # If we've already added these directories once, keep the
126             # existing path.
127             if {$ld_library_path == $env(LD_LIBRARY_PATH)
128                 || [string first $ld_library_path: \
129                                  $env(LD_LIBRARY_PATH)] == 0} {
130                 set ld_library_path $env(LD_LIBRARY_PATH)
131             } elseif { $env(LD_LIBRARY_PATH) != "" } {
132                 append ld_library_path ":$env(LD_LIBRARY_PATH)"
133             }
134         }
135         setenv  LD_LIBRARY_PATH     $ld_library_path
136         setenv  SHLIB_PATH          $ld_library_path
137         setenv  LD_LIBRARYN32_PATH  $ld_library_path
138         setenv  LD_LIBRARY64_PATH   $ld_library_path
139         setenv  LD_LIBRARY_PATH_32  $ld_library_path
140         setenv  LD_LIBRARY_PATH_64  $ld_library_path
141         setenv  DYLD_LIBRARY_PATH   $ld_library_path
142     }
143
144     return "$flags"
145 }
146
147 #
148 # gfortran_init -- called at the start of each subdir of tests
149 #
150
151 proc gfortran_init { args } {
152     global subdir
153     global gpp_initialized
154     global base_dir
155     global tmpdir
156     global libdir
157     global gluefile wrap_flags;
158     global objdir srcdir
159     global ALWAYS_GFORTRANFLAGS
160     global TOOL_EXECUTABLE TOOL_OPTIONS
161     global GFORTRAN_UNDER_TEST
162     global TESTING_IN_BUILD_TREE
163
164     # We set LC_ALL and LANG to C so that we get the same error messages as expected.
165     setenv LC_ALL C
166     setenv LANG C
167
168     if ![info exists GFORTRAN_UNDER_TEST] then {
169         if [info exists TOOL_EXECUTABLE] {
170             set GFORTRAN_UNDER_TEST $TOOL_EXECUTABLE;
171         } else {
172             if { [is_remote host] || ! [info exists TESTING_IN_BUILD_TREE] } {
173                 set GFORTRAN_UNDER_TEST [transform gfortran]
174             } else {
175                 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]]]
176             }
177         }
178     }
179
180     if ![is_remote host] {
181         if { [which $GFORTRAN_UNDER_TEST] == 0 } then {
182             perror "GFORTRAN_UNDER_TEST ($GFORTRAN_UNDER_TEST) does not exist"
183             exit 1
184         }
185     }
186     if ![info exists tmpdir] {
187         set tmpdir "/tmp"
188     }
189
190     if [info exists gluefile] {
191         unset gluefile
192     }
193
194     gfortran_maybe_build_wrapper "${tmpdir}/gfortran-testglue.o"
195
196     set ALWAYS_GFORTRANFLAGS ""
197
198     if ![is_remote host] {
199         if [info exists TOOL_OPTIONS] {
200             lappend ALWAYS_GFORTRANFLAGS "ldflags=[gfortran_link_flags [get_multilibs ${TOOL_OPTIONS}] ]";
201         } else {
202             lappend ALWAYS_GFORTRANFLAGS "ldflags=[gfortran_link_flags [get_multilibs] ]";
203         }
204     }
205
206     if [info exists TOOL_OPTIONS] {
207         lappend ALWAYS_GFORTRANFLAGS "additional_flags=$TOOL_OPTIONS";
208     }
209
210     verbose -log "ALWAYS_GFORTRANFLAGS set to $ALWAYS_GFORTRANFLAGS"
211
212     verbose "gfortran is initialized" 3
213 }
214
215 #
216 # gfortran_target_compile -- compile a source file
217 #
218
219 proc gfortran_target_compile { source dest type options } {
220     global tmpdir;
221     global gluefile wrap_flags
222     global ALWAYS_GFORTRANFLAGS;
223     global GFORTRAN_UNDER_TEST;
224
225     if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
226         lappend options "libs=${gluefile}"
227         lappend options "ldflags=${wrap_flags}"
228     }
229
230     lappend options "compiler=$GFORTRAN_UNDER_TEST";
231
232     set options [concat "$ALWAYS_GFORTRANFLAGS" $options];
233
234     return [target_compile $source $dest $type $options]
235 }