2015-09-24 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / gcc / testsuite / lib / g++.exp
blobb440dd7f6c8cc269c8e68c24628d4198342b4582
1 # Copyright (C) 1992-2015 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 was written by Rob Savoye (rob@cygnus.com)
18 # Many modifications by Jeffrey Wheat (cassidy@cygnus.com)
19 # With modifications by Mike Stump <mrs@cygnus.com>.
22 # g++ support library routines
24 load_lib prune.exp
25 load_lib gcc-defs.exp
26 load_lib timeout.exp
27 load_lib target-libpath.exp
30 # GXX_UNDER_TEST is the compiler under test.
34 set gpp_compile_options ""
37 # g++_version -- extract and print the version number of the compiler
40 proc g++_version { } {
41 global GXX_UNDER_TEST
43 g++_init
45 # ignore any arguments after the command
46 set compiler [lindex $GXX_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 \[^\n\r\]*" $output version
54 if { $status == 0 && [info exists version] } then {
55 if [is_remote host] {
56 clone_output "$compiler $version\n"
57 } else {
58 clone_output "[which $compiler] $version\n"
60 } else {
61 clone_output "Couldn't determine version of [which $compiler]\n"
63 } else {
64 # compiler does not exist (this should have already been detected)
65 warning "$compiler does not exist"
70 # g++_include_flags -- provide new version of g++_include_flags
71 # (originally from libgloss.exp) which knows about the gcc tree structure
73 proc g++_include_flags { paths } {
74 global srcdir
75 global HAVE_LIBSTDCXX_V3
76 global TESTING_IN_BUILD_TREE
78 set flags ""
80 if { [is_remote host] || ! [info exists TESTING_IN_BUILD_TREE] } {
81 return "${flags}"
84 set gccpath ${paths}
86 set odir [lookfor_file ${gccpath} libstdc++-v3]
87 if { ${odir} != "" } {
88 append flags [exec sh ${odir}/scripts/testsuite_flags --build-includes]
91 return "$flags"
95 # g++_link_flags -- provide new version of g++_link_flags
96 # (originally from libgloss.exp) which knows about the gcc tree structure
99 proc g++_link_flags { paths } {
100 global srcdir
101 global ld_library_path
102 global GXX_UNDER_TEST
103 global shlib_ext
105 set gccpath ${paths}
106 set libio_dir ""
107 set flags ""
108 set ld_library_path "."
110 set shlib_ext [get_shlib_extension]
111 verbose "shared lib extension: $shlib_ext"
113 if { $gccpath != "" } {
114 if [file exists "${gccpath}/lib/libstdc++.a"] {
115 append ld_library_path ":${gccpath}/lib"
117 if [file exists "${gccpath}/libg++/libg++.a"] {
118 append flags "-L${gccpath}/libg++ "
119 append ld_library_path ":${gccpath}/libg++"
121 if [file exists "${gccpath}/libstdc++/libstdc++.a"] {
122 append flags "-L${gccpath}/libstdc++ "
123 append ld_library_path ":${gccpath}/libstdc++"
125 if [file exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.a"] {
126 append flags " -L${gccpath}/libstdc++-v3/src/.libs "
127 # Some targets use libstdc++.a%s in their specs, so they need a
128 # -B option for uninstalled testing.
129 append flags " -B${gccpath}/libstdc++-v3/src/.libs "
130 append ld_library_path ":${gccpath}/libstdc++-v3/src/.libs"
132 # Look for libstdc++.${shlib_ext}.
133 if [file exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.${shlib_ext}"] {
134 append flags " -L${gccpath}/libstdc++-v3/src/.libs "
135 append ld_library_path ":${gccpath}/libstdc++-v3/src/.libs"
138 if [file exists "${gccpath}/libiberty/libiberty.a"] {
139 append flags "-L${gccpath}/libiberty "
141 if [file exists "${gccpath}/librx/librx.a"] {
142 append flags "-L${gccpath}/librx "
144 append ld_library_path [gcc-set-multilib-library-path $GXX_UNDER_TEST]
145 } else {
146 global tool_root_dir
148 set libgpp [lookfor_file ${tool_root_dir} libg++]
149 if { $libgpp != "" } {
150 append flags "-L${libgpp} "
151 append ld_library_path ":${libgpp}"
153 set libstdcpp [lookfor_file ${tool_root_dir} libstdc++]
154 if { $libstdcpp != "" } {
155 append flags "-L${libstdcpp} "
156 append ld_library_path ":${libstdcpp}"
158 set libiberty [lookfor_file ${tool_root_dir} libiberty]
159 if { $libiberty != "" } {
160 append flags "-L${libiberty} "
162 set librx [lookfor_file ${tool_root_dir} librx]
163 if { $librx != "" } {
164 append flags "-L${librx} "
168 set_ld_library_path_env_vars
170 return "$flags"
174 # g++_init -- called at the start of each subdir of tests
177 proc g++_init { args } {
178 global subdir
179 global gpp_initialized
180 global base_dir
181 global tmpdir
182 global libdir
183 global gluefile wrap_flags
184 global objdir srcdir
185 global ALWAYS_CXXFLAGS
186 global CXXFLAGS
187 global TOOL_EXECUTABLE TOOL_OPTIONS
188 global GXX_UNDER_TEST
189 global TESTING_IN_BUILD_TREE
190 global gcc_warning_prefix
191 global gcc_error_prefix
192 global TEST_ALWAYS_FLAGS
194 # We set LC_ALL and LANG to C so that we get the same error messages as expected.
195 setenv LC_ALL C
196 setenv LANG C
198 # Many hosts now default to a non-ASCII C locale, however, so
199 # they can set a charset encoding here if they need.
200 if { [ishost "*-*-cygwin*"] } {
201 setenv LC_ALL C.ASCII
202 setenv LANG C.ASCII
205 if ![info exists GXX_UNDER_TEST] then {
206 if [info exists TOOL_EXECUTABLE] {
207 set GXX_UNDER_TEST $TOOL_EXECUTABLE
208 } else {
209 if { [is_remote host] || ! [info exists TESTING_IN_BUILD_TREE] } {
210 set GXX_UNDER_TEST [transform c++]
211 } else {
212 set GXX_UNDER_TEST [findfile $base_dir/../../xg++ "$base_dir/../../xg++ -B$base_dir/../../" [findfile $base_dir/xg++ "$base_dir/xg++ -B$base_dir/" [transform c++]]]
217 # Bleah, nasty. Bad taste.
218 if [ishost "*-dos-*" ] {
219 regsub "c\\+\\+" "$GXX_UNDER_TEST" "gcc" GXX_UNDER_TEST
222 if ![is_remote host] {
223 if { [which $GXX_UNDER_TEST] == 0 } then {
224 perror "GXX_UNDER_TEST ($GXX_UNDER_TEST) does not exist"
225 exit 1
228 if ![info exists tmpdir] {
229 set tmpdir "/tmp"
232 if [info exists gluefile] {
233 unset gluefile
236 g++_maybe_build_wrapper "${tmpdir}/g++-testglue.o" "-fexceptions"
238 if {![info exists CXXFLAGS]} {
239 set CXXFLAGS ""
242 set ALWAYS_CXXFLAGS ""
244 # TEST_ALWAYS_FLAGS are flags that should be passed to every
245 # compilation command. They are passed first to allow individual
246 # tests to override them.
247 if [info exists TEST_ALWAYS_FLAGS] {
248 lappend ALWAYS_CXXFLAGS "additional_flags=$TEST_ALWAYS_FLAGS"
251 if ![is_remote host] {
252 if [info exists TOOL_OPTIONS] {
253 lappend ALWAYS_CXXFLAGS "additional_flags=[g++_include_flags [get_multilibs ${TOOL_OPTIONS}] ]"
254 lappend ALWAYS_CXXFLAGS "ldflags=[g++_link_flags [get_multilibs ${TOOL_OPTIONS}] ]"
255 } else {
256 lappend ALWAYS_CXXFLAGS "additional_flags=[g++_include_flags [get_multilibs] ]"
257 lappend ALWAYS_CXXFLAGS "ldflags=[g++_link_flags [get_multilibs] ]"
261 if [info exists TOOL_OPTIONS] {
262 lappend ALWAYS_CXXFLAGS "additional_flags=$TOOL_OPTIONS"
265 # Make sure that lines are not wrapped. That can confuse the
266 # error-message parsing machinery.
267 lappend ALWAYS_CXXFLAGS "additional_flags=-fmessage-length=0"
269 set gcc_warning_prefix "warning:"
270 set gcc_error_prefix "(fatal )?error:"
272 if { [istarget *-*-darwin*] } {
273 lappend ALWAYS_CXXFLAGS "ldflags=-multiply_defined suppress"
276 verbose -log "ALWAYS_CXXFLAGS set to $ALWAYS_CXXFLAGS"
278 verbose "g++ is initialized" 3
282 # g++_target_compile -- compile a source file
285 proc g++_target_compile { source dest type options } {
286 global tmpdir
287 global gpp_compile_options
288 global gluefile wrap_flags
289 global ALWAYS_CXXFLAGS
290 global GXX_UNDER_TEST
291 global flags_to_postpone
292 global board_info
294 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
295 lappend options "libs=${gluefile}"
296 lappend options "ldflags=${wrap_flags}"
299 global TEST_EXTRA_LIBS
300 if [info exists TEST_EXTRA_LIBS] {
301 lappend options "ldflags=$TEST_EXTRA_LIBS"
304 lappend options "additional_flags=[libio_include_flags]"
305 lappend options "compiler=$GXX_UNDER_TEST"
306 lappend options "timeout=[timeout_value]"
308 set options [concat $gpp_compile_options $options]
310 set options [concat "$ALWAYS_CXXFLAGS" $options]
312 if { [regexp "(^| )-frepo( |$)" $options] && \
313 [regexp "\.o(|bj)$" $dest] } then {
314 regsub "\.o(|bj)$" $dest ".rpo" rponame
315 exec rm -f $rponame
318 # bind_pic_locally adds -fpie/-fPIE flags to flags_to_postpone and it is
319 # appended here to multilib_flags as it can be overridden by the latter
320 # if it was added earlier. After the target_compile, multilib_flags is
321 # restored to its orignal content.
322 set tboard [target_info name]
323 if {[board_info $tboard exists multilib_flags]} {
324 set orig_multilib_flags "[board_info [target_info name] multilib_flags]"
325 append board_info($tboard,multilib_flags) " $flags_to_postpone"
328 set options [dg-additional-files-options $options $source]
330 set result [target_compile $source $dest $type $options]
332 if {[board_info $tboard exists multilib_flags]} {
333 set board_info($tboard,multilib_flags) $orig_multilib_flags
334 set flags_to_postpone ""
337 return $result
341 # ${tool}_option_help
343 # Changed "additional" to "extra" because runtest.exp treats --a* as --all.
345 # This shouldn't be necessary at all; it should be entirely redundant with
346 # --tool_opts, except that --tool_opts currently breaks multilib: see
347 # http://lists.gnu.org/archive/html/dejagnu/2002-10/msg00007.html
349 proc ${tool}_option_help { } {
350 send_user " --extra_opts,OPTIONS\t\tUse OPTIONS to compile the testcase files. OPTIONS should be comma-separated.\n"
354 # ${tool}_option_proc
357 proc ${tool}_option_proc { option } {
358 if [regexp "^--extra_opts," $option] {
359 global gpp_compile_options
360 regsub "^--extra_opts," $option "" option
361 foreach x [split $option ","] {
362 lappend gpp_compile_options "additional_flags=$x"
364 verbose -log "gpp_compile_options set to $gpp_compile_options"
365 return 1
366 } else {
367 return 0