OSDN Git Service

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