Merge from mainline
[official-gcc.git] / gcc / testsuite / lib / g++.exp
blob700cc5819e998c3a8dd075714a2b5e3364e028e0
1 # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 2000, 2001, 2002, 2003,
2 # 2004, 2005 Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 # This file was written by Rob Savoye (rob@cygnus.com)
19 # Many modifications by Jeffrey Wheat (cassidy@cygnus.com)
20 # With modifications by Mike Stump <mrs@cygnus.com>.
23 # g++ support library routines
25 load_lib prune.exp
26 load_lib gcc-defs.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 append ld_library_path ":${gccpath}/libstdc++-v3/src/.libs"
129 # Look for libstdc++.${shlib_ext}.
130 if [file exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.${shlib_ext}"] {
131 append flags " -L${gccpath}/libstdc++-v3/src/.libs "
132 append ld_library_path ":${gccpath}/libstdc++-v3/src/.libs"
135 if [file exists "${gccpath}/libiberty/libiberty.a"] {
136 append flags "-L${gccpath}/libiberty "
138 if [file exists "${gccpath}/librx/librx.a"] {
139 append flags "-L${gccpath}/librx "
141 append ld_library_path [gcc-set-multilib-library-path $GXX_UNDER_TEST]
142 } else {
143 global tool_root_dir
145 set libgpp [lookfor_file ${tool_root_dir} libg++]
146 if { $libgpp != "" } {
147 append flags "-L${libgpp} "
148 append ld_library_path ":${libgpp}"
150 set libstdcpp [lookfor_file ${tool_root_dir} libstdc++]
151 if { $libstdcpp != "" } {
152 append flags "-L${libstdcpp} "
153 append ld_library_path ":${libstdcpp}"
155 set libiberty [lookfor_file ${tool_root_dir} libiberty]
156 if { $libiberty != "" } {
157 append flags "-L${libiberty} "
159 set librx [lookfor_file ${tool_root_dir} librx]
160 if { $librx != "" } {
161 append flags "-L${librx} "
165 set_ld_library_path_env_vars
167 return "$flags"
171 # g++_init -- called at the start of each subdir of tests
174 proc g++_init { args } {
175 global subdir
176 global gpp_initialized
177 global base_dir
178 global tmpdir
179 global libdir
180 global gluefile wrap_flags
181 global objdir srcdir
182 global ALWAYS_CXXFLAGS
183 global CXXFLAGS
184 global TOOL_EXECUTABLE TOOL_OPTIONS
185 global GXX_UNDER_TEST
186 global TESTING_IN_BUILD_TREE
187 global target_triplet
189 # We set LC_ALL and LANG to C so that we get the same error messages as expected.
190 setenv LC_ALL C
191 setenv LANG C
193 if ![info exists GXX_UNDER_TEST] then {
194 if [info exists TOOL_EXECUTABLE] {
195 set GXX_UNDER_TEST $TOOL_EXECUTABLE
196 } else {
197 if { [is_remote host] || ! [info exists TESTING_IN_BUILD_TREE] } {
198 set GXX_UNDER_TEST [transform c++]
199 } else {
200 set GXX_UNDER_TEST [findfile $base_dir/../../g++ "$base_dir/../../g++ -B$base_dir/../../" [findfile $base_dir/g++ "$base_dir/g++ -B$base_dir/" [transform c++]]]
205 # Bleah, nasty. Bad taste.
206 if [ishost "*-dos-*" ] {
207 regsub "c\\+\\+" "$GXX_UNDER_TEST" "gcc" GXX_UNDER_TEST
210 if ![is_remote host] {
211 if { [which $GXX_UNDER_TEST] == 0 } then {
212 perror "GXX_UNDER_TEST ($GXX_UNDER_TEST) does not exist"
213 exit 1
216 if ![info exists tmpdir] {
217 set tmpdir "/tmp"
220 if [info exists gluefile] {
221 unset gluefile
224 g++_maybe_build_wrapper "${tmpdir}/g++-testglue.o"
226 if {![info exists CXXFLAGS]} {
227 set CXXFLAGS ""
230 set ALWAYS_CXXFLAGS ""
232 if ![is_remote host] {
233 if [info exists TOOL_OPTIONS] {
234 lappend ALWAYS_CXXFLAGS "additional_flags=[g++_include_flags [get_multilibs ${TOOL_OPTIONS}] ]"
235 lappend ALWAYS_CXXFLAGS "ldflags=[g++_link_flags [get_multilibs ${TOOL_OPTIONS}] ]"
236 } else {
237 lappend ALWAYS_CXXFLAGS "additional_flags=[g++_include_flags [get_multilibs] ]"
238 lappend ALWAYS_CXXFLAGS "ldflags=[g++_link_flags [get_multilibs] ]"
242 if [info exists TOOL_OPTIONS] {
243 lappend ALWAYS_CXXFLAGS "additional_flags=$TOOL_OPTIONS"
246 # Make sure that lines are not wrapped. That can confuse the
247 # error-message parsing machinery.
248 lappend ALWAYS_CXXFLAGS "additional_flags=-fmessage-length=0"
250 if { [string match "*-*-darwin*" $target_triplet] } {
251 lappend ALWAYS_CXXFLAGS "ldflags=-multiply_defined suppress"
254 verbose -log "ALWAYS_CXXFLAGS set to $ALWAYS_CXXFLAGS"
256 verbose "g++ is initialized" 3
260 # g++_target_compile -- compile a source file
263 proc g++_target_compile { source dest type options } {
264 global tmpdir
265 global gpp_compile_options
266 global gluefile wrap_flags
267 global ALWAYS_CXXFLAGS
268 global GXX_UNDER_TEST
270 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
271 lappend options "libs=${gluefile}"
272 lappend options "ldflags=${wrap_flags}"
275 lappend options "additional_flags=[libio_include_flags]"
276 lappend options "compiler=$GXX_UNDER_TEST"
278 set options [concat $gpp_compile_options $options]
280 set options [concat "$ALWAYS_CXXFLAGS" $options]
282 if { [regexp "(^| )-frepo( |$)" $options] && \
283 [regexp "\.o(|bj)$" $dest] } then {
284 regsub "\.o(|bj)$" $dest ".rpo" rponame
285 exec rm -f $rponame
288 set options [dg-additional-files-options $options $source]
290 set result [target_compile $source $dest $type $options]
292 return $result
296 # ${tool}_option_help
299 proc ${tool}_option_help { } {
300 send_user " --additional_options,OPTIONS\t\tUse OPTIONS to compile the testcase files. OPTIONS should be comma-separated.\n"
304 # ${tool}_option_proc
307 proc ${tool}_option_proc { option } {
308 if [regexp "^--additional_options," $option] {
309 global gpp_compile_options
310 regsub "--additional_options," $option "" option
311 foreach x [split $option ","] {
312 lappend gpp_compile_options "additional_flags=$x"
314 return 1
315 } else {
316 return 0