Merge from mainline (gomp-merge-2005-02-26).
[official-gcc.git] / gcc / testsuite / lib / gfortran.exp
blob95af06a10d1fcb6ca6d2f35cad81a705d06754df
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
27 load_lib target-libpath.exp
30 # GFORTRAN_UNDER_TEST is the compiler under test.
34 set gpp_compile_options ""
38 # gfortran_version -- extract and print the version number of the compiler
41 proc gfortran_version { } {
42 global GFORTRAN_UNDER_TEST
44 gfortran_init
46 # ignore any arguments after the command
47 set compiler [lindex $GFORTRAN_UNDER_TEST 0]
49 # verify that the compiler exists
50 if { [is_remote host] || [which $compiler] != 0 } then {
51 set tmp [remote_exec host "$compiler -v"]
52 set status [lindex $tmp 0];
53 set output [lindex $tmp 1];
54 regexp " version \[^\n\r\]*" $output version
55 if { $status == 0 && [info exists version] } then {
56 if [is_remote host] {
57 clone_output "$compiler $version\n"
58 } else {
59 clone_output "[which $compiler] $version\n"
61 } else {
62 clone_output "Couldn't determine version of [which $compiler]\n"
64 } else {
65 # compiler does not exist (this should have already been detected)
66 warning "$compiler does not exist"
71 # gfortran_link_flags -- provide new version of gfortran_link_flags
72 # (originally from libgloss.exp) which knows about the gcc tree structure
75 proc gfortran_link_flags { paths } {
76 global rootme
77 global srcdir
78 global ld_library_path
79 global GFORTRAN_UNDER_TEST
81 set gccpath ${paths}
82 set libio_dir ""
83 set flags ""
84 set ld_library_path "."
86 if { $gccpath != "" } {
87 if [file exists "${gccpath}/libgfortran/.libs/libgfortran.a"] {
88 append flags "-L${gccpath}/libgfortran/.libs "
89 append ld_library_path ":${gccpath}/libgfortran/.libs"
91 if [file exists "${gccpath}/libgfortran/libgforbegin.a"] {
92 append flags "-L${gccpath}/libgfortran "
94 if [file exists "${gccpath}/libiberty/libiberty.a"] {
95 append flags "-L${gccpath}/libiberty "
97 append ld_library_path ":${rootme}"
98 set compiler [lindex $GFORTRAN_UNDER_TEST 0]
99 if { [is_remote host] == 0 && [which $compiler] != 0 } {
100 foreach i "[exec $compiler --print-multi-lib]" {
101 set mldir ""
102 regexp -- "\[a-z0-9=/\.-\]*;" $i mldir
103 set mldir [string trimright $mldir "\;@"]
104 if { "$mldir" == "." } {
105 continue
107 if { [llength [glob -nocomplain ${rootme}/${mldir}/libgcc_s*.so.*]] >= 1 } {
108 append ld_library_path ":${rootme}/${mldir}"
114 set_ld_library_path_env_vars
116 return "$flags"
120 # gfortran_init -- called at the start of each subdir of tests
123 proc gfortran_init { args } {
124 global subdir
125 global gpp_initialized
126 global base_dir
127 global tmpdir
128 global libdir
129 global gluefile wrap_flags;
130 global objdir srcdir
131 global ALWAYS_GFORTRANFLAGS
132 global TOOL_EXECUTABLE TOOL_OPTIONS
133 global GFORTRAN_UNDER_TEST
134 global TESTING_IN_BUILD_TREE
136 # We set LC_ALL and LANG to C so that we get the same error messages as expected.
137 setenv LC_ALL C
138 setenv LANG C
140 if ![info exists GFORTRAN_UNDER_TEST] then {
141 if [info exists TOOL_EXECUTABLE] {
142 set GFORTRAN_UNDER_TEST $TOOL_EXECUTABLE;
143 } else {
144 if { [is_remote host] || ! [info exists TESTING_IN_BUILD_TREE] } {
145 set GFORTRAN_UNDER_TEST [transform gfortran]
146 } else {
147 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]]]
152 if ![is_remote host] {
153 if { [which $GFORTRAN_UNDER_TEST] == 0 } then {
154 perror "GFORTRAN_UNDER_TEST ($GFORTRAN_UNDER_TEST) does not exist"
155 exit 1
158 if ![info exists tmpdir] {
159 set tmpdir "/tmp"
162 if [info exists gluefile] {
163 unset gluefile
166 gfortran_maybe_build_wrapper "${tmpdir}/gfortran-testglue.o"
168 set ALWAYS_GFORTRANFLAGS ""
170 if ![is_remote host] {
171 if [info exists TOOL_OPTIONS] {
172 lappend ALWAYS_GFORTRANFLAGS "ldflags=[gfortran_link_flags [get_multilibs ${TOOL_OPTIONS}] ]";
173 } else {
174 lappend ALWAYS_GFORTRANFLAGS "ldflags=[gfortran_link_flags [get_multilibs] ]";
178 if [info exists TOOL_OPTIONS] {
179 lappend ALWAYS_GFORTRANFLAGS "additional_flags=$TOOL_OPTIONS";
182 verbose -log "ALWAYS_GFORTRANFLAGS set to $ALWAYS_GFORTRANFLAGS"
184 verbose "gfortran is initialized" 3
188 # gfortran_target_compile -- compile a source file
191 proc gfortran_target_compile { source dest type options } {
192 global tmpdir;
193 global gluefile wrap_flags
194 global ALWAYS_GFORTRANFLAGS;
195 global GFORTRAN_UNDER_TEST;
197 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
198 lappend options "libs=${gluefile}"
199 lappend options "ldflags=${wrap_flags}"
202 lappend options "compiler=$GFORTRAN_UNDER_TEST";
204 set options [concat "$ALWAYS_GFORTRANFLAGS" $options];
206 return [target_compile $source $dest $type $options]