OSDN Git Service

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