1 # Copyright (C) 2003 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.
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
29 # GFORTRAN_UNDER_TEST is the compiler under test.
33 set gpp_compile_options ""
37 # gfortran_version -- extract and print the version number of the compiler
40 proc gfortran_version { } {
41 global GFORTRAN_UNDER_TEST
45 # ignore any arguments after the command
46 set compiler [lindex $GFORTRAN_UNDER_TEST 0]
48 # verify that the compiler exists
49 if { [is_remote host] || [which $compiler] != 0 } then {
50 set tmp [remote_exec host "$compiler -v"]
51 set status [lindex $tmp 0];
52 set output [lindex $tmp 1];
53 regexp "version.*$" $output version
54 if { $status == 0 && [info exists version] } then {
56 clone_output "$compiler $version\n"
58 clone_output "[which $compiler] $version\n"
61 clone_output "Couldn't determine version of [which $compiler]\n"
64 # compiler does not exist (this should have already been detected)
65 warning "$compiler does not exist"
70 # gfortran_link_flags -- provide new version of gfortran_link_flags
71 # (originally from libgloss.exp) which knows about the gcc tree structure
74 proc gfortran_link_flags { paths } {
77 global ld_library_path
78 global GFORTRAN_UNDER_TEST
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 ":${rootme}"
97 set compiler [lindex $GFORTRAN_UNDER_TEST 0]
98 if { [is_remote host] == 0 && [which $compiler] != 0 } {
99 foreach i "[exec $compiler --print-multi-lib]" {
101 regexp -- "\[a-z0-9=/\.-\]*;" $i mldir
102 set mldir [string trimright $mldir "\;@"]
103 if { "$mldir" == "." } {
106 if { [llength [glob -nocomplain ${rootme}/${mldir}/libgcc_s*.so.*]] == 1 } {
107 append ld_library_path ":${rootme}/${mldir}"
113 # On IRIX 6, we have to set variables akin to LD_LIBRARY_PATH, but
114 # called LD_LIBRARYN32_PATH (for the N32 ABI) and LD_LIBRARY64_PATH
115 # (for the 64-bit ABI). The right way to do this would be to modify
116 # unix.exp -- but that's not an option since it's part of DejaGNU
117 # proper, so we do it here.
118 # The same applies to Darwin (DYLD_LIBRARY_PATH), Solaris 32 bit
119 # (LD_LIBRARY_PATH_32), Solaris 64 bit (LD_LIBRARY_PATH_64), and HP-UX
121 # Doing this does cause trouble when testing cross-compilers.
122 if {![is_remote target]} {
124 if { [info exists env(LD_LIBRARY_PATH)]
125 && $env(LD_LIBRARY_PATH) != "" } {
126 append ld_library_path ":$env(LD_LIBRARY_PATH)";
128 setenv LD_LIBRARY_PATH $ld_library_path
129 setenv SHLIB_PATH $ld_library_path
130 setenv LD_LIBRARYN32_PATH $ld_library_path
131 setenv LD_LIBRARY64_PATH $ld_library_path
132 setenv LD_LIBRARY_PATH_32 $ld_library_path
133 setenv LD_LIBRARY_PATH_64 $ld_library_path
134 setenv DYLD_LIBRARY_PATH $ld_library_path
141 # gfortran_init -- called at the start of each subdir of tests
144 proc gfortran_init { args } {
146 global gpp_initialized
150 global gluefile wrap_flags;
152 global ALWAYS_GFORTRANFLAGS
153 global TOOL_EXECUTABLE TOOL_OPTIONS
154 global GFORTRAN_UNDER_TEST
155 global TESTING_IN_BUILD_TREE
157 if ![info exists GFORTRAN_UNDER_TEST] then {
158 if [info exists TOOL_EXECUTABLE] {
159 set GFORTRAN_UNDER_TEST $TOOL_EXECUTABLE;
161 if { [is_remote host] || ! [info exists TESTING_IN_BUILD_TREE] } {
162 set GFORTRAN_UNDER_TEST [transform gfortran]
164 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]]]
169 if ![is_remote host] {
170 if { [which $GFORTRAN_UNDER_TEST] == 0 } then {
171 perror "GFORTRAN_UNDER_TEST ($GFORTRAN_UNDER_TEST) does not exist"
175 if ![info exists tmpdir] {
179 if [info exists gluefile] {
183 if { [target_info needs_status_wrapper] != "" } {
184 set gluefile ${tmpdir}/gfortran-testglue.o;
185 set result [build_wrapper $gluefile];
186 if { $result != "" } {
187 set gluefile [lindex $result 0];
188 set wrap_flags [lindex $result 1];
194 set ALWAYS_GFORTRANFLAGS ""
196 if ![is_remote host] {
197 if [info exists TOOL_OPTIONS] {
198 lappend ALWAYS_GFORTRANFLAGS "ldflags=[gfortran_link_flags [get_multilibs ${TOOL_OPTIONS}] ]";
200 lappend ALWAYS_GFORTRANFLAGS "ldflags=[gfortran_link_flags [get_multilibs] ]";
204 if [info exists TOOL_OPTIONS] {
205 lappend ALWAYS_GFORTRANFLAGS "additional_flags=$TOOL_OPTIONS";
208 verbose -log "ALWAYS_GFORTRANFLAGS set to $ALWAYS_GFORTRANFLAGS"
210 verbose "gfortran is initialized" 3
214 # gfortran_target_compile -- compile a source file
217 proc gfortran_target_compile { source dest type options } {
219 global gluefile wrap_flags
220 global ALWAYS_GFORTRANFLAGS;
221 global GFORTRAN_UNDER_TEST;
223 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
224 lappend options "libs=${gluefile}"
225 lappend options "ldflags=${wrap_flags}"
228 lappend options "compiler=$GFORTRAN_UNDER_TEST";
230 set options [concat "$ALWAYS_GFORTRANFLAGS" $options];
232 return [target_compile $source $dest $type $options]