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
82 global ENABLE_DARWIN_AT_RPATH
87 set ld_library_path
"."
88 set shlib_ext
[get_shlib_extension
]
89 verbose
"shared lib extension: $shlib_ext"
91 # We need to add options to locate libgfortran and the dependent libs
92 # libquadmath
(supporting REAL
*16) and libatomic
(supporting operations
93 # used by coarrays
). Usually
'-L' options are added to point to the
94 # relevant directories
for the uninstalled libraries.
96 # In cases where libraries are available as both shared and convenience
97 # some additional checks are made.
99 #
For some targets
-static
-xxxx options are handled by specs substitution
100 # and need a
'-B' option rather than
'-L'.
For Darwin
, when embedded
101 # runpaths are in use
(the default
for all versions after macOS
10.11),
102 #
'-B' is also needed to provide the runpath.
103 # When
'-B' is used
, this results in a
'-L' for each path that
exists (so
104 # that appending a
'-L' as well is a needless duplicate
). There are also
105 # cases where tools warn
for duplicates
, leading to spurious fails.
106 # Therefore the objective of the code below is to add just one
'-L' or
107 #
'-B' for each of the libraries.
109 set target_wants_B_option
0
110 if { [istarget
*-*-darwin9
* ] ||
[istarget
*-*-darwin\
[12\
]* ] } {
111 set target_wants_B_option
1
114 if { $gccpath
!= "" } {
115 if [file
exists "${gccpath}/libgfortran/libgforbegin.a"] {
116 append flags
"-L${gccpath}/libgfortran "
118 if { [file
exists "${gccpath}/libgfortran/.libs/libgfortran.a"] ||
119 [file
exists "${gccpath}/libgfortran/.libs/libgfortran.${shlib_ext}"] } {
120 if { $target_wants_B_option
} {
121 append flags
"-B${gccpath}/libgfortran/.libs "
123 append flags
"-L${gccpath}/libgfortran/.libs "
125 append ld_library_path
":${gccpath}/libgfortran/.libs"
128 if { [file
exists "${gccpath}/libatomic/.libs/libatomic.a"] ||
129 [file
exists "${gccpath}/libatomic/.libs/libatomic.${shlib_ext}"] } {
130 if { $target_wants_B_option
} {
131 append flags
"-B${gccpath}/libatomic/.libs "
133 append flags
"-L${gccpath}/libatomic/.libs "
135 append ld_library_path
":${gccpath}/libatomic/.libs"
138 if { [file
exists "${gccpath}/libquadmath/.libs/libquadmath.a"] ||
139 [file
exists "${gccpath}/libquadmath/.libs/libquadmath.${shlib_ext}"] } {
140 if { $target_wants_B_option
} {
141 append flags
"-B${gccpath}/libquadmath/.libs "
143 append flags
"-L${gccpath}/libquadmath/.libs "
145 append ld_library_path
":${gccpath}/libquadmath/.libs"
148 if [file
exists "${gccpath}/libiberty/libiberty.a"] {
149 append flags
"-L${gccpath}/libiberty "
151 append ld_library_path \
152 [gcc
-set-multilib
-library
-path $GFORTRAN_UNDER_TEST
]
155 set_ld_library_path_env_vars
161 # gfortran_init
-- called at the start of each subdir of tests
164 proc gfortran_init
{ args } {
166 global gpp_initialized
170 global gluefile wrap_flags
172 global ALWAYS_GFORTRANFLAGS
173 global TOOL_EXECUTABLE TOOL_OPTIONS
174 global GFORTRAN_UNDER_TEST
175 global TESTING_IN_BUILD_TREE
176 global gcc_warning_prefix
177 global gcc_error_prefix
178 global TEST_ALWAYS_FLAGS
179 global gfortran_init_set_GFORTRAN_UNDER_TEST
181 # We
set LC_ALL and LANG to C so that we
get the same error messages as expected.
185 set gcc_warning_prefix
"\[Ww\]arning:"
186 set gcc_error_prefix
"(Fatal )?\[Ee\]rror:"
188 # Many hosts now default to a non
-ASCII C locale
, however
, so
189 # they can
set a
charset encoding here
if they need.
190 if { [ishost
"*-*-cygwin*"] } {
191 setenv LC_ALL C.ASCII
195 # GFORTRAN_UNDER_TEST as
set below contains $specpath
, which depends
on
196 # the used multilib config. Thus
, its value may need to be reset
;
197 # that
's tracked via gfortran_init_set_GFORTRAN_UNDER_TEST.
198 if { ![info exists GFORTRAN_UNDER_TEST]
199 || [info exists gfortran_init_set_GFORTRAN_UNDER_TEST] } then {
200 if [info exists TOOL_EXECUTABLE] {
201 set GFORTRAN_UNDER_TEST $TOOL_EXECUTABLE
203 if { [is_remote host] || ! [info exists TESTING_IN_BUILD_TREE] } {
204 set GFORTRAN_UNDER_TEST [transform gfortran]
206 if [info exists TOOL_OPTIONS] {
207 set specpath [get_multilibs ${TOOL_OPTIONS}]
209 set specpath [get_multilibs]
211 set gfortran_init_set_GFORTRAN_UNDER_TEST 1
212 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]]]
217 if ![is_remote host] {
218 if { [which $GFORTRAN_UNDER_TEST] == 0 } then {
219 perror "GFORTRAN_UNDER_TEST ($GFORTRAN_UNDER_TEST) does not exist"
223 if ![info exists tmpdir] {
227 if [info exists gluefile] {
231 gfortran_maybe_build_wrapper "${tmpdir}/gfortran-testglue.o"
233 set ALWAYS_GFORTRANFLAGS ""
235 # TEST_ALWAYS_FLAGS are flags that should be passed to every
236 # compilation. They are passed first to allow individual
237 # tests to override them.
238 if [info exists TEST_ALWAYS_FLAGS] {
239 lappend ALWAYS_GFORTRANFLAGS "additional_flags=$TEST_ALWAYS_FLAGS"
242 if ![is_remote host] {
243 if [info exists TOOL_OPTIONS] {
244 lappend ALWAYS_GFORTRANFLAGS "ldflags=[gfortran_link_flags [get_multilibs ${TOOL_OPTIONS}] ]"
246 lappend ALWAYS_GFORTRANFLAGS "ldflags=[gfortran_link_flags [get_multilibs] ]"
250 if [info exists TOOL_OPTIONS] {
251 lappend ALWAYS_GFORTRANFLAGS "additional_flags=$TOOL_OPTIONS"
254 verbose -log "ALWAYS_GFORTRANFLAGS set to $ALWAYS_GFORTRANFLAGS"
256 verbose "gfortran is initialized" 3
260 # gfortran_target_compile -- compile a source file
263 proc gfortran_target_compile { source dest type options } {
265 global gluefile wrap_flags
266 global ALWAYS_GFORTRANFLAGS
267 global GFORTRAN_UNDER_TEST
268 global TEST_ALWAYS_FLAGS
269 global flags_to_postpone
272 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
273 lappend options "libs=${gluefile}"
274 lappend options "ldflags=${wrap_flags}"
277 # TEST_ALWAYS_FLAGS are flags that should be passed to every
278 # compilation. They are passed first to allow individual
279 # tests to override them.
280 if [info exists TEST_ALWAYS_FLAGS] {
281 set options [concat "{additional_flags=$TEST_ALWAYS_FLAGS}" $options]
284 # bind_pic_locally adds -fpie/-fPIE flags to flags_to_postpone and it is
285 # appended here to multilib_flags as it can be overridden by the latter
286 # if it was added earlier. After the target_compile, multilib_flags is
287 # restored to its orignal content.
288 set tboard [target_info name]
289 if {[board_info $tboard exists multilib_flags]} {
290 set orig_multilib_flags "[board_info [target_info name] multilib_flags]"
291 append board_info($tboard,multilib_flags) " $flags_to_postpone"
294 lappend options "compiler=$GFORTRAN_UNDER_TEST"
295 lappend options "timeout=[timeout_value]"
297 set options [concat "$ALWAYS_GFORTRANFLAGS" $options]
298 set options [dg-additional-files-options $options $source]
299 set return_val [target_compile $source $dest $type $options]
301 if {[board_info $tboard exists multilib_flags]} {
302 set board_info($tboard,multilib_flags) $orig_multilib_flags
303 set flags_to_postpone ""