1 # Copyright (C) 2003-2024 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 3 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 GCC; see the file COPYING3. If not see
15 # <http://www.gnu.org/licenses/>.
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
28 load_lib target-libpath.exp
29 load_lib target-supports.exp
32 # GFORTRAN_UNDER_TEST is the compiler under test.
36 set gpp_compile_options ""
40 # gfortran_version -- extract and print the version number of the compiler
43 proc gfortran_version { } {
44 global GFORTRAN_UNDER_TEST
48 # ignore any arguments after the command
49 set compiler [lindex $GFORTRAN_UNDER_TEST 0]
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 {
59 clone_output "$compiler $version\n"
61 clone_output "[which $compiler] $version\n"
64 clone_output "Couldn't determine version of [which $compiler]\n"
67 # compiler does not exist (this should have already been detected)
68 warning "$compiler does not exist"
73 # gfortran_link_flags -- provide new version of gfortran_link_flags
74 # (originally from libgloss.exp) which knows about the gcc tree structure
77 proc gfortran_link_flags { paths } {
79 global ld_library_path
80 global GFORTRAN_UNDER_TEST
86 set ld_library_path "."
87 set shlib_ext [get_shlib_extension]
88 verbose "shared lib extension: $shlib_ext"
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"
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"
102 if [file exists "${gccpath}/libgfortran/libgforbegin.a"] {
103 append flags "-L${gccpath}/libgfortran "
105 if [file exists "${gccpath}/libatomic/.libs/libatomic.${shlib_ext}"] {
106 append flags "-L${gccpath}/libatomic/.libs "
107 append ld_library_path ":${gccpath}/libatomic/.libs"
109 if [file exists "${gccpath}/libatomic/libatomic.a"] {
110 append flags "-L${gccpath}/libatomic "
112 if [file exists "${gccpath}/libquadmath/.libs/libquadmath.a"] {
113 # Some targets use libquadmath.a%s in their specs, so they need a -B option
114 # for uninstalled testing.
115 append flags "-B${gccpath}/libquadmath/.libs "
116 append flags "-L${gccpath}/libquadmath/.libs "
117 append ld_library_path ":${gccpath}/libquadmath/.libs"
119 if [file exists "${gccpath}/libquadmath/.libs/libquadmath.${shlib_ext}"] {
120 append flags "-L${gccpath}/libquadmath/.libs "
121 append ld_library_path ":${gccpath}/libquadmath/.libs"
123 if [file exists "${gccpath}/libiberty/libiberty.a"] {
124 append flags "-L${gccpath}/libiberty "
126 append ld_library_path \
127 [gcc-set-multilib-library-path $GFORTRAN_UNDER_TEST ]
130 set_ld_library_path_env_vars
136 # gfortran_init -- called at the start of each subdir of tests
139 proc gfortran_init { args } {
141 global gpp_initialized
145 global gluefile wrap_flags
147 global ALWAYS_GFORTRANFLAGS
148 global TOOL_EXECUTABLE TOOL_OPTIONS
149 global GFORTRAN_UNDER_TEST
150 global TESTING_IN_BUILD_TREE
151 global gcc_warning_prefix
152 global gcc_error_prefix
153 global TEST_ALWAYS_FLAGS
154 global gfortran_init_set_GFORTRAN_UNDER_TEST
156 # We set LC_ALL and LANG to C so that we get the same error messages as expected.
160 set gcc_warning_prefix "\[Ww\]arning:"
161 set gcc_error_prefix "(Fatal )?\[Ee\]rror:"
163 # Many hosts now default to a non-ASCII C locale, however, so
164 # they can set a charset encoding here if they need.
165 if { [ishost "*-*-cygwin*"] } {
166 setenv LC_ALL C.ASCII
170 # GFORTRAN_UNDER_TEST as set below contains $specpath, which depends on
171 # the used multilib config. Thus, its value may need to be reset;
172 # that's tracked via gfortran_init_set_GFORTRAN_UNDER_TEST.
173 if { ![info exists GFORTRAN_UNDER_TEST]
174 || [info exists gfortran_init_set_GFORTRAN_UNDER_TEST] } then {
175 if [info exists TOOL_EXECUTABLE] {
176 set GFORTRAN_UNDER_TEST $TOOL_EXECUTABLE
178 if { [is_remote host] || ! [info exists TESTING_IN_BUILD_TREE] } {
179 set GFORTRAN_UNDER_TEST [transform gfortran]
181 if [info exists TOOL_OPTIONS] {
182 set specpath [get_multilibs ${TOOL_OPTIONS}]
184 set specpath [get_multilibs]
186 set gfortran_init_set_GFORTRAN_UNDER_TEST 1
187 set GFORTRAN_UNDER_TEST [findfile $base_dir/../../gfortran "$base_dir/../../gfortran -B$base_dir/../../ -B$specpath/libgfortran/" [findfile $base_dir/gfortran "$base_dir/gfortran -B$base_dir/" [transform gfortran]]]
192 if ![is_remote host] {
193 if { [which $GFORTRAN_UNDER_TEST] == 0 } then {
194 perror "GFORTRAN_UNDER_TEST ($GFORTRAN_UNDER_TEST) does not exist"
198 if ![info exists tmpdir] {
202 if [info exists gluefile] {
206 gfortran_maybe_build_wrapper "${tmpdir}/gfortran-testglue.o"
208 set ALWAYS_GFORTRANFLAGS ""
210 # TEST_ALWAYS_FLAGS are flags that should be passed to every
211 # compilation. They are passed first to allow individual
212 # tests to override them.
213 if [info exists TEST_ALWAYS_FLAGS] {
214 lappend ALWAYS_GFORTRANFLAGS "additional_flags=$TEST_ALWAYS_FLAGS"
217 if ![is_remote host] {
218 if [info exists TOOL_OPTIONS] {
219 lappend ALWAYS_GFORTRANFLAGS "ldflags=[gfortran_link_flags [get_multilibs ${TOOL_OPTIONS}] ]"
221 lappend ALWAYS_GFORTRANFLAGS "ldflags=[gfortran_link_flags [get_multilibs] ]"
225 if [info exists TOOL_OPTIONS] {
226 lappend ALWAYS_GFORTRANFLAGS "additional_flags=$TOOL_OPTIONS"
229 verbose -log "ALWAYS_GFORTRANFLAGS set to $ALWAYS_GFORTRANFLAGS"
231 verbose "gfortran is initialized" 3
235 # gfortran_target_compile -- compile a source file
238 proc gfortran_target_compile { source dest type options } {
240 global gluefile wrap_flags
241 global ALWAYS_GFORTRANFLAGS
242 global GFORTRAN_UNDER_TEST
243 global TEST_ALWAYS_FLAGS
244 global flags_to_postpone
247 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
248 lappend options "libs=${gluefile}"
249 lappend options "ldflags=${wrap_flags}"
252 # TEST_ALWAYS_FLAGS are flags that should be passed to every
253 # compilation. They are passed first to allow individual
254 # tests to override them.
255 if [info exists TEST_ALWAYS_FLAGS] {
256 set options [concat "{additional_flags=$TEST_ALWAYS_FLAGS}" $options]
259 # bind_pic_locally adds -fpie/-fPIE flags to flags_to_postpone and it is
260 # appended here to multilib_flags as it can be overridden by the latter
261 # if it was added earlier. After the target_compile, multilib_flags is
262 # restored to its orignal content.
263 set tboard [target_info name]
264 if {[board_info $tboard exists multilib_flags]} {
265 set orig_multilib_flags "[board_info [target_info name] multilib_flags]"
266 append board_info($tboard,multilib_flags) " $flags_to_postpone"
269 lappend options "compiler=$GFORTRAN_UNDER_TEST"
270 lappend options "timeout=[timeout_value]"
272 set options [concat "$ALWAYS_GFORTRANFLAGS" $options]
273 set options [dg-additional-files-options $options $source]
274 set return_val [target_compile $source $dest $type $options]
276 if {[board_info $tboard exists multilib_flags]} {
277 set board_info($tboard,multilib_flags) $orig_multilib_flags
278 set flags_to_postpone ""