OSDN Git Service

b0e66d8d3a81a412ec1dd5b6d77677eff6121543
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / lib / gfortran.exp
1 # Copyright (C) 2003, 2004, 2005, 2007 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 3 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 GCC; see the file COPYING3.  If not see
15 # <http://www.gnu.org/licenses/>.
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 load_lib timeout.exp
28 load_lib target-libpath.exp
29
30 #
31 # GFORTRAN_UNDER_TEST is the compiler under test.
32 #
33
34
35 set gpp_compile_options ""
36
37
38 #
39 # gfortran_version -- extract and print the version number of the compiler
40 #
41
42 proc gfortran_version { } {
43     global GFORTRAN_UNDER_TEST
44     
45     gfortran_init
46
47     # ignore any arguments after the command
48     set compiler [lindex $GFORTRAN_UNDER_TEST 0]
49     
50     # verify that the compiler exists
51     if { [is_remote host] || [which $compiler] != 0 } then {
52         set tmp [remote_exec host "$compiler -v"]
53         set status [lindex $tmp 0]
54         set output [lindex $tmp 1]
55         regexp " version \[^\n\r\]*" $output version
56         if { $status == 0 && [info exists version] } then {
57             if [is_remote host] {
58                 clone_output "$compiler $version\n"
59             } else {
60                 clone_output "[which $compiler] $version\n"
61             }
62         } else {
63             clone_output "Couldn't determine version of [which $compiler]\n"
64         }
65     } else {
66         # compiler does not exist (this should have already been detected)
67         warning "$compiler does not exist"
68     }
69 }
70
71 #
72 # gfortran_link_flags -- provide new version of gfortran_link_flags
73 # (originally from libgloss.exp) which knows about the gcc tree structure
74 #
75
76 proc gfortran_link_flags { paths } {
77     global srcdir
78     global ld_library_path
79     global GFORTRAN_UNDER_TEST
80     global shlib_ext
81
82     set gccpath ${paths}
83     set libio_dir ""
84     set flags ""
85     set ld_library_path "."
86     set shlib_ext [get_shlib_extension]
87     verbose "shared lib extension: $shlib_ext"
88
89     if { $gccpath != "" } {
90       if [file exists "${gccpath}/libgfortran/.libs/libgfortran.a"] {
91           append flags "-L${gccpath}/libgfortran/.libs "
92           append ld_library_path ":${gccpath}/libgfortran/.libs"
93       }
94       if [file exists "${gccpath}/libgfortran/.libs/libgfortran.${shlib_ext}"] {
95           append flags "-L${gccpath}/libgfortran/.libs "
96           append ld_library_path ":${gccpath}/libgfortran/.libs"
97       }
98       if [file exists "${gccpath}/libgfortran/libgforbegin.a"] {
99           append flags "-L${gccpath}/libgfortran "
100       }
101       if [file exists "${gccpath}/libiberty/libiberty.a"] {
102           append flags "-L${gccpath}/libiberty "
103       }
104       append ld_library_path \
105         [gcc-set-multilib-library-path $GFORTRAN_UNDER_TEST]
106     }
107
108     set_ld_library_path_env_vars
109
110     return "$flags"
111 }
112
113 #
114 # gfortran_init -- called at the start of each subdir of tests
115 #
116
117 proc gfortran_init { args } {
118     global subdir
119     global gpp_initialized
120     global base_dir
121     global tmpdir
122     global libdir
123     global gluefile wrap_flags
124     global objdir srcdir
125     global ALWAYS_GFORTRANFLAGS
126     global TOOL_EXECUTABLE TOOL_OPTIONS
127     global GFORTRAN_UNDER_TEST
128     global TESTING_IN_BUILD_TREE
129
130     # We set LC_ALL and LANG to C so that we get the same error messages as expected.
131     setenv LC_ALL C
132     setenv LANG C
133
134     if ![info exists GFORTRAN_UNDER_TEST] then {
135         if [info exists TOOL_EXECUTABLE] {
136             set GFORTRAN_UNDER_TEST $TOOL_EXECUTABLE
137         } else {
138             if { [is_remote host] || ! [info exists TESTING_IN_BUILD_TREE] } {
139                 set GFORTRAN_UNDER_TEST [transform gfortran]
140             } else {
141                 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]]]
142             }
143         }
144     }
145
146     if ![is_remote host] {
147         if { [which $GFORTRAN_UNDER_TEST] == 0 } then {
148             perror "GFORTRAN_UNDER_TEST ($GFORTRAN_UNDER_TEST) does not exist"
149             exit 1
150         }
151     }
152     if ![info exists tmpdir] {
153         set tmpdir "/tmp"
154     }
155
156     if [info exists gluefile] {
157         unset gluefile
158     }
159
160     gfortran_maybe_build_wrapper "${tmpdir}/gfortran-testglue.o"
161
162     set ALWAYS_GFORTRANFLAGS ""
163
164     if ![is_remote host] {
165         if [info exists TOOL_OPTIONS] {
166             lappend ALWAYS_GFORTRANFLAGS "ldflags=[gfortran_link_flags [get_multilibs ${TOOL_OPTIONS}] ]"
167         } else {
168             lappend ALWAYS_GFORTRANFLAGS "ldflags=[gfortran_link_flags [get_multilibs] ]"
169         }
170     }
171
172     if [info exists TOOL_OPTIONS] {
173         lappend ALWAYS_GFORTRANFLAGS "additional_flags=$TOOL_OPTIONS"
174     }
175
176     verbose -log "ALWAYS_GFORTRANFLAGS set to $ALWAYS_GFORTRANFLAGS"
177
178     verbose "gfortran is initialized" 3
179 }
180
181 #
182 # gfortran_target_compile -- compile a source file
183 #
184
185 proc gfortran_target_compile { source dest type options } {
186     global tmpdir
187     global gluefile wrap_flags
188     global ALWAYS_GFORTRANFLAGS
189     global GFORTRAN_UNDER_TEST
190
191     if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
192         lappend options "libs=${gluefile}"
193         lappend options "ldflags=${wrap_flags}"
194     }
195
196     lappend options "compiler=$GFORTRAN_UNDER_TEST"
197     lappend options "timeout=[timeout_value]"
198
199     set options [concat "$ALWAYS_GFORTRANFLAGS" $options]
200     set options [dg-additional-files-options $options $source]
201     return [target_compile $source $dest $type $options]
202 }