Merge from mainline (gomp-merge-2005-02-26).
[official-gcc.git] / gcc / testsuite / lib / g++.exp
blob19c06839fe6749e86780f134c38ec84ee95a49f1
1 # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 2000, 2001, 2002, 2003, 2004
2 # 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.
8 #
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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 rootme
101 global srcdir
102 global ld_library_path
103 global GXX_UNDER_TEST
105 set gccpath ${paths}
106 set libio_dir ""
107 set flags ""
108 set ld_library_path "."
110 if { $gccpath != "" } {
111 if [file exists "${gccpath}/lib/libstdc++.a"] {
112 append ld_library_path ":${gccpath}/lib"
114 if [file exists "${gccpath}/libg++/libg++.a"] {
115 append flags "-L${gccpath}/libg++ "
116 append ld_library_path ":${gccpath}/libg++"
118 if [file exists "${gccpath}/libstdc++/libstdc++.a"] {
119 append flags "-L${gccpath}/libstdc++ "
120 append ld_library_path ":${gccpath}/libstdc++"
122 if [file exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.a"] {
123 append flags " -L${gccpath}/libstdc++-v3/src/.libs "
124 append ld_library_path ":${gccpath}/libstdc++-v3/src/.libs"
126 if [file exists "${gccpath}/libiberty/libiberty.a"] {
127 append flags "-L${gccpath}/libiberty "
129 if [file exists "${gccpath}/librx/librx.a"] {
130 append flags "-L${gccpath}/librx "
132 append ld_library_path ":${rootme}"
133 set compiler [lindex $GXX_UNDER_TEST 0]
134 if { [is_remote host] == 0 && [which $compiler] != 0 } {
135 foreach i "[exec $compiler --print-multi-lib]" {
136 set mldir ""
137 regexp -- "\[a-z0-9=/\.-\]*;" $i mldir
138 set mldir [string trimright $mldir "\;@"]
139 if { "$mldir" == "." } {
140 continue
142 if { [llength [glob -nocomplain ${rootme}/${mldir}/libgcc_s*.so.*]] >= 1 } {
143 append ld_library_path ":${rootme}/${mldir}"
147 } else {
148 global tool_root_dir;
150 set libgpp [lookfor_file ${tool_root_dir} libg++];
151 if { $libgpp != "" } {
152 append flags "-L${libgpp} ";
153 append ld_library_path ":${libgpp}"
155 set libstdcpp [lookfor_file ${tool_root_dir} libstdc++];
156 if { $libstdcpp != "" } {
157 append flags "-L${libstdcpp} ";
158 append ld_library_path ":${libstdcpp}"
160 set libiberty [lookfor_file ${tool_root_dir} libiberty];
161 if { $libiberty != "" } {
162 append flags "-L${libiberty} ";
164 set librx [lookfor_file ${tool_root_dir} librx];
165 if { $librx != "" } {
166 append flags "-L${librx} ";
170 set_ld_library_path_env_vars
172 return "$flags"
176 # g++_init -- called at the start of each subdir of tests
179 proc g++_init { args } {
180 global subdir
181 global gpp_initialized
182 global base_dir
183 global tmpdir
184 global libdir
185 global gluefile wrap_flags;
186 global objdir srcdir
187 global ALWAYS_CXXFLAGS
188 global TOOL_EXECUTABLE TOOL_OPTIONS
189 global GXX_UNDER_TEST
190 global TESTING_IN_BUILD_TREE
191 global target_triplet
193 # We set LC_ALL and LANG to C so that we get the same error messages as expected.
194 setenv LC_ALL C
195 setenv LANG C
197 if ![info exists GXX_UNDER_TEST] then {
198 if [info exists TOOL_EXECUTABLE] {
199 set GXX_UNDER_TEST $TOOL_EXECUTABLE;
200 } else {
201 if { [is_remote host] || ! [info exists TESTING_IN_BUILD_TREE] } {
202 set GXX_UNDER_TEST [transform c++]
203 } else {
204 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++]]]
209 # Bleah, nasty. Bad taste.
210 if [ishost "*-dos-*" ] {
211 regsub "c\\+\\+" "$GXX_UNDER_TEST" "gcc" GXX_UNDER_TEST
214 if ![is_remote host] {
215 if { [which $GXX_UNDER_TEST] == 0 } then {
216 perror "GXX_UNDER_TEST ($GXX_UNDER_TEST) does not exist"
217 exit 1
220 if ![info exists tmpdir] {
221 set tmpdir "/tmp"
224 if [info exists gluefile] {
225 unset gluefile
228 g++_maybe_build_wrapper "${tmpdir}/g++-testglue.o"
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 "powerpc-*-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