OSDN Git Service

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