]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/testsuite/lib/gdc.exp
Update copyright years.
[thirdparty/gcc.git] / gcc / testsuite / lib / gdc.exp
CommitLineData
fbd26352 1# Copyright (C) 2012-2019 Free Software Foundation, Inc.
03385ed3 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# gdc support library routines
19#
20
21load_lib prune.exp
22load_lib gcc-defs.exp
23load_lib timeout.exp
24load_lib target-libpath.exp
25
26#
27# GDC_UNDER_TEST is the compiler under test.
28#
29
30set gdc_compile_options ""
31
32
33#
34# gdc_version -- extract and print the version number of the compiler
35#
36
37proc gdc_version { } {
38 global GDC_UNDER_TEST
39
40 gdc_init
41
42 # ignore any arguments after the command
43 set compiler [lindex $GDC_UNDER_TEST 0]
44
45 # verify that the compiler exists
46 if { [is_remote host] || [which $compiler] != 0 } then {
47 set tmp [remote_exec host "$compiler -v"]
48 set status [lindex $tmp 0]
49 set output [lindex $tmp 1]
50 regexp " version \[^\n\r\]*" $output version
51 if { $status == 0 && [info exists version] } then {
52 if [is_remote host] {
53 clone_output "$compiler $version\n"
54 } else {
55 clone_output "[which $compiler] $version\n"
56 }
57 } else {
58 clone_output "Couldn't determine version of [which $compiler]\n"
59 }
60 } else {
61 # compiler does not exist (this should have already been detected)
62 warning "$compiler does not exist"
63 }
64}
65
66#
67# gdc_include_flags -- include flags for the gcc tree structure
68#
69
70proc gdc_include_flags { paths } {
71 global srcdir
72 global TESTING_IN_BUILD_TREE
73
74 set flags ""
75
76 if { [is_remote host] || ![info exists TESTING_IN_BUILD_TREE] } {
77 return "${flags}"
78 }
79
80 set gccpath ${paths}
81 set target [file tail [file normalize ${paths}]]
82
83 if { $gccpath != "" } {
84 if [file exists "${gccpath}/libphobos/libdruntime"] {
85 append flags "-I${gccpath}/libphobos/libdruntime "
86 }
87 }
88 append flags "-I${srcdir}/../../libphobos/libdruntime "
89 append flags "-I${srcdir}/../../libphobos/src "
90
91 # For the tests that mix C++ and D, we should try and handle this better.
92 if { $gccpath != "" } {
93 if [file exists "${gccpath}/libstdc++-v3/include"] {
94 append flags "-I${gccpath}/libstdc++-v3/include "
95 append flags "-I${gccpath}/libstdc++-v3/include/$target "
96 }
97 }
98 append flags "-I${srcdir}/../../libstdc++-v3/libsupc++"
99}
100
101#
102# gdc_link_flags -- linker flags for the gcc tree structure
103#
104
105proc gdc_link_flags { paths } {
106 global srcdir
107 global ld_library_path
108 global GDC_UNDER_TEST
109 global shlib_ext
110 global SHARED_OPTION
111
112 set gccpath ${paths}
113 set libio_dir ""
114 set flags ""
115 set ld_library_path "."
116 set shlib_ext [get_shlib_extension]
117 set SHARED_OPTION ""
118 verbose "shared lib extension: $shlib_ext"
119
120 if { $gccpath != "" } {
121 # Path to libgphobos.spec.
122 append flags "-B${gccpath}/libphobos/src "
123
124 if { [file exists "${gccpath}/libphobos/src/.libs/libgphobos.a"] \
125 || [file exists "${gccpath}/libphobos/src/.libs/libgphobos.${shlib_ext}"] } {
126 append flags "-L${gccpath}/libphobos/src/.libs "
127 append ld_library_path ":${gccpath}/libphobos/src/.libs"
128 }
129 if { [file exists "${gccpath}/libphobos/libdruntime/.libs/libgdruntime.a"] \
130 || [file exists "${gccpath}/libphobos/libdruntime/.libs/libgdruntime.${shlib_ext}"] } {
131 append flags "-L${gccpath}/libphobos/libdruntime/.libs "
132 append ld_library_path ":${gccpath}/libphobos/libdruntime/.libs"
133 }
134 # Static linking is default. If only the shared lib is available adjust
135 # flags to always use it. If both are available, set SHARED_OPTION which
136 # will be added to PERMUTE_ARGS
137 if { [file exists "${gccpath}/libphobos/libdruntime/.libs/libgdruntime.${shlib_ext}"] } {
138 if { [file exists "${gccpath}/libphobos/libdruntime/.libs/libgdruntime.a"] } {
139 set SHARED_OPTION "-shared-libphobos"
140 } else {
141 append flags "-shared-libphobos "
142 }
143 }
144 if [file exists "${gccpath}/libiberty/libiberty.a"] {
145 append flags "-L${gccpath}/libiberty "
146 }
147 # For the tests that mix C++ and D, we should try and handle this better.
148 if { [file exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.a"] \
149 || [file exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.${shlib_ext}"] } {
150 append flags "-L${gccpath}/libstdc++-v3/src/.libs "
151 append ld_library_path ":${gccpath}/libstdc++-v3/src/.libs"
152 }
153 append ld_library_path [gcc-set-multilib-library-path $GDC_UNDER_TEST]
154 } else {
155 global tool_root_dir
156
157 set libphobos [lookfor_file ${tool_root_dir} libgphobos]
158 if { $libphobos != "" } {
159 append flags "-B${libphobos} -L${libphobos} "
160 append ld_library_path ":${libphobos}"
161 }
162 set libdruntime [lookfor_file ${tool_root_dir} libgdruntime]
163 if { $libdruntime != "" } {
164 append flags "-L${libdruntime} "
165 append ld_library_path ":${libdruntime}"
166 }
167 set libiberty [lookfor_file ${tool_root_dir} libiberty]
168 if { $libiberty != "" } {
169 append flags "-L${libiberty} "
170 }
171 }
172
173 set_ld_library_path_env_vars
174
175 return "$flags"
176}
177
178#
179# gdc_init -- called at the start of each subdir of tests
180#
181
182proc gdc_init { args } {
183 global subdir
184 global gdc_initialized
185 global base_dir
186 global tmpdir
187 global libdir
188 global gluefile wrap_flags
189 global objdir srcdir
190 global ALWAYS_DFLAGS
191 global TOOL_EXECUTABLE TOOL_OPTIONS
192 global GDC_UNDER_TEST
193 global TESTING_IN_BUILD_TREE
194 global TEST_ALWAYS_FLAGS
195
196 # We set LC_ALL and LANG to C so that we get the same error messages as expected.
197 setenv LC_ALL C
198 setenv LANG C
199
200 if ![info exists GDC_UNDER_TEST] then {
201 if [info exists TOOL_EXECUTABLE] {
202 set GDC_UNDER_TEST $TOOL_EXECUTABLE
203 } else {
204 if { [is_remote host] || ! [info exists TESTING_IN_BUILD_TREE] } {
205 set GDC_UNDER_TEST [transform gdc]
206 } else {
207 set GDC_UNDER_TEST [findfile $base_dir/../../gdc "$base_dir/../../gdc -B$base_dir/../../" [findfile $base_dir/gdc "$base_dir/gdc -B$base_dir/" [transform gdc]]]
208 }
209 }
210 }
211
212 if ![is_remote host] {
213 if { [which $GDC_UNDER_TEST] == 0 } then {
214 perror "GDC_UNDER_TEST ($GDC_UNDER_TEST) does not exist"
215 exit 1
216 }
217 }
218 if ![info exists tmpdir] {
219 set tmpdir "/tmp"
220 }
221
222 if [info exists gluefile] {
223 unset gluefile
224 }
225
226 gdc_maybe_build_wrapper "${tmpdir}/d-testglue.o"
227
228 set ALWAYS_DFLAGS ""
229
230 # TEST_ALWAYS_FLAGS are flags that should be passed to every
231 # compilation. They are passed first to allow individual
232 # tests to override them.
233 if [info exists TEST_ALWAYS_FLAGS] {
234 lappend ALWAYS_DFLAGS "additional_flags=$TEST_ALWAYS_FLAGS"
235 }
236
237 if ![is_remote host] {
238 if [info exists TOOL_OPTIONS] {
239 lappend ALWAYS_DFLAGS "additional_flags=[gdc_include_flags [get_multilibs ${TOOL_OPTIONS}] ]"
240 lappend ALWAYS_DFLAGS "ldflags=[gdc_link_flags [get_multilibs ${TOOL_OPTIONS}] ]"
241 } else {
242 lappend ALWAYS_DFLAGS "additional_flags=[gdc_include_flags [get_multilibs] ]"
243 lappend ALWAYS_DFLAGS "ldflags=[gdc_link_flags [get_multilibs] ]"
244 }
245 }
246
247 if [info exists TOOL_OPTIONS] {
248 lappend ALWAYS_DFLAGS "additional_flags=$TOOL_OPTIONS"
249 }
250
251 verbose -log "ALWAYS_DFLAGS set to $ALWAYS_DFLAGS"
252
253 verbose "gdc is initialized" 3
254}
255
256#
257# gdc_target_compile -- compile a source file
258#
259
260proc gdc_target_compile { source dest type options } {
261 global tmpdir
262 global gluefile wrap_flags
263 global ALWAYS_DFLAGS
264 global GDC_UNDER_TEST
265
266 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
267 lappend options "libs=${gluefile}"
268 lappend options "ldflags=${wrap_flags}"
269 }
270
271 lappend options "timeout=[timeout_value]"
272 lappend options "compiler=$GDC_UNDER_TEST"
273
274 set options [concat "$ALWAYS_DFLAGS" $options]
275 set options [dg-additional-files-options $options $source]
276 return [target_compile $source $dest $type $options]
277}