OSDN Git Service

gcc/testsuite:
[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 load_lib prune.exp
25 load_lib gcc-defs.exp
26
27 #
28 # GXX_UNDER_TEST is the compiler under test.
29 #
30
31
32 set gpp_compile_options ""
33
34
35 #
36 # g++_version -- extract and print the version number of the compiler
37 #
38
39 proc g++_version { } {
40     global GXX_UNDER_TEST
41     
42     g++_init
43
44     # ignore any arguments after the command
45     set compiler [lindex $GXX_UNDER_TEST 0]
46     
47     # verify that the compiler exists
48     if { [is_remote host] || [which $compiler] != 0 } then {
49         set tmp [remote_exec host "$compiler -v"]
50         set status [lindex $tmp 0];
51         set output [lindex $tmp 1];
52         regexp "version.*$" $output version
53         if { $status == 0 && [info exists version] } then {
54             if [is_remote host] {
55                 clone_output "$compiler $version\n"
56             } else {
57                 clone_output "[which $compiler] $version\n"
58             }
59         } else {
60             clone_output "Couldn't determine version of [which $compiler]\n"
61         }
62     } else {
63         # compiler does not exist (this should have already been detected)
64         warning "$compiler does not exist"
65     }
66 }
67
68 #
69 # g++_include_flags -- provide new version of g++_include_flags
70 # (originally from libgloss.exp) which knows about the gcc tree structure
71 #
72 proc g++_include_flags { paths } {
73     global srcdir
74     global HAVE_LIBSTDCXX_V3
75     global TESTING_IN_BUILD_TREE
76
77     set flags ""
78
79     if { [is_remote host] || ! [info exists TESTING_IN_BUILD_TREE] } {
80       return "${flags}"
81     }
82
83     set dir [lookfor_file ${srcdir} libg++]
84     if { ${dir} != "" } {
85       append flags "-I${dir} -I${dir}/src "
86     }
87
88     set gccpath ${paths}
89
90     if { ${HAVE_LIBSTDCXX_V3} } {
91       set odir_v3 [lookfor_file ${gccpath} libstdc++-v3]
92       append flags [exec sh ${odir_v3}/testsuite_flags --build-includes]
93     } else {
94       set odir_v2 [lookfor_file ${gccpath} libstdc++]
95       set sdir_v2 [lookfor_file ${srcdir} libstdc++]
96       append flags "-I${sdir_v2} -I${sdir_v2}/stl "
97     }
98
99     return "$flags"
100 }
101
102 #
103 # g++_link_flags -- provide new version of g++_link_flags
104 # (originally from libgloss.exp) which knows about the gcc tree structure
105 #
106
107 proc g++_link_flags { paths } {
108     global rootme
109     global srcdir
110     global ld_library_path
111
112     set gccpath ${paths}
113     set libio_dir ""
114     set flags ""
115     set ld_library_path "."
116
117     if { $gccpath != "" } {
118       if [file exists "${gccpath}/lib/libstdc++.a"] {
119           append ld_library_path ":${gccpath}/lib"
120       }
121       if [file exists "${gccpath}/libg++/libg++.a"] {
122           append flags "-L${gccpath}/libg++ "
123           append ld_library_path ":${gccpath}/libg++"
124       }
125       if [file exists "${gccpath}/libstdc++/libstdc++.a"] {
126           append flags "-L${gccpath}/libstdc++ "
127           append ld_library_path ":${gccpath}/libstdc++"
128       }
129       if [file exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.a"] {
130           append flags " -L${gccpath}/libstdc++-v3/src/.libs "
131           append ld_library_path ":${gccpath}/libstdc++-v3/src/.libs"
132       }
133       if [file exists "${gccpath}/libiberty/libiberty.a"] {
134           append flags "-L${gccpath}/libiberty "
135       }
136       if [file exists "${gccpath}/librx/librx.a"] {
137           append flags "-L${gccpath}/librx "
138       }
139       append ld_library_path ":${rootme}"
140     } else {
141       global tool_root_dir;
142
143       set libgpp [lookfor_file ${tool_root_dir} libg++];
144       if { $libgpp != "" } {
145           append flags "-L${libgpp} ";
146           append ld_library_path ":${libgpp}"
147       }
148       set libstdcpp [lookfor_file ${tool_root_dir} libstdc++];
149       if { $libstdcpp != "" } {
150           append flags "-L${libstdcpp} ";
151           append ld_library_path ":${libstdcpp}"
152       }
153       set libiberty [lookfor_file ${tool_root_dir} libiberty];
154       if { $libiberty != "" } {
155           append flags "-L${libiberty} ";
156       }
157       set librx [lookfor_file ${tool_root_dir} librx];
158       if { $librx != "" } {
159           append flags "-L${librx} ";
160       }
161     }
162     return "$flags"
163 }
164
165 #
166 # g++_init -- called at the start of each subdir of tests
167 #
168
169 proc g++_init { args } {
170     global subdir
171     global gpp_initialized
172     global base_dir
173     global tmpdir
174     global libdir
175     global gluefile wrap_flags;
176     global objdir srcdir
177     global ALWAYS_CXXFLAGS
178     global TOOL_EXECUTABLE TOOL_OPTIONS
179     global GXX_UNDER_TEST
180     global TESTING_IN_BUILD_TREE
181
182     if ![info exists GXX_UNDER_TEST] then {
183         if [info exists TOOL_EXECUTABLE] {
184             set GXX_UNDER_TEST $TOOL_EXECUTABLE;
185         } else {
186             if { [is_remote host] || ! [info exists TESTING_IN_BUILD_TREE] } {
187                 set GXX_UNDER_TEST [transform c++]
188             } else {
189                 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++]]]
190             }
191         }
192     }
193
194     # Bleah, nasty. Bad taste.
195     if [ishost "*-dos-*" ] {
196         regsub "c\\+\\+" "$GXX_UNDER_TEST" "gcc" GXX_UNDER_TEST
197     }
198
199     if ![is_remote host] {
200         if { [which $GXX_UNDER_TEST] == 0 } then {
201             perror "GXX_UNDER_TEST ($GXX_UNDER_TEST) does not exist"
202             exit 1
203         }
204     }
205     if ![info exists tmpdir] {
206         set tmpdir "/tmp"
207     }
208
209     if [info exists gluefile] {
210         unset gluefile
211     }
212
213     if { [target_info needs_status_wrapper] != "" } {
214         set gluefile ${tmpdir}/testglue.o;
215         set result [build_wrapper $gluefile];
216         if { $result != "" } {
217             set gluefile [lindex $result 0];
218             set wrap_flags [lindex $result 1];
219         } else {
220             unset gluefile
221         }
222     }
223
224     set ALWAYS_CXXFLAGS ""
225
226     if ![is_remote host] {
227         if [info exists TOOL_OPTIONS] {
228             lappend ALWAYS_CXXFLAGS "additional_flags=[g++_include_flags [get_multilibs ${TOOL_OPTIONS}] ]";
229             lappend ALWAYS_CXXFLAGS "ldflags=[g++_link_flags [get_multilibs ${TOOL_OPTIONS}] ]";
230         } else {
231             lappend ALWAYS_CXXFLAGS "additional_flags=[g++_include_flags [get_multilibs] ]";
232             lappend ALWAYS_CXXFLAGS "ldflags=[g++_link_flags [get_multilibs] ]";
233         }
234     }
235
236     if [info exists TOOL_OPTIONS] {
237         lappend ALWAYS_CXXFLAGS "additional_flags=$TOOL_OPTIONS";
238     }
239
240     # Make sure that lines are not wrapped.  That can confuse the
241     # error-message parsing machinery.
242     lappend ALWAYS_CXXFLAGS "additional_flags=-fmessage-length=0"
243
244     verbose -log "ALWAYS_CXXFLAGS set to $ALWAYS_CXXFLAGS"
245
246     verbose "g++ is initialized" 3
247 }
248
249 #
250 # g++_target_compile -- compile a source file
251 #
252
253 proc g++_target_compile { source dest type options } {
254     global tmpdir;
255     global gpp_compile_options
256     global gluefile wrap_flags
257     global ALWAYS_CXXFLAGS;
258     global GXX_UNDER_TEST;
259
260     if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
261         lappend options "libs=${gluefile}"
262         lappend options "ldflags=${wrap_flags}"
263     }
264
265     lappend options "additional_flags=[libio_include_flags]"
266     lappend options "compiler=$GXX_UNDER_TEST";
267
268     set options [concat $gpp_compile_options $options]
269
270     set options [concat "$ALWAYS_CXXFLAGS" $options];
271
272     if { [regexp "(^| )-frepo( |$)" $options] && \
273          [regexp "\.o(|bj)$" $dest] } then {
274         regsub "\.o(|bj)$" $dest ".rpo" rponame
275         exec rm -f $rponame
276     }
277
278     return [target_compile $source $dest $type $options]
279 }
280
281 #
282 # g++_set_ld_library_path --
283 # On IRIX 6, we have to set variables akin to LD_LIBRARY_PATH, but
284 # called LD_LIBRARYN32_PATH (for the N32 ABI) and LD_LIBRARY64_PATH
285 # (for the 64-bit ABI).  The right way to do this would be to modify
286 # unix.exp -- but that's not an option since it's part of DejaGNU
287 # proper, so we do it here, by trickery.  We really only need to do 
288 # this on IRIX, but it shouldn't hurt to do it anywhere else.
289 #
290
291 proc ${tool}_set_ld_library_path { name element op } {
292   setenv LD_LIBRARYN32_PATH [getenv LD_LIBRARY_PATH]
293   setenv LD_LIBRARY64_PATH [getenv LD_LIBRARY_PATH]
294 }
295
296 trace variable env(LD_LIBRARY_PATH) w ${tool}_set_ld_library_path
297
298 #
299 # ${tool}_option_help
300 #
301
302 proc ${tool}_option_help { } {
303     send_user " --additional_options,OPTIONS\t\tUse OPTIONS to compile the testcase files. OPTIONS should be comma-separated.\n"
304 }
305
306 #
307 # ${tool}_option_proc
308 #
309
310 proc ${tool}_option_proc { option } {
311     if [regexp "^--additional_options," $option] {
312         global gpp_compile_options
313         regsub "--additional_options," $option "" option
314         foreach x [split $option ","] {
315             lappend gpp_compile_options "additional_flags=$x"
316         }
317         return 1;
318     } else {
319         return 0
320     }
321 }