OSDN Git Service

2003-12-09 Robert Schiele <rschiele@uni-mannheim.de>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / lib / g++.exp
1 # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 2000, 2001, 2002, 2003
2 # Free Software Foundation, Inc.
3
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.
13
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.
17
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>.
21
22 #
23 # g++ support library routines
24 #
25 load_lib prune.exp
26 load_lib gcc-defs.exp
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
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\[^\n\r\]*" $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 gccpath ${paths}
84
85     set odir [lookfor_file ${gccpath} libstdc++-v3]
86     if { ${odir} != "" } {
87       append flags [exec sh ${odir}/scripts/testsuite_flags --build-includes]  
88     }
89
90     return "$flags"
91 }
92
93 #
94 # g++_link_flags -- provide new version of g++_link_flags
95 # (originally from libgloss.exp) which knows about the gcc tree structure
96 #
97
98 proc g++_link_flags { paths } {
99     global rootme
100     global srcdir
101     global ld_library_path
102     global GXX_UNDER_TEST
103
104     set gccpath ${paths}
105     set libio_dir ""
106     set flags ""
107     set ld_library_path "."
108
109     if { $gccpath != "" } {
110       if [file exists "${gccpath}/lib/libstdc++.a"] {
111           append ld_library_path ":${gccpath}/lib"
112       }
113       if [file exists "${gccpath}/libg++/libg++.a"] {
114           append flags "-L${gccpath}/libg++ "
115           append ld_library_path ":${gccpath}/libg++"
116       }
117       if [file exists "${gccpath}/libstdc++/libstdc++.a"] {
118           append flags "-L${gccpath}/libstdc++ "
119           append ld_library_path ":${gccpath}/libstdc++"
120       }
121       if [file exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.a"] {
122           append flags " -L${gccpath}/libstdc++-v3/src/.libs "
123           append ld_library_path ":${gccpath}/libstdc++-v3/src/.libs"
124       }
125       if [file exists "${gccpath}/libiberty/libiberty.a"] {
126           append flags "-L${gccpath}/libiberty "
127       }
128       if [file exists "${gccpath}/librx/librx.a"] {
129           append flags "-L${gccpath}/librx "
130       }
131       append ld_library_path ":${rootme}"
132       set compiler [lindex $GXX_UNDER_TEST 0]
133       if { [is_remote host] == 0 && [which $compiler] != 0 } {
134         foreach i "[exec $compiler --print-multi-lib]" {
135           set mldir ""
136           regexp -- "\[a-z0-9=/\.-\]*;" $i mldir
137           set mldir [string trimright $mldir "\;@"]
138           if { "$mldir" == "." } {
139             continue
140           }
141           if { [llength [glob -nocomplain ${rootme}/${mldir}/libgcc_s*.so.*]] == 1 } {
142             append ld_library_path ":${rootme}/${mldir}"
143           }
144         }
145       }
146     } else {
147       global tool_root_dir;
148
149       set libgpp [lookfor_file ${tool_root_dir} libg++];
150       if { $libgpp != "" } {
151           append flags "-L${libgpp} ";
152           append ld_library_path ":${libgpp}"
153       }
154       set libstdcpp [lookfor_file ${tool_root_dir} libstdc++];
155       if { $libstdcpp != "" } {
156           append flags "-L${libstdcpp} ";
157           append ld_library_path ":${libstdcpp}"
158       }
159       set libiberty [lookfor_file ${tool_root_dir} libiberty];
160       if { $libiberty != "" } {
161           append flags "-L${libiberty} ";
162       }
163       set librx [lookfor_file ${tool_root_dir} librx];
164       if { $librx != "" } {
165           append flags "-L${librx} ";
166       }
167     }
168
169     # On IRIX 6, we have to set variables akin to LD_LIBRARY_PATH, but
170     # called LD_LIBRARYN32_PATH (for the N32 ABI) and LD_LIBRARY64_PATH
171     # (for the 64-bit ABI).  The right way to do this would be to modify
172     # unix.exp -- but that's not an option since it's part of DejaGNU
173     # proper, so we do it here.  We really only need to do 
174     # this on IRIX, but it shouldn't hurt to do it anywhere else.
175     setenv  LD_LIBRARY_PATH     $ld_library_path
176     setenv  SHLIB_PATH          $ld_library_path
177     setenv  LD_LIBRARYN32_PATH  $ld_library_path
178     setenv  LD_LIBRARY64_PATH   $ld_library_path
179     setenv  DYLD_LIBRARY_PATH   $ld_library_path
180
181     return "$flags"
182 }
183
184 #
185 # g++_init -- called at the start of each subdir of tests
186 #
187
188 proc g++_init { args } {
189     global subdir
190     global gpp_initialized
191     global base_dir
192     global tmpdir
193     global libdir
194     global gluefile wrap_flags;
195     global objdir srcdir
196     global ALWAYS_CXXFLAGS
197     global TOOL_EXECUTABLE TOOL_OPTIONS
198     global GXX_UNDER_TEST
199     global TESTING_IN_BUILD_TREE
200     global target_triplet
201
202     if ![info exists GXX_UNDER_TEST] then {
203         if [info exists TOOL_EXECUTABLE] {
204             set GXX_UNDER_TEST $TOOL_EXECUTABLE;
205         } else {
206             if { [is_remote host] || ! [info exists TESTING_IN_BUILD_TREE] } {
207                 set GXX_UNDER_TEST [transform c++]
208             } else {
209                 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++]]]
210             }
211         }
212     }
213
214     # Bleah, nasty. Bad taste.
215     if [ishost "*-dos-*" ] {
216         regsub "c\\+\\+" "$GXX_UNDER_TEST" "gcc" GXX_UNDER_TEST
217     }
218
219     if ![is_remote host] {
220         if { [which $GXX_UNDER_TEST] == 0 } then {
221             perror "GXX_UNDER_TEST ($GXX_UNDER_TEST) does not exist"
222             exit 1
223         }
224     }
225     if ![info exists tmpdir] {
226         set tmpdir "/tmp"
227     }
228
229     if [info exists gluefile] {
230         unset gluefile
231     }
232
233     if { [target_info needs_status_wrapper] != "" } {
234         set gluefile ${tmpdir}/g++-testglue.o;
235         set result [build_wrapper $gluefile];
236         if { $result != "" } {
237             set gluefile [lindex $result 0];
238             set wrap_flags [lindex $result 1];
239         } else {
240             unset gluefile
241         }
242     }
243
244     set ALWAYS_CXXFLAGS ""
245
246     if ![is_remote host] {
247         if [info exists TOOL_OPTIONS] {
248             lappend ALWAYS_CXXFLAGS "additional_flags=[g++_include_flags [get_multilibs ${TOOL_OPTIONS}] ]";
249             lappend ALWAYS_CXXFLAGS "ldflags=[g++_link_flags [get_multilibs ${TOOL_OPTIONS}] ]";
250         } else {
251             lappend ALWAYS_CXXFLAGS "additional_flags=[g++_include_flags [get_multilibs] ]";
252             lappend ALWAYS_CXXFLAGS "ldflags=[g++_link_flags [get_multilibs] ]";
253         }
254     }
255
256     if [info exists TOOL_OPTIONS] {
257         lappend ALWAYS_CXXFLAGS "additional_flags=$TOOL_OPTIONS";
258     }
259
260     # Make sure that lines are not wrapped.  That can confuse the
261     # error-message parsing machinery.
262     lappend ALWAYS_CXXFLAGS "additional_flags=-fmessage-length=0"
263
264     if { [string match "powerpc-*-darwin*" $target_triplet] } {
265         lappend ALWAYS_CXXFLAGS "ldflags=-multiply_defined suppress"
266        }
267
268     verbose -log "ALWAYS_CXXFLAGS set to $ALWAYS_CXXFLAGS"
269
270     verbose "g++ is initialized" 3
271 }
272
273 #
274 # g++_target_compile -- compile a source file
275 #
276
277 proc g++_target_compile { source dest type options } {
278     global tmpdir;
279     global gpp_compile_options
280     global gluefile wrap_flags
281     global ALWAYS_CXXFLAGS;
282     global GXX_UNDER_TEST;
283
284     if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
285         lappend options "libs=${gluefile}"
286         lappend options "ldflags=${wrap_flags}"
287     }
288
289     lappend options "additional_flags=[libio_include_flags]"
290     lappend options "compiler=$GXX_UNDER_TEST";
291
292     set options [concat $gpp_compile_options $options]
293
294     set options [concat "$ALWAYS_CXXFLAGS" $options];
295
296     if { [regexp "(^| )-frepo( |$)" $options] && \
297          [regexp "\.o(|bj)$" $dest] } then {
298         regsub "\.o(|bj)$" $dest ".rpo" rponame
299         exec rm -f $rponame
300     }
301
302     set options [dg-additional-files-options $options $source]
303
304     set result [target_compile $source $dest $type $options]
305
306     return $result
307 }
308
309 #
310 # ${tool}_option_help
311 #
312
313 proc ${tool}_option_help { } {
314     send_user " --additional_options,OPTIONS\t\tUse OPTIONS to compile the testcase files. OPTIONS should be comma-separated.\n"
315 }
316
317 #
318 # ${tool}_option_proc
319 #
320
321 proc ${tool}_option_proc { option } {
322     if [regexp "^--additional_options," $option] {
323         global gpp_compile_options
324         regsub "--additional_options," $option "" option
325         foreach x [split $option ","] {
326             lappend gpp_compile_options "additional_flags=$x"
327         }
328         return 1;
329     } else {
330         return 0
331     }
332 }