OSDN Git Service

* config/default.exp, gcc.dg/cpp/cpp.exp, gcc.dg/dg.exp,
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / lib / g++.exp
1 # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 2000, 2001 Free Software Foundation, Inc.
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 2 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 this program; if not, write to the Free Software
15 # Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
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>.
20
21 #
22 # g++ support library routines
23 #
24
25 #
26 # GXX_UNDER_TEST is the compiler under test.
27 #
28
29
30 set gpp_compile_options ""
31
32 #
33 # g++_version -- extract and print the version number of the compiler
34 #
35 proc g++_version { } {
36     global GXX_UNDER_TEST
37     
38     # ignore any arguments after the command
39     set compiler [lindex $GXX_UNDER_TEST 0]
40     
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 {
48             if [is_remote host] {
49                 clone_output "$compiler $version\n"
50             } else {
51                 clone_output "[which $compiler] $version\n"
52             }
53         } else {
54             clone_output "Couldn't determine version of [which $compiler]\n"
55         }
56     } else {
57         # compiler does not exist (this should have already been detected)
58         warning "$compiler does not exist"
59     }
60 }
61
62 #
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
65 #
66 proc g++_include_flags { args } {
67     global srcdir
68     global HAVE_LIBSTDCXX_V3
69
70     set flags ""
71
72     if [is_remote host] {
73       return "${flags}"
74     }
75
76     set dir [lookfor_file ${srcdir} libg++]
77     if { ${dir} != "" } {
78       append flags "-I${dir} -I${dir}/src "
79     }
80
81     set gccpath [get_multilibs]
82
83     if { ${HAVE_LIBSTDCXX_V3} } {
84       set odir_v3 [lookfor_file ${gccpath} libstdc++-v3]
85       set sdir_v3 [lookfor_file ${srcdir} libstdc++-v3]
86       append flags [exec sh ${odir_v3}/tests_flags --compiler ${odir_v3} ${sdir_v3}]
87     } else {
88       set odir_v2 [lookfor_file ${gccpath} libstdc++]
89       set sdir_v2 [lookfor_file ${srcdir} libstdc++]
90       append flags "-I${sdir_v2} -I${sdir_v2}/stl "
91     }
92
93     return "$flags"
94 }
95
96 proc g++_link_flags { args } {
97     global rootme
98     global srcdir
99     global ld_library_path
100
101     set gccpath [get_multilibs];
102     set libio_dir ""
103     set flags ""
104     set ld_library_path "."
105
106     if { $gccpath != "" } {
107       if [file exists "${gccpath}/lib/libstdc++.a"] {
108           append ld_library_path ":${gccpath}/lib"
109       }
110       if [file exists "${gccpath}/libg++/libg++.a"] {
111           append flags "-L${gccpath}/libg++ "
112           append ld_library_path ":${gccpath}/libg++"
113       }
114       if [file exists "${gccpath}/libstdc++/libstdc++.a"] {
115           append flags "-L${gccpath}/libstdc++ "
116           append ld_library_path ":${gccpath}/libstdc++"
117       }
118       if [file exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.a"] {
119           append flags " -L${gccpath}/libstdc++-v3/src/.libs "
120           append ld_library_path ":${gccpath}/libstdc++-v3/src/.libs"
121       }
122       if [file exists "${gccpath}/libiberty/libiberty.a"] {
123           append flags "-L${gccpath}/libiberty "
124       }
125       if [file exists "${gccpath}/librx/librx.a"] {
126           append flags "-L${gccpath}/librx "
127       }
128       append ld_library_path ":${rootme}"
129     } else {
130       global tool_root_dir;
131
132       set libgpp [lookfor_file ${tool_root_dir} libg++];
133       if { $libgpp != "" } {
134           append flags "-L${libgpp} ";
135           append ld_library_path ":${libgpp}"
136       }
137       set libstdcpp [lookfor_file ${tool_root_dir} libstdc++];
138       if { $libstdcpp != "" } {
139           append flags "-L${libstdcpp} ";
140           append ld_library_path ":${libstdcpp}"
141       }
142       set libiberty [lookfor_file ${tool_root_dir} libiberty];
143       if { $libiberty != "" } {
144           append flags "-L${libiberty} ";
145       }
146       set librx [lookfor_file ${tool_root_dir} librx];
147       if { $librx != "" } {
148           append flags "-L${librx} ";
149       }
150     }
151     return "$flags"
152 }
153
154 #
155 # g++_init -- called at the start of each subdir of tests
156 #
157
158 proc g++_init { args } {
159     global subdir
160     global gpp_initialized
161     global base_dir
162     global tmpdir
163     global libdir
164     global gluefile wrap_flags;
165     global objdir srcdir
166     global ALWAYS_CXXFLAGS
167     global TOOL_EXECUTABLE TOOL_OPTIONS
168     global GXX_UNDER_TEST
169
170     if ![info exists GXX_UNDER_TEST] then {
171         if [info exists TOOL_EXECUTABLE] {
172             set GXX_UNDER_TEST $TOOL_EXECUTABLE;
173         } else {
174             if [is_remote host] {
175                 set GXX_UNDER_TEST [transform c++]
176             } else {
177                 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++]]]
178             }
179         }
180     }
181
182     # Bleah, nasty. Bad taste.
183     if [ishost "*-dos-*" ] {
184         regsub "c\\+\\+" "$GXX_UNDER_TEST" "gcc" GXX_UNDER_TEST
185     }
186
187     if ![is_remote host] {
188         if { [which $GXX_UNDER_TEST] == 0 } then {
189             perror "GXX_UNDER_TEST ($GXX_UNDER_TEST) does not exist"
190             exit 1
191         }
192     }
193     if ![info exists tmpdir] {
194         set tmpdir "/tmp"
195     }
196
197     if [info exists gluefile] {
198         unset gluefile
199     }
200
201     if { [target_info needs_status_wrapper] != "" } {
202         set gluefile ${tmpdir}/testglue.o;
203         set result [build_wrapper $gluefile];
204         if { $result != "" } {
205             set gluefile [lindex $result 0];
206             set wrap_flags [lindex $result 1];
207         } else {
208             unset gluefile
209         }
210     }
211
212     set ALWAYS_CXXFLAGS ""
213
214     if ![is_remote host] {
215         lappend ALWAYS_CXXFLAGS "additional_flags=[g++_include_flags]";
216         lappend ALWAYS_CXXFLAGS "ldflags=[g++_link_flags]";
217     }
218
219     if [info exists TOOL_OPTIONS] {
220         lappend ALWAYS_CXXFLAGS "additional_flags=$TOOL_OPTIONS";
221     }
222
223     # Make sure that lines are not wrapped.  That can confuse the
224     # error-message parsing machinery.
225     lappend ALWAYS_CXXFLAGS "additional_flags=-fmessage-length=0"
226
227     verbose -log "ALWAYS_CXXFLAGS set to $ALWAYS_CXXFLAGS"
228
229     verbose "g++ is initialized" 3
230 }
231
232
233 proc g++_target_compile { source dest type options } {
234     global tmpdir;
235     global gpp_compile_options
236     global gluefile wrap_flags
237     global ALWAYS_CXXFLAGS;
238     global GXX_UNDER_TEST;
239
240     if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
241         lappend options "libs=${gluefile}"
242         lappend options "ldflags=${wrap_flags}"
243     }
244
245     lappend options "additional_flags=[libio_include_flags]"
246     lappend options "compiler=$GXX_UNDER_TEST";
247
248     set options [concat $gpp_compile_options $options]
249
250     set options [concat "$ALWAYS_CXXFLAGS" $options];
251
252     if { [regexp "(^| )-frepo( |$)" $options] && \
253          [regexp "\.o(|bj)$" $dest] } then {
254         regsub "\.o(|bj)$" $dest ".rpo" rponame
255         exec rm -f $rponame
256     }
257
258     return [target_compile $source $dest $type $options]
259 }
260
261 proc g++_exit { args } {
262     global gluefile;
263
264     if [info exists gluefile] {
265         file_on_build delete $gluefile;
266         unset gluefile;
267     }
268 }
269
270 # If this is an older version of dejagnu (without runtest_file_p),
271 # provide one and assume the old syntax: foo1.exp bar1.c foo2.exp bar2.c.
272 # This can be deleted after the next dejagnu release.
273
274 if { [info procs runtest_file_p] == "" } then {
275     proc runtest_file_p { runtests testcase } {
276         if { $runtests != "" && [regexp "\[.\]\[cC\]" $runtests] } then {
277             if { [lsearch $runtests [file tail $testcase]] >= 0 } then {
278                 return 1
279             } else {
280                 return 0
281             }
282         }
283         return 1
284     }
285 }
286
287 # Provide a definition of this if missing (delete after next dejagnu release).
288
289 if { [info procs prune_warnings] == "" } then {
290     proc prune_warnings { text } {
291         return $text
292     }
293 }
294
295 # On IRIX 6, we have to set variables akin to LD_LIBRARY_PATH, but
296 # called LD_LIBRARYN32_PATH (for the N32 ABI) and LD_LIBRARY64_PATH
297 # (for the 64-bit ABI).  The right way to do this would be to modify
298 # unix.exp -- but that's not an option since it's part of DejaGNU
299 # proper, so we do it here, by trickery.  We really only need to do 
300 # this on IRIX, but it shouldn't hurt to do it anywhere else.
301
302 proc g++_set_ld_library_path { name element op } {
303   setenv LD_LIBRARYN32_PATH [getenv LD_LIBRARY_PATH]
304   setenv LD_LIBRARY64_PATH [getenv LD_LIBRARY_PATH]
305 }
306
307 trace variable env(LD_LIBRARY_PATH) w g++_set_ld_library_path
308
309 # Utility used by mike-g++.exp and old-dejagnu.exp.
310 # Check the compiler(/assembler/linker) output for text indicating that
311 # the testcase should be marked as "unsupported".
312 #
313 # When dealing with a large number of tests, it's difficult to weed out the
314 # ones that are too big for a particular cpu (eg: 16 bit with a small amount
315 # of memory).  There are various ways to deal with this.  Here's one.
316 # Fortunately, all of the cases where this is likely to happen will be using
317 # gld so we can tell what the error text will look like.
318
319 proc ${tool}_check_unsupported_p { output } {
320     if [regexp "(^|\n)\[^\n\]*: region \[^\n\]* is full" $output] {
321         return "memory full"
322     }
323     return ""
324 }
325
326 proc ${tool}_option_help { } {
327     send_user "--additional_options,OPTIONS\t\tUse OPTIONS to compile the testcase files. OPTIONS should be comma-separated."
328 }
329
330 proc ${tool}_option_proc { option } {
331     if [regexp "^--additional_options," $option] {
332         global gpp_compile_options
333         regsub "--additional_options," $option "" option
334         foreach x [split $option ","] {
335             lappend gpp_compile_options "additional_flags=$x"
336         }
337         return 1;
338     } else {
339         return 0
340     }
341 }