Merge reload-branch up to revision 101000
[official-gcc.git] / gcc / testsuite / lib / gfortran.exp
blob850df4f0f03c40615c6924f37f8d1657f173729e
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 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 \
97 [gcc-set-multilib-library-path $GFORTRAN_UNDER_TEST]
100 set_ld_library_path_env_vars
102 return "$flags"
106 # gfortran_init -- called at the start of each subdir of tests
109 proc gfortran_init { args } {
110 global subdir
111 global gpp_initialized
112 global base_dir
113 global tmpdir
114 global libdir
115 global gluefile wrap_flags
116 global objdir srcdir
117 global ALWAYS_GFORTRANFLAGS
118 global TOOL_EXECUTABLE TOOL_OPTIONS
119 global GFORTRAN_UNDER_TEST
120 global TESTING_IN_BUILD_TREE
122 # We set LC_ALL and LANG to C so that we get the same error messages as expected.
123 setenv LC_ALL C
124 setenv LANG C
126 if ![info exists GFORTRAN_UNDER_TEST] then {
127 if [info exists TOOL_EXECUTABLE] {
128 set GFORTRAN_UNDER_TEST $TOOL_EXECUTABLE
129 } else {
130 if { [is_remote host] || ! [info exists TESTING_IN_BUILD_TREE] } {
131 set GFORTRAN_UNDER_TEST [transform gfortran]
132 } else {
133 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]]]
138 if ![is_remote host] {
139 if { [which $GFORTRAN_UNDER_TEST] == 0 } then {
140 perror "GFORTRAN_UNDER_TEST ($GFORTRAN_UNDER_TEST) does not exist"
141 exit 1
144 if ![info exists tmpdir] {
145 set tmpdir "/tmp"
148 if [info exists gluefile] {
149 unset gluefile
152 gfortran_maybe_build_wrapper "${tmpdir}/gfortran-testglue.o"
154 set ALWAYS_GFORTRANFLAGS ""
156 if ![is_remote host] {
157 if [info exists TOOL_OPTIONS] {
158 lappend ALWAYS_GFORTRANFLAGS "ldflags=[gfortran_link_flags [get_multilibs ${TOOL_OPTIONS}] ]"
159 } else {
160 lappend ALWAYS_GFORTRANFLAGS "ldflags=[gfortran_link_flags [get_multilibs] ]"
164 if [info exists TOOL_OPTIONS] {
165 lappend ALWAYS_GFORTRANFLAGS "additional_flags=$TOOL_OPTIONS"
168 verbose -log "ALWAYS_GFORTRANFLAGS set to $ALWAYS_GFORTRANFLAGS"
170 verbose "gfortran is initialized" 3
174 # gfortran_target_compile -- compile a source file
177 proc gfortran_target_compile { source dest type options } {
178 global tmpdir
179 global gluefile wrap_flags
180 global ALWAYS_GFORTRANFLAGS
181 global GFORTRAN_UNDER_TEST
183 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
184 lappend options "libs=${gluefile}"
185 lappend options "ldflags=${wrap_flags}"
188 lappend options "compiler=$GFORTRAN_UNDER_TEST"
190 set options [concat "$ALWAYS_GFORTRANFLAGS" $options]
191 set options [dg-additional-files-options $options $source]
192 return [target_compile $source $dest $type $options]