OSDN Git Service

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