OSDN Git Service

PR testsuite/25241
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / lib / g++.exp
1 # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 2000, 2001, 2002, 2003,
2 # 2004, 2005, 2007 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 3 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 GCC; see the file COPYING3.  If not see
16 # <http://www.gnu.org/licenses/>.
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 load_lib target-libpath.exp
28
29 #
30 # GXX_UNDER_TEST is the compiler under test.
31 #
32
33
34 set gpp_compile_options ""
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 \[^\n\r\]*" $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 gccpath ${paths}
85
86     set odir [lookfor_file ${gccpath} libstdc++-v3]
87     if { ${odir} != "" } {
88       append flags [exec sh ${odir}/scripts/testsuite_flags --build-includes]  
89     }
90
91     return "$flags"
92 }
93
94 #
95 # g++_link_flags -- provide new version of g++_link_flags
96 # (originally from libgloss.exp) which knows about the gcc tree structure
97 #
98
99 proc g++_link_flags { paths } {
100     global srcdir
101     global ld_library_path
102     global GXX_UNDER_TEST
103     global shlib_ext
104
105     set gccpath ${paths}
106     set libio_dir ""
107     set flags ""
108     set ld_library_path "."
109
110     set shlib_ext [get_shlib_extension]
111     verbose "shared lib extension: $shlib_ext"
112
113     if { $gccpath != "" } {
114       if [file exists "${gccpath}/lib/libstdc++.a"] {
115           append ld_library_path ":${gccpath}/lib"
116       }
117       if [file exists "${gccpath}/libg++/libg++.a"] {
118           append flags "-L${gccpath}/libg++ "
119           append ld_library_path ":${gccpath}/libg++"
120       }
121       if [file exists "${gccpath}/libstdc++/libstdc++.a"] {
122           append flags "-L${gccpath}/libstdc++ "
123           append ld_library_path ":${gccpath}/libstdc++"
124       }
125       if [file exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.a"] {
126           append flags " -L${gccpath}/libstdc++-v3/src/.libs "
127           append ld_library_path ":${gccpath}/libstdc++-v3/src/.libs"
128       }
129       # Look for libstdc++.${shlib_ext}.
130       if [file exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.${shlib_ext}"] {
131           append flags " -L${gccpath}/libstdc++-v3/src/.libs "
132           append ld_library_path ":${gccpath}/libstdc++-v3/src/.libs"
133       }
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 [gcc-set-multilib-library-path $GXX_UNDER_TEST]
142     } else {
143       global tool_root_dir
144
145       set libgpp [lookfor_file ${tool_root_dir} libg++]
146       if { $libgpp != "" } {
147           append flags "-L${libgpp} "
148           append ld_library_path ":${libgpp}"
149       }
150       set libstdcpp [lookfor_file ${tool_root_dir} libstdc++]
151       if { $libstdcpp != "" } {
152           append flags "-L${libstdcpp} "
153           append ld_library_path ":${libstdcpp}"
154       }
155       set libiberty [lookfor_file ${tool_root_dir} libiberty]
156       if { $libiberty != "" } {
157           append flags "-L${libiberty} "
158       }
159       set librx [lookfor_file ${tool_root_dir} librx]
160       if { $librx != "" } {
161           append flags "-L${librx} "
162       }
163     }
164
165     set_ld_library_path_env_vars
166
167     return "$flags"
168 }
169
170 #
171 # g++_init -- called at the start of each subdir of tests
172 #
173
174 proc g++_init { args } {
175     global subdir
176     global gpp_initialized
177     global base_dir
178     global tmpdir
179     global libdir
180     global gluefile wrap_flags
181     global objdir srcdir
182     global ALWAYS_CXXFLAGS
183     global CXXFLAGS
184     global TOOL_EXECUTABLE TOOL_OPTIONS
185     global GXX_UNDER_TEST
186     global TESTING_IN_BUILD_TREE
187     global target_triplet
188     global gcc_warning_prefix
189     global gcc_error_prefix
190
191     # We set LC_ALL and LANG to C so that we get the same error messages as expected.
192     setenv LC_ALL C
193     setenv LANG C
194
195     if ![info exists GXX_UNDER_TEST] then {
196         if [info exists TOOL_EXECUTABLE] {
197             set GXX_UNDER_TEST $TOOL_EXECUTABLE
198         } else {
199             if { [is_remote host] || ! [info exists TESTING_IN_BUILD_TREE] } {
200                 set GXX_UNDER_TEST [transform c++]
201             } else {
202                 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++]]]
203             }
204         }
205     }
206
207     # Bleah, nasty. Bad taste.
208     if [ishost "*-dos-*" ] {
209         regsub "c\\+\\+" "$GXX_UNDER_TEST" "gcc" GXX_UNDER_TEST
210     }
211
212     if ![is_remote host] {
213         if { [which $GXX_UNDER_TEST] == 0 } then {
214             perror "GXX_UNDER_TEST ($GXX_UNDER_TEST) does not exist"
215             exit 1
216         }
217     }
218     if ![info exists tmpdir] {
219         set tmpdir "/tmp"
220     }
221
222     if [info exists gluefile] {
223         unset gluefile
224     }
225
226     g++_maybe_build_wrapper "${tmpdir}/g++-testglue.o" "-fexceptions"
227
228     if {![info exists CXXFLAGS]} {
229         set CXXFLAGS ""
230     }
231
232     set ALWAYS_CXXFLAGS ""
233
234     if ![is_remote host] {
235         if [info exists TOOL_OPTIONS] {
236             lappend ALWAYS_CXXFLAGS "additional_flags=[g++_include_flags [get_multilibs ${TOOL_OPTIONS}] ]"
237             lappend ALWAYS_CXXFLAGS "ldflags=[g++_link_flags [get_multilibs ${TOOL_OPTIONS}] ]"
238         } else {
239             lappend ALWAYS_CXXFLAGS "additional_flags=[g++_include_flags [get_multilibs] ]"
240             lappend ALWAYS_CXXFLAGS "ldflags=[g++_link_flags [get_multilibs] ]"
241         }
242     }
243
244     if [info exists TOOL_OPTIONS] {
245         lappend ALWAYS_CXXFLAGS "additional_flags=$TOOL_OPTIONS"
246     }
247
248     # Make sure that lines are not wrapped.  That can confuse the
249     # error-message parsing machinery.
250     lappend ALWAYS_CXXFLAGS "additional_flags=-fmessage-length=0"
251
252     set gcc_warning_prefix "warning:"
253     set gcc_error_prefix "error:"
254
255     if { [string match "*-*-darwin*" $target_triplet] } {
256         lappend ALWAYS_CXXFLAGS "ldflags=-multiply_defined suppress"
257        }
258
259     verbose -log "ALWAYS_CXXFLAGS set to $ALWAYS_CXXFLAGS"
260
261     verbose "g++ is initialized" 3
262 }
263
264 #
265 # g++_target_compile -- compile a source file
266 #
267
268 proc g++_target_compile { source dest type options } {
269     global tmpdir
270     global gpp_compile_options
271     global gluefile wrap_flags
272     global ALWAYS_CXXFLAGS
273     global GXX_UNDER_TEST
274
275     if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
276         lappend options "libs=${gluefile}"
277         lappend options "ldflags=${wrap_flags}"
278     }
279
280     lappend options "additional_flags=[libio_include_flags]"
281     lappend options "compiler=$GXX_UNDER_TEST"
282
283     set options [concat $gpp_compile_options $options]
284
285     set options [concat "$ALWAYS_CXXFLAGS" $options]
286
287     if { [regexp "(^| )-frepo( |$)" $options] && \
288          [regexp "\.o(|bj)$" $dest] } then {
289         regsub "\.o(|bj)$" $dest ".rpo" rponame
290         exec rm -f $rponame
291     }
292
293     set options [dg-additional-files-options $options $source]
294
295     set result [target_compile $source $dest $type $options]
296
297     return $result
298 }
299
300 #
301 # ${tool}_option_help
302 #
303
304 proc ${tool}_option_help { } {
305     send_user " --additional_options,OPTIONS\t\tUse OPTIONS to compile the testcase files. OPTIONS should be comma-separated.\n"
306 }
307
308 #
309 # ${tool}_option_proc
310 #
311
312 proc ${tool}_option_proc { option } {
313     if [regexp "^--additional_options," $option] {
314         global gpp_compile_options
315         regsub "--additional_options," $option "" option
316         foreach x [split $option ","] {
317             lappend gpp_compile_options "additional_flags=$x"
318         }
319         return 1
320     } else {
321         return 0
322     }
323 }