OSDN Git Service

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