1 # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 2000, 2001, 2002, 2003,
2 # 2004, 2005, 2007 Free Software Foundation, Inc.
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.
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.
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/>.
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>.
23 # g++ support library routines
28 load_lib target-libpath.exp
31 # GXX_UNDER_TEST is the compiler under test.
35 set gpp_compile_options ""
38 # g++_version -- extract and print the version number of the compiler
41 proc g++_version { } {
46 # ignore any arguments after the command
47 set compiler [lindex $GXX_UNDER_TEST 0]
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 \[^\n\r\]*" $output version
55 if { $status == 0 && [info exists version] } then {
57 clone_output "$compiler $version\n"
59 clone_output "[which $compiler] $version\n"
62 clone_output "Couldn't determine version of [which $compiler]\n"
65 # compiler does not exist (this should have already been detected)
66 warning "$compiler does not exist"
71 # g++_include_flags -- provide new version of g++_include_flags
72 # (originally from libgloss.exp) which knows about the gcc tree structure
74 proc g++_include_flags { paths } {
76 global HAVE_LIBSTDCXX_V3
77 global TESTING_IN_BUILD_TREE
81 if { [is_remote host] || ! [info exists TESTING_IN_BUILD_TREE] } {
87 set odir [lookfor_file ${gccpath} libstdc++-v3]
88 if { ${odir} != "" } {
89 append flags [exec sh ${odir}/scripts/testsuite_flags --build-includes]
96 # g++_link_flags -- provide new version of g++_link_flags
97 # (originally from libgloss.exp) which knows about the gcc tree structure
100 proc g++_link_flags { paths } {
102 global ld_library_path
103 global GXX_UNDER_TEST
109 set ld_library_path "."
111 set shlib_ext [get_shlib_extension]
112 verbose "shared lib extension: $shlib_ext"
114 if { $gccpath != "" } {
115 if [file exists "${gccpath}/lib/libstdc++.a"] {
116 append ld_library_path ":${gccpath}/lib"
118 if [file exists "${gccpath}/libg++/libg++.a"] {
119 append flags "-L${gccpath}/libg++ "
120 append ld_library_path ":${gccpath}/libg++"
122 if [file exists "${gccpath}/libstdc++/libstdc++.a"] {
123 append flags "-L${gccpath}/libstdc++ "
124 append ld_library_path ":${gccpath}/libstdc++"
126 if [file exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.a"] {
127 append flags " -L${gccpath}/libstdc++-v3/src/.libs "
128 append ld_library_path ":${gccpath}/libstdc++-v3/src/.libs"
130 # Look for libstdc++.${shlib_ext}.
131 if [file exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.${shlib_ext}"] {
132 append flags " -L${gccpath}/libstdc++-v3/src/.libs "
133 append ld_library_path ":${gccpath}/libstdc++-v3/src/.libs"
136 if [file exists "${gccpath}/libiberty/libiberty.a"] {
137 append flags "-L${gccpath}/libiberty "
139 if [file exists "${gccpath}/librx/librx.a"] {
140 append flags "-L${gccpath}/librx "
142 append ld_library_path [gcc-set-multilib-library-path $GXX_UNDER_TEST]
146 set libgpp [lookfor_file ${tool_root_dir} libg++]
147 if { $libgpp != "" } {
148 append flags "-L${libgpp} "
149 append ld_library_path ":${libgpp}"
151 set libstdcpp [lookfor_file ${tool_root_dir} libstdc++]
152 if { $libstdcpp != "" } {
153 append flags "-L${libstdcpp} "
154 append ld_library_path ":${libstdcpp}"
156 set libiberty [lookfor_file ${tool_root_dir} libiberty]
157 if { $libiberty != "" } {
158 append flags "-L${libiberty} "
160 set librx [lookfor_file ${tool_root_dir} librx]
161 if { $librx != "" } {
162 append flags "-L${librx} "
166 set_ld_library_path_env_vars
172 # g++_init -- called at the start of each subdir of tests
175 proc g++_init { args } {
177 global gpp_initialized
181 global gluefile wrap_flags
183 global ALWAYS_CXXFLAGS
185 global TOOL_EXECUTABLE TOOL_OPTIONS
186 global GXX_UNDER_TEST
187 global TESTING_IN_BUILD_TREE
188 global target_triplet
189 global gcc_warning_prefix
190 global gcc_error_prefix
192 # We set LC_ALL and LANG to C so that we get the same error messages as expected.
196 if ![info exists GXX_UNDER_TEST] then {
197 if [info exists TOOL_EXECUTABLE] {
198 set GXX_UNDER_TEST $TOOL_EXECUTABLE
200 if { [is_remote host] || ! [info exists TESTING_IN_BUILD_TREE] } {
201 set GXX_UNDER_TEST [transform c++]
203 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++]]]
208 # Bleah, nasty. Bad taste.
209 if [ishost "*-dos-*" ] {
210 regsub "c\\+\\+" "$GXX_UNDER_TEST" "gcc" GXX_UNDER_TEST
213 if ![is_remote host] {
214 if { [which $GXX_UNDER_TEST] == 0 } then {
215 perror "GXX_UNDER_TEST ($GXX_UNDER_TEST) does not exist"
219 if ![info exists tmpdir] {
223 if [info exists gluefile] {
227 g++_maybe_build_wrapper "${tmpdir}/g++-testglue.o" "-fexceptions"
229 if {![info exists CXXFLAGS]} {
233 set ALWAYS_CXXFLAGS ""
235 if ![is_remote host] {
236 if [info exists TOOL_OPTIONS] {
237 lappend ALWAYS_CXXFLAGS "additional_flags=[g++_include_flags [get_multilibs ${TOOL_OPTIONS}] ]"
238 lappend ALWAYS_CXXFLAGS "ldflags=[g++_link_flags [get_multilibs ${TOOL_OPTIONS}] ]"
240 lappend ALWAYS_CXXFLAGS "additional_flags=[g++_include_flags [get_multilibs] ]"
241 lappend ALWAYS_CXXFLAGS "ldflags=[g++_link_flags [get_multilibs] ]"
245 if [info exists TOOL_OPTIONS] {
246 lappend ALWAYS_CXXFLAGS "additional_flags=$TOOL_OPTIONS"
249 # Make sure that lines are not wrapped. That can confuse the
250 # error-message parsing machinery.
251 lappend ALWAYS_CXXFLAGS "additional_flags=-fmessage-length=0"
253 set gcc_warning_prefix "warning:"
254 set gcc_error_prefix "error:"
256 if { [string match "*-*-darwin*" $target_triplet] } {
257 lappend ALWAYS_CXXFLAGS "ldflags=-multiply_defined suppress"
260 verbose -log "ALWAYS_CXXFLAGS set to $ALWAYS_CXXFLAGS"
262 verbose "g++ is initialized" 3
266 # g++_target_compile -- compile a source file
269 proc g++_target_compile { source dest type options } {
271 global gpp_compile_options
272 global gluefile wrap_flags
273 global ALWAYS_CXXFLAGS
274 global GXX_UNDER_TEST
276 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
277 lappend options "libs=${gluefile}"
278 lappend options "ldflags=${wrap_flags}"
281 lappend options "additional_flags=[libio_include_flags]"
282 lappend options "compiler=$GXX_UNDER_TEST"
283 lappend options "timeout=[timeout_value]"
285 set options [concat $gpp_compile_options $options]
287 set options [concat "$ALWAYS_CXXFLAGS" $options]
289 if { [regexp "(^| )-frepo( |$)" $options] && \
290 [regexp "\.o(|bj)$" $dest] } then {
291 regsub "\.o(|bj)$" $dest ".rpo" rponame
295 set options [dg-additional-files-options $options $source]
297 set result [target_compile $source $dest $type $options]
303 # ${tool}_option_help
306 proc ${tool}_option_help { } {
307 send_user " --additional_options,OPTIONS\t\tUse OPTIONS to compile the testcase files. OPTIONS should be comma-separated.\n"
311 # ${tool}_option_proc
314 proc ${tool}_option_proc { option } {
315 if [regexp "^--additional_options," $option] {
316 global gpp_compile_options
317 regsub "--additional_options," $option "" option
318 foreach x [split $option ","] {
319 lappend gpp_compile_options "additional_flags=$x"