1 # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 2000, 2001 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 2 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 this program; if not, write to the Free Software
15 # Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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
26 # GXX_UNDER_TEST is the compiler under test.
30 set gpp_compile_options ""
33 # g++_version -- extract and print the version number of the compiler
35 proc g++_version { } {
38 # ignore any arguments after the command
39 set compiler [lindex $GXX_UNDER_TEST 0]
41 # verify that the compiler exists
42 if { [is_remote host] || [which $compiler] != 0 } then {
43 set tmp [remote_exec host "$compiler -v"]
44 set status [lindex $tmp 0];
45 set output [lindex $tmp 1];
46 regexp "version.*$" $output version
47 if { $status == 0 && [info exists version] } then {
49 clone_output "$compiler $version\n"
51 clone_output "[which $compiler] $version\n"
54 clone_output "Couldn't determine version of [which $compiler]\n"
57 # compiler does not exist (this should have already been detected)
58 warning "$compiler does not exist"
63 # provide new versions of g++_include_flags and g++_link_flags (both
64 # originally from libgloss.exp) which know about the new gcc tree structure
66 proc g++_include_flags { args } {
68 global HAVE_LIBSTDCXX_V3
69 global TESTING_IN_BUILD_TREE
73 if { [is_remote host] || ! [info exists TESTING_IN_BUILD_TREE] } {
77 set dir [lookfor_file ${srcdir} libg++]
79 append flags "-I${dir} -I${dir}/src "
82 set gccpath [get_multilibs]
84 if { ${HAVE_LIBSTDCXX_V3} } {
85 set odir_v3 [lookfor_file ${gccpath} libstdc++-v3]
86 set sdir_v3 [lookfor_file ${srcdir} libstdc++-v3]
87 append flags [exec sh ${odir_v3}/tests_flags --compiler ${odir_v3} ${sdir_v3}]
89 set odir_v2 [lookfor_file ${gccpath} libstdc++]
90 set sdir_v2 [lookfor_file ${srcdir} libstdc++]
91 append flags "-I${sdir_v2} -I${sdir_v2}/stl "
97 proc g++_link_flags { args } {
100 global ld_library_path
102 set gccpath [get_multilibs];
105 set ld_library_path "."
107 if { $gccpath != "" } {
108 if [file exists "${gccpath}/lib/libstdc++.a"] {
109 append ld_library_path ":${gccpath}/lib"
111 if [file exists "${gccpath}/libg++/libg++.a"] {
112 append flags "-L${gccpath}/libg++ "
113 append ld_library_path ":${gccpath}/libg++"
115 if [file exists "${gccpath}/libstdc++/libstdc++.a"] {
116 append flags "-L${gccpath}/libstdc++ "
117 append ld_library_path ":${gccpath}/libstdc++"
119 if [file exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.a"] {
120 append flags " -L${gccpath}/libstdc++-v3/src/.libs "
121 append ld_library_path ":${gccpath}/libstdc++-v3/src/.libs"
123 if [file exists "${gccpath}/libiberty/libiberty.a"] {
124 append flags "-L${gccpath}/libiberty "
126 if [file exists "${gccpath}/librx/librx.a"] {
127 append flags "-L${gccpath}/librx "
129 append ld_library_path ":${rootme}"
131 global tool_root_dir;
133 set libgpp [lookfor_file ${tool_root_dir} libg++];
134 if { $libgpp != "" } {
135 append flags "-L${libgpp} ";
136 append ld_library_path ":${libgpp}"
138 set libstdcpp [lookfor_file ${tool_root_dir} libstdc++];
139 if { $libstdcpp != "" } {
140 append flags "-L${libstdcpp} ";
141 append ld_library_path ":${libstdcpp}"
143 set libiberty [lookfor_file ${tool_root_dir} libiberty];
144 if { $libiberty != "" } {
145 append flags "-L${libiberty} ";
147 set librx [lookfor_file ${tool_root_dir} librx];
148 if { $librx != "" } {
149 append flags "-L${librx} ";
156 # g++_init -- called at the start of each subdir of tests
159 proc g++_init { args } {
161 global gpp_initialized
165 global gluefile wrap_flags;
167 global ALWAYS_CXXFLAGS
168 global TOOL_EXECUTABLE TOOL_OPTIONS
169 global GXX_UNDER_TEST
170 global TESTING_IN_BUILD_TREE
172 if ![info exists GXX_UNDER_TEST] then {
173 if [info exists TOOL_EXECUTABLE] {
174 set GXX_UNDER_TEST $TOOL_EXECUTABLE;
176 if { [is_remote host] || ! [info exists TESTING_IN_BUILD_TREE] } {
177 set GXX_UNDER_TEST [transform c++]
179 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++]]]
184 # Bleah, nasty. Bad taste.
185 if [ishost "*-dos-*" ] {
186 regsub "c\\+\\+" "$GXX_UNDER_TEST" "gcc" GXX_UNDER_TEST
189 if ![is_remote host] {
190 if { [which $GXX_UNDER_TEST] == 0 } then {
191 perror "GXX_UNDER_TEST ($GXX_UNDER_TEST) does not exist"
195 if ![info exists tmpdir] {
199 if [info exists gluefile] {
203 if { [target_info needs_status_wrapper] != "" } {
204 set gluefile ${tmpdir}/testglue.o;
205 set result [build_wrapper $gluefile];
206 if { $result != "" } {
207 set gluefile [lindex $result 0];
208 set wrap_flags [lindex $result 1];
214 set ALWAYS_CXXFLAGS ""
216 if ![is_remote host] {
217 lappend ALWAYS_CXXFLAGS "additional_flags=[g++_include_flags]";
218 lappend ALWAYS_CXXFLAGS "ldflags=[g++_link_flags]";
221 if [info exists TOOL_OPTIONS] {
222 lappend ALWAYS_CXXFLAGS "additional_flags=$TOOL_OPTIONS";
225 # Make sure that lines are not wrapped. That can confuse the
226 # error-message parsing machinery.
227 lappend ALWAYS_CXXFLAGS "additional_flags=-fmessage-length=0"
229 verbose -log "ALWAYS_CXXFLAGS set to $ALWAYS_CXXFLAGS"
231 verbose "g++ is initialized" 3
235 proc g++_target_compile { source dest type options } {
237 global gpp_compile_options
238 global gluefile wrap_flags
239 global ALWAYS_CXXFLAGS;
240 global GXX_UNDER_TEST;
242 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
243 lappend options "libs=${gluefile}"
244 lappend options "ldflags=${wrap_flags}"
247 lappend options "additional_flags=[libio_include_flags]"
248 lappend options "compiler=$GXX_UNDER_TEST";
250 set options [concat $gpp_compile_options $options]
252 set options [concat "$ALWAYS_CXXFLAGS" $options];
254 if { [regexp "(^| )-frepo( |$)" $options] && \
255 [regexp "\.o(|bj)$" $dest] } then {
256 regsub "\.o(|bj)$" $dest ".rpo" rponame
260 return [target_compile $source $dest $type $options]
263 proc g++_exit { args } {
266 if [info exists gluefile] {
267 file_on_build delete $gluefile;
272 # If this is an older version of dejagnu (without runtest_file_p),
273 # provide one and assume the old syntax: foo1.exp bar1.c foo2.exp bar2.c.
274 # This can be deleted after the next dejagnu release.
276 if { [info procs runtest_file_p] == "" } then {
277 proc runtest_file_p { runtests testcase } {
278 if { $runtests != "" && [regexp "\[.\]\[cC\]" $runtests] } then {
279 if { [lsearch $runtests [file tail $testcase]] >= 0 } then {
289 # Provide a definition of this if missing (delete after next dejagnu release).
291 if { [info procs prune_warnings] == "" } then {
292 proc prune_warnings { text } {
297 # On IRIX 6, we have to set variables akin to LD_LIBRARY_PATH, but
298 # called LD_LIBRARYN32_PATH (for the N32 ABI) and LD_LIBRARY64_PATH
299 # (for the 64-bit ABI). The right way to do this would be to modify
300 # unix.exp -- but that's not an option since it's part of DejaGNU
301 # proper, so we do it here, by trickery. We really only need to do
302 # this on IRIX, but it shouldn't hurt to do it anywhere else.
304 proc g++_set_ld_library_path { name element op } {
305 setenv LD_LIBRARYN32_PATH [getenv LD_LIBRARY_PATH]
306 setenv LD_LIBRARY64_PATH [getenv LD_LIBRARY_PATH]
309 trace variable env(LD_LIBRARY_PATH) w g++_set_ld_library_path
311 # Utility used by mike-g++.exp and old-dejagnu.exp.
312 # Check the compiler(/assembler/linker) output for text indicating that
313 # the testcase should be marked as "unsupported".
315 # When dealing with a large number of tests, it's difficult to weed out the
316 # ones that are too big for a particular cpu (eg: 16 bit with a small amount
317 # of memory). There are various ways to deal with this. Here's one.
318 # Fortunately, all of the cases where this is likely to happen will be using
319 # gld so we can tell what the error text will look like.
321 proc ${tool}_check_unsupported_p { output } {
322 if [regexp "(^|\n)\[^\n\]*: region \[^\n\]* is full" $output] {
328 proc ${tool}_option_help { } {
329 send_user "--additional_options,OPTIONS\t\tUse OPTIONS to compile the testcase files. OPTIONS should be comma-separated."
332 proc ${tool}_option_proc { option } {
333 if [regexp "^--additional_options," $option] {
334 global gpp_compile_options
335 regsub "--additional_options," $option "" option
336 foreach x [split $option ","] {
337 lappend gpp_compile_options "additional_flags=$x"