Debian Codegraph @

gcc/testsuite/lib/cobol.exp

raw
1 # Copyright (C) 2003-2025 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 3 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 GCC; see the file COPYING3. If not see
15 # <http://www.gnu.org/licenses/>.
16
17 #
18 # cobol support library routines
19 #
20 load_lib prune.exp
21 load_lib gcc-defs.exp
22 load_lib timeout.exp
23 load_lib target-libpath.exp
24 load_lib target-supports.exp
25
26 #
27 # COBOL_UNDER_TEST is the compiler under test.
28 #
29
30
31 set gpp_compile_options ""
32
33
34 #
35 # cobol_version -- extract and print the version number of the compiler
36 #
37
38 proc cobol_version { } {
39 global COBOL_UNDER_TEST
40
41 cobol_init
42
43 # ignore any arguments after the command
44 set compiler [lindex $COBOL_UNDER_TEST 0]
45
46 # verify that the compiler exists
47 if { [is_remote host] || [which $compiler] != 0 } then {
48 set tmp [remote_exec host "$compiler -v"]
49 set status [lindex $tmp 0]
50 set output [lindex $tmp 1]
51 regexp " version \[^\n\r\]*" $output version
52 if { $status == 0 && [info exists version] } then {
53 if [is_remote host] {
54 clone_output "$compiler $version\n"
55 } else {
56 clone_output "[which $compiler] $version\n"
57 }
58 } else {
59 clone_output "Couldn't determine version of [which $compiler]\n"
60 }
61 } else {
62 # compiler does not exist (this should have already been detected)
63 warning "$compiler does not exist"
64 }
65 }
66
67 #
68 # cobol_link_flags -- provide new version of cobol_link_flags
69 # (originally from libgloss.exp) which knows about the gcc tree structure
70 #
71
72 proc cobol_link_flags { paths } {
73 global srcdir
74 global ld_library_path
75 global COBOL_UNDER_TEST
76 global shlib_ext
77 global ENABLE_DARWIN_AT_RPATH
78
79 set gccpath ${paths}
80 set libio_dir ""
81 set flags ""
82 set ld_library_path "."
83 set shlib_ext [get_shlib_extension]
84 verbose "shared lib extension: $shlib_ext"
85
86 # We need to add options to locate libgfortran and the dependent libs
87 # libquadmath (supporting REAL*16) and libatomic (supporting operations
88 # used by coarrays). Usually '-L' options are added to point to the
89 # relevant directories for the uninstalled libraries.
90
91 # In cases where libraries are available as both shared and convenience
92 # some additional checks are made.
93
94 # For some targets -static-xxxx options are handled by specs substitution
95 # and need a '-B' option rather than '-L'. For Darwin, when embedded
96 # runpaths are in use (the default for all versions after macOS 10.11),
97 # '-B' is also needed to provide the runpath.
98 # When '-B' is used, this results in a '-L' for each path that exists (so
99 # that appending a '-L' as well is a needless duplicate). There are also
100 # cases where tools warn for duplicates, leading to spurious fails.
101 # Therefore the objective of the code below is to add just one '-L' or
102 # '-B' for each of the libraries.
103
104 set target_wants_B_option 0
105 if { [istarget *-*-darwin9* ] || [istarget *-*-darwin\[12\]* ] } {
106 set target_wants_B_option 1
107 }
108
109 if { $gccpath != "" } {
110 if [file exists "${gccpath}/libgcobol/libgcobol.spec"] {
111 append flags "-B${gccpath}/libgcobol "
112 }
113 if [file exists "${gccpath}/libgcobol/libgcobol.a"] {
114 append flags "-L${gccpath}/libgcobol "
115 }
116 if { [file exists "${gccpath}/libgcobol/.libs/libgcobol.a"] ||
117 [file exists "${gccpath}/libgobol/.libs/libgcobol.${shlib_ext}"] } {
118 if { $target_wants_B_option } {
119 append flags "-B${gccpath}/libgcobol/.libs "
120 } else {
121 append flags "-L${gccpath}/libgcobol/.libs "
122 }
123 append ld_library_path ":${gccpath}/libgcobol/.libs"
124 }
125 if { [file exists "${gccpath}/libquadmath/.libs/libquadmath.a"] ||
126 [file exists "${gccpath}/libquadmath/.libs/libquadmath.${shlib_ext}"] } {
127 if { $target_wants_B_option } {
128 append flags "-B${gccpath}/libquadmath/.libs "
129 } else {
130 append flags "-L${gccpath}/libquadmath/.libs "
131 }
132 append ld_library_path ":${gccpath}/libquadmath/.libs"
133 }
134 if { [file exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.a"] ||
135 [file exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.${shlib_ext}"] } {
136 if { $target_wants_B_option } {
137 append flags "-B${gccpath}/libstdc++-v3/src/.libs "
138 } else {
139 append flags "-L${gccpath}/libstdc++-v3/src/.libs "
140 }
141 append ld_library_path ":${gccpath}/libstdc++-v3/src/.libs"
142 }
143
144 if [file exists "${gccpath}/libiberty/libiberty.a"] {
145 append flags "-L${gccpath}/libiberty "
146 }
147 append ld_library_path \
148 [gcc-set-multilib-library-path $COBOL_UNDER_TEST ]
149 }
150
151 set_ld_library_path_env_vars
152
153 return "$flags"
154 }
155
156 #
157 # cobol_init -- called at the start of each subdir of tests
158 #
159
160 proc cobol_init { args } {
161 global subdir
162 global gpp_initialized
163 global base_dir
164 global tmpdir
165 global libdir
166 global gluefile wrap_flags
167 global objdir srcdir
168 global ALWAYS_COBOLFLAGS
169 global TOOL_EXECUTABLE TOOL_OPTIONS
170 global COBOL_UNDER_TEST
171 global TESTING_IN_BUILD_TREE
172 global gcc_warning_prefix
173 global gcc_error_prefix
174 global TEST_ALWAYS_FLAGS
175
176 # We set LC_ALL and LANG to C so that we get the same error messages as expected.
177 setenv LC_ALL C
178 setenv LANG C
179
180 set gcc_warning_prefix "\[Ww\]arning:"
181 set gcc_error_prefix "(Fatal )?\[Ee\]rror:"
182
183 # Many hosts now default to a non-ASCII C locale, however, so
184 # they can set a charset encoding here if they need.
185 if { [ishost "*-*-cygwin*"] } {
186 setenv LC_ALL C.ASCII
187 setenv LANG C.ASCII
188 }
189
190 if ![info exists COBOL_UNDER_TEST] then {
191 if [info exists TOOL_EXECUTABLE] {
192 set COBOL_UNDER_TEST $TOOL_EXECUTABLE
193 } else {
194 if { [is_remote host] || ! [info exists TESTING_IN_BUILD_TREE] } {
195 set COBOL_UNDER_TEST [transform gcobol]
196 } else {
197 set COBOL_UNDER_TEST [findfile $base_dir/../../gcobol "$base_dir/../../gcobol -B$base_dir/../../" [findfile $base_dir/gcobol "$base_dir/gcobol -B$base_dir/" [transform gcobol]]]
198 }
199 }
200 }
201
202 if ![is_remote host] {
203 if { [which $COBOL_UNDER_TEST] == 0 } then {
204 perror "COBOL_UNDER_TEST ($COBOL_UNDER_TEST) does not exist"
205 exit 1
206 }
207 }
208 if ![info exists tmpdir] {
209 set tmpdir "/tmp"
210 }
211
212 if [info exists gluefile] {
213 unset gluefile
214 }
215
216 cobol_maybe_build_wrapper "${tmpdir}/cobol-testglue.o"
217
218 set ALWAYS_COBOLFLAGS ""
219
220 # TEST_ALWAYS_FLAGS are flags that should be passed to every
221 # compilation. They are passed first to allow individual
222 # tests to override them.
223 if [info exists TEST_ALWAYS_FLAGS] {
224 lappend ALWAYS_COBOLFLAGS "additional_flags=$TEST_ALWAYS_FLAGS"
225 }
226
227 if ![is_remote host] {
228 if [info exists TOOL_OPTIONS] {
229 lappend ALWAYS_COBOLFLAGS "ldflags=[cobol_link_flags [get_multilibs ${TOOL_OPTIONS}] ]"
230 } else {
231 lappend ALWAYS_COBOLFLAGS "ldflags=[cobol_link_flags [get_multilibs] ]"
232 }
233 }
234
235 if [info exists TOOL_OPTIONS] {
236 lappend ALWAYS_COBOLFLAGS "additional_flags=$TOOL_OPTIONS"
237 }
238
239 verbose -log "ALWAYS_COBOLFLAGS set to $ALWAYS_COBOLFLAGS"
240
241 verbose "cobol is initialized" 3
242 }
243
244 #
245 # cobol_target_compile -- compile a source file
246 #
247
248 proc cobol_target_compile { source dest type options } {
249 global tmpdir
250 global gluefile wrap_flags
251 global ALWAYS_COBOLFLAGS
252 global COBOL_UNDER_TEST
253 global TEST_ALWAYS_FLAGS
254 global flags_to_postpone
255 global board_info
256
257 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
258 lappend options "libs=${gluefile}"
259 lappend options "ldflags=${wrap_flags}"
260 }
261
262 # TEST_ALWAYS_FLAGS are flags that should be passed to every
263 # compilation. They are passed first to allow individual
264 # tests to override them.
265 if [info exists TEST_ALWAYS_FLAGS] {
266 set options [concat "{additional_flags=$TEST_ALWAYS_FLAGS}" $options]
267 }
268
269 # bind_pic_locally adds -fpie/-fPIE flags to flags_to_postpone and it is
270 # appended here to multilib_flags as it can be overridden by the latter
271 # if it was added earlier. After the target_compile, multilib_flags is
272 # restored to its orignal content.
273 set tboard [target_info name]
274 if {[board_info $tboard exists multilib_flags]} {
275 set orig_multilib_flags "[board_info [target_info name] multilib_flags]"
276 append board_info($tboard,multilib_flags) " $flags_to_postpone"
277 }
278
279 lappend options "compiler=$COBOL_UNDER_TEST"
280 lappend options "timeout=[timeout_value]"
281
282 set options [concat "$ALWAYS_COBOLFLAGS" $options]
283 set options [dg-additional-files-options $options $source $dest $type]
284 set return_val [target_compile $source $dest $type $options]
285
286 if {[board_info $tboard exists multilib_flags]} {
287 set board_info($tboard,multilib_flags) $orig_multilib_flags
288 set flags_to_postpone ""
289 }
290
291 return $return_val
292 }