OSDN Git Service

gcc/testsuite/
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / lib / gfortran.exp
1 # Copyright (C) 2003, 2004, 2005, 2007, 2008, 2009
2 # Free Software Foundation, Inc.
3
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with GCC; see the file COPYING3.  If not see
16 # <http://www.gnu.org/licenses/>.
17
18 # This file is just 'sed -e 's/77/fortran/g' \
19 #                        -e 's/f2c/gfortran' g77.exp > gfortran.exp'
20 #
21 # with some minor modifications to make it work.
22
23 #
24 # gfortran support library routines
25 #
26 load_lib prune.exp
27 load_lib gcc-defs.exp
28 load_lib timeout.exp
29 load_lib target-libpath.exp
30
31 #
32 # GFORTRAN_UNDER_TEST is the compiler under test.
33 #
34
35
36 set gpp_compile_options ""
37
38
39 #
40 # gfortran_version -- extract and print the version number of the compiler
41 #
42
43 proc gfortran_version { } {
44     global GFORTRAN_UNDER_TEST
45     
46     gfortran_init
47
48     # ignore any arguments after the command
49     set compiler [lindex $GFORTRAN_UNDER_TEST 0]
50     
51     # verify that the compiler exists
52     if { [is_remote host] || [which $compiler] != 0 } then {
53         set tmp [remote_exec host "$compiler -v"]
54         set status [lindex $tmp 0]
55         set output [lindex $tmp 1]
56         regexp " version \[^\n\r\]*" $output version
57         if { $status == 0 && [info exists version] } then {
58             if [is_remote host] {
59                 clone_output "$compiler $version\n"
60             } else {
61                 clone_output "[which $compiler] $version\n"
62             }
63         } else {
64             clone_output "Couldn't determine version of [which $compiler]\n"
65         }
66     } else {
67         # compiler does not exist (this should have already been detected)
68         warning "$compiler does not exist"
69     }
70 }
71
72 #
73 # gfortran_link_flags -- provide new version of gfortran_link_flags
74 # (originally from libgloss.exp) which knows about the gcc tree structure
75 #
76
77 proc gfortran_link_flags { paths } {
78     global srcdir
79     global ld_library_path
80     global GFORTRAN_UNDER_TEST
81     global shlib_ext
82
83     set gccpath ${paths}
84     set libio_dir ""
85     set flags ""
86     set ld_library_path "."
87     set shlib_ext [get_shlib_extension]
88     verbose "shared lib extension: $shlib_ext"
89
90     if { $gccpath != "" } {
91       if [file exists "${gccpath}/libgfortran/.libs/libgfortran.a"] {
92           # Some targets use libgfortran.a%s in their specs, so they need a -B option
93           # for uninstalled testing.
94           append flags "-B${gccpath}/libgfortran/.libs "
95           append flags "-L${gccpath}/libgfortran/.libs "
96           append ld_library_path ":${gccpath}/libgfortran/.libs"
97       }
98       if [file exists "${gccpath}/libgfortran/.libs/libgfortran.${shlib_ext}"] {
99           append flags "-L${gccpath}/libgfortran/.libs "
100           append ld_library_path ":${gccpath}/libgfortran/.libs"
101       }
102       if [file exists "${gccpath}/libgfortran/libgforbegin.a"] {
103           append flags "-L${gccpath}/libgfortran "
104       }
105       if [file exists "${gccpath}/libiberty/libiberty.a"] {
106           append flags "-L${gccpath}/libiberty "
107       }
108       append ld_library_path \
109         [gcc-set-multilib-library-path $GFORTRAN_UNDER_TEST]
110     }
111
112     set_ld_library_path_env_vars
113
114     return "$flags"
115 }
116
117 #
118 # gfortran_init -- called at the start of each subdir of tests
119 #
120
121 proc gfortran_init { args } {
122     global subdir
123     global gpp_initialized
124     global base_dir
125     global tmpdir
126     global libdir
127     global gluefile wrap_flags
128     global objdir srcdir
129     global ALWAYS_GFORTRANFLAGS
130     global TOOL_EXECUTABLE TOOL_OPTIONS
131     global GFORTRAN_UNDER_TEST
132     global TESTING_IN_BUILD_TREE
133
134     # We set LC_ALL and LANG to C so that we get the same error messages as expected.
135     setenv LC_ALL C
136     setenv LANG C
137
138     if ![info exists GFORTRAN_UNDER_TEST] then {
139         if [info exists TOOL_EXECUTABLE] {
140             set GFORTRAN_UNDER_TEST $TOOL_EXECUTABLE
141         } else {
142             if { [is_remote host] || ! [info exists TESTING_IN_BUILD_TREE] } {
143                 set GFORTRAN_UNDER_TEST [transform gfortran]
144             } else {
145                 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]]]
146             }
147         }
148     }
149
150     if ![is_remote host] {
151         if { [which $GFORTRAN_UNDER_TEST] == 0 } then {
152             perror "GFORTRAN_UNDER_TEST ($GFORTRAN_UNDER_TEST) does not exist"
153             exit 1
154         }
155     }
156     if ![info exists tmpdir] {
157         set tmpdir "/tmp"
158     }
159
160     if [info exists gluefile] {
161         unset gluefile
162     }
163
164     gfortran_maybe_build_wrapper "${tmpdir}/gfortran-testglue.o"
165
166     set ALWAYS_GFORTRANFLAGS ""
167
168     if ![is_remote host] {
169         if [info exists TOOL_OPTIONS] {
170             lappend ALWAYS_GFORTRANFLAGS "ldflags=[gfortran_link_flags [get_multilibs ${TOOL_OPTIONS}] ]"
171         } else {
172             lappend ALWAYS_GFORTRANFLAGS "ldflags=[gfortran_link_flags [get_multilibs] ]"
173         }
174     }
175
176     if [info exists TOOL_OPTIONS] {
177         lappend ALWAYS_GFORTRANFLAGS "additional_flags=$TOOL_OPTIONS"
178     }
179
180     verbose -log "ALWAYS_GFORTRANFLAGS set to $ALWAYS_GFORTRANFLAGS"
181
182     verbose "gfortran is initialized" 3
183 }
184
185 #
186 # gfortran_target_compile -- compile a source file
187 #
188
189 proc gfortran_target_compile { source dest type options } {
190     global tmpdir
191     global gluefile wrap_flags
192     global ALWAYS_GFORTRANFLAGS
193     global GFORTRAN_UNDER_TEST
194
195     if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
196         lappend options "libs=${gluefile}"
197         lappend options "ldflags=${wrap_flags}"
198     }
199
200     lappend options "compiler=$GFORTRAN_UNDER_TEST"
201     lappend options "timeout=[timeout_value]"
202
203     set options [concat "$ALWAYS_GFORTRANFLAGS" $options]
204     set options [dg-additional-files-options $options $source]
205     return [target_compile $source $dest $type $options]
206 }