* Merge with edge-vector-mergepoint-20040918.
[official-gcc.git] / gcc / testsuite / lib / gfortran.exp
blob07787cc5bcced7cf2fa4262eccabe8c8297d9c86
1 # Copyright (C) 2003, 2004 Free Software Foundation, Inc.
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.
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.
17 # This file is just 'sed -e 's/77/fortran/g' \
18 # -e 's/f2c/gfortran' g77.exp > gfortran.exp'
20 # with some minor modifications to make it work.
23 # gfortran support library routines
25 load_lib prune.exp
26 load_lib gcc-defs.exp
29 # GFORTRAN_UNDER_TEST is the compiler under test.
33 set gpp_compile_options ""
37 # gfortran_version -- extract and print the version number of the compiler
40 proc gfortran_version { } {
41 global GFORTRAN_UNDER_TEST
43 gfortran_init
45 # ignore any arguments after the command
46 set compiler [lindex $GFORTRAN_UNDER_TEST 0]
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"
60 } else {
61 clone_output "Couldn't determine version of [which $compiler]\n"
63 } else {
64 # compiler does not exist (this should have already been detected)
65 warning "$compiler does not exist"
70 # gfortran_link_flags -- provide new version of gfortran_link_flags
71 # (originally from libgloss.exp) which knows about the gcc tree structure
74 proc gfortran_link_flags { paths } {
75 global rootme
76 global srcdir
77 global ld_library_path
78 global GFORTRAN_UNDER_TEST
80 set gccpath ${paths}
81 set libio_dir ""
82 set flags ""
83 set ld_library_path "."
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"
90 if [file exists "${gccpath}/libgfortran/libgforbegin.a"] {
91 append flags "-L${gccpath}/libgfortran "
93 if [file exists "${gccpath}/libiberty/libiberty.a"] {
94 append flags "-L${gccpath}/libiberty "
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
106 if { [llength [glob -nocomplain ${rootme}/${mldir}/libgcc_s*.so.*]] == 1 } {
107 append ld_library_path ":${rootme}/${mldir}"
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)"
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
144 return "$flags"
148 # gfortran_init -- called at the start of each subdir of tests
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
164 if ![info exists GFORTRAN_UNDER_TEST] then {
165 if [info exists TOOL_EXECUTABLE] {
166 set GFORTRAN_UNDER_TEST $TOOL_EXECUTABLE;
167 } else {
168 if { [is_remote host] || ! [info exists TESTING_IN_BUILD_TREE] } {
169 set GFORTRAN_UNDER_TEST [transform gfortran]
170 } else {
171 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 if ![is_remote host] {
177 if { [which $GFORTRAN_UNDER_TEST] == 0 } then {
178 perror "GFORTRAN_UNDER_TEST ($GFORTRAN_UNDER_TEST) does not exist"
179 exit 1
182 if ![info exists tmpdir] {
183 set tmpdir "/tmp"
186 if [info exists gluefile] {
187 unset gluefile
190 gfortran_maybe_build_wrapper "${tmpdir}/gfortran-testglue.o"
192 set ALWAYS_GFORTRANFLAGS ""
194 if ![is_remote host] {
195 if [info exists TOOL_OPTIONS] {
196 lappend ALWAYS_GFORTRANFLAGS "ldflags=[gfortran_link_flags [get_multilibs ${TOOL_OPTIONS}] ]";
197 } else {
198 lappend ALWAYS_GFORTRANFLAGS "ldflags=[gfortran_link_flags [get_multilibs] ]";
202 if [info exists TOOL_OPTIONS] {
203 lappend ALWAYS_GFORTRANFLAGS "additional_flags=$TOOL_OPTIONS";
206 verbose -log "ALWAYS_GFORTRANFLAGS set to $ALWAYS_GFORTRANFLAGS"
208 verbose "gfortran is initialized" 3
212 # gfortran_target_compile -- compile a source file
215 proc gfortran_target_compile { source dest type options } {
216 global tmpdir;
217 global gluefile wrap_flags
218 global ALWAYS_GFORTRANFLAGS;
219 global GFORTRAN_UNDER_TEST;
221 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
222 lappend options "libs=${gluefile}"
223 lappend options "ldflags=${wrap_flags}"
226 lappend options "compiler=$GFORTRAN_UNDER_TEST";
228 set options [concat "$ALWAYS_GFORTRANFLAGS" $options];
230 return [target_compile $source $dest $type $options]