Merge reload-branch up to revision 101000
[official-gcc.git] / gcc / testsuite / lib / obj-c++.exp
blobe88e011bb2cbdcab36e902170a9fd2d0f94afbda
1 # Copyright (C) 2004 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 # This file was written by Rob Savoye (rob@cygnus.com)
18 # Many modifications by Jeffrey Wheat (cassidy@cygnus.com)
19 # With modifications by Mike Stump <mrs@cygnus.com>.
22 # obj-c++ support library routines
24 load_lib prune.exp
25 load_lib gcc-defs.exp
28 # OBJCXX_UNDER_TEST is the compiler under test.
32 set gpp_compile_options ""
35 # obj-c++_version -- extract and print the version number of the compiler
38 proc obj-c++_version { } {
39 global OBJCXX_UNDER_TEST
41 obj-c++_init
43 # ignore any arguments after the command
44 set compiler [lindex $OBJCXX_UNDER_TEST 0]
46 # verify that the compiler exists
47 if { [is_remote host] || [which $compiler] != 0 } then {
48 set tmp [remote_exec host "$compiler -v"]
49 set status [lindex $tmp 0];
50 set output [lindex $tmp 1];
51 regexp " version \[^\n\r\]*" $output version
52 if { $status == 0 && [info exists version] } then {
53 if [is_remote host] {
54 clone_output "$compiler $version\n"
55 } else {
56 clone_output "[which $compiler] $version\n"
58 } else {
59 clone_output "Couldn't determine version of [which $compiler]\n"
61 } else {
62 # compiler does not exist (this should have already been detected)
63 warning "$compiler does not exist"
68 # obj-c++_include_flags -- provide new version of obj-c++_include_flags
69 # (originally from libgloss.exp) which knows about the gcc tree structure
71 proc obj-c++_include_flags { paths } {
72 global srcdir
73 global HAVE_LIBSTDCXX_V3
74 global TESTING_IN_BUILD_TREE
76 set flags ""
78 if { [is_remote host] || ! [info exists TESTING_IN_BUILD_TREE] } {
79 return "${flags}"
82 set gccpath ${paths}
84 set odir [lookfor_file ${gccpath} libstdc++-v3]
85 if { ${odir} != "" } {
86 append flags [exec sh ${odir}/scripts/testsuite_flags --build-includes]
89 return "$flags"
93 # obj-c++_link_flags -- provide new version of obj-c++_link_flags
94 # (originally from libgloss.exp) which knows about the gcc tree structure
97 proc obj-c++_link_flags { paths } {
98 global rootme
99 global srcdir
100 global ld_library_path
101 global OBJCXX_UNDER_TEST
103 set gccpath ${paths}
104 set libio_dir ""
105 set flags ""
106 set ld_library_path "."
108 if { $gccpath != "" } {
109 if [file exists "${gccpath}/lib/libstdc++.a"] {
110 append ld_library_path ":${gccpath}/lib"
112 if [file exists "${gccpath}/libg++/libg++.a"] {
113 append flags "-L${gccpath}/libg++ "
114 append ld_library_path ":${gccpath}/libg++"
116 if [file exists "${gccpath}/libstdc++/libstdc++.a"] {
117 append flags "-L${gccpath}/libstdc++ "
118 append ld_library_path ":${gccpath}/libstdc++"
120 if [file exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.a"] {
121 append flags " -L${gccpath}/libstdc++-v3/src/.libs "
122 append ld_library_path ":${gccpath}/libstdc++-v3/src/.libs"
124 if [file exists "${gccpath}/libiberty/libiberty.a"] {
125 append flags "-L${gccpath}/libiberty "
127 if [file exists "${gccpath}/librx/librx.a"] {
128 append flags "-L${gccpath}/librx "
130 append ld_library_path ":${rootme}"
131 set compiler [lindex $OBJCXX_UNDER_TEST 0]
132 if { [is_remote host] == 0 && [which $compiler] != 0 } {
133 foreach i "[exec $compiler --print-multi-lib]" {
134 set mldir ""
135 regexp -- "\[a-z0-9=/\.-\]*;" $i mldir
136 set mldir [string trimright $mldir "\;@"]
137 if { "$mldir" == "." } {
138 continue
140 if { [llength [glob -nocomplain ${rootme}/${mldir}/libgcc_s*.so.*]] == 1 } {
141 append ld_library_path ":${rootme}/${mldir}"
145 } else {
146 global tool_root_dir;
148 set libgpp [lookfor_file ${tool_root_dir} libg++];
149 if { $libgpp != "" } {
150 append flags "-L${libgpp} ";
151 append ld_library_path ":${libgpp}"
153 set libstdcpp [lookfor_file ${tool_root_dir} libstdc++];
154 if { $libstdcpp != "" } {
155 append flags "-L${libstdcpp} ";
156 append ld_library_path ":${libstdcpp}"
158 set libiberty [lookfor_file ${tool_root_dir} libiberty];
159 if { $libiberty != "" } {
160 append flags "-L${libiberty} ";
162 set librx [lookfor_file ${tool_root_dir} librx];
163 if { $librx != "" } {
164 append flags "-L${librx} ";
168 # On IRIX 6, we have to set variables akin to LD_LIBRARY_PATH, but
169 # called LD_LIBRARYN32_PATH (for the N32 ABI) and LD_LIBRARY64_PATH
170 # (for the 64-bit ABI). The right way to do this would be to modify
171 # unix.exp -- but that's not an option since it's part of DejaGNU
172 # proper, so we do it here.
173 # The same applies to Darwin (DYLD_LIBRARY_PATH), Solaris 32 bit
174 # (LD_LIBRARY_PATH_32), Solaris 64 bit (LD_LIBRARY_PATH_64), and HP-UX
175 # (SHLIB_PATH).
176 # Doing this does cause trouble when testing cross-compilers.
177 if {![is_remote target]} {
178 global env;
179 if [info exists env(LD_LIBRARY_PATH)] {
180 # If we've already added these directories once, keep the
181 # existing path.
182 if {$ld_library_path == $env(LD_LIBRARY_PATH)
183 || [string first $ld_library_path: \
184 $env(LD_LIBRARY_PATH)] == 0} {
185 set ld_library_path $env(LD_LIBRARY_PATH)
186 } elseif { $env(LD_LIBRARY_PATH) != "" } {
187 append ld_library_path ":$env(LD_LIBRARY_PATH)"
190 setenv LD_LIBRARY_PATH $ld_library_path
191 setenv SHLIB_PATH $ld_library_path
192 setenv LD_LIBRARYN32_PATH $ld_library_path
193 setenv LD_LIBRARY64_PATH $ld_library_path
194 setenv LD_LIBRARY_PATH_32 $ld_library_path
195 setenv LD_LIBRARY_PATH_64 $ld_library_path
196 setenv DYLD_LIBRARY_PATH $ld_library_path
199 return "$flags"
203 # obj-c++_init -- called at the start of each subdir of tests
206 proc obj-c++_init { args } {
207 global subdir
208 global gpp_initialized
209 global base_dir
210 global tmpdir
211 global libdir
212 global gluefile wrap_flags;
213 global objdir srcdir
214 global ALWAYS_OBJCXXFLAGS
215 global TOOL_EXECUTABLE TOOL_OPTIONS
216 global OBJCXX_UNDER_TEST
217 global TESTING_IN_BUILD_TREE
218 global target_triplet
220 if ![info exists OBJCXX_UNDER_TEST] then {
221 if [info exists TOOL_EXECUTABLE] {
222 set OBJCXX_UNDER_TEST $TOOL_EXECUTABLE;
223 } else {
224 if { [is_remote host] || ! [info exists TESTING_IN_BUILD_TREE] } {
225 set OBJCXX_UNDER_TEST [transform c++]
226 } else {
227 set OBJCXX_UNDER_TEST [findfile $base_dir/../g++ "$base_dir/../g++ -B$base_dir/../" [findfile $base_dir/g++ "$base_dir/g++ -B$base_dir/" [transform c++]]]
232 # Bleah, nasty. Bad taste.
233 if [ishost "*-dos-*" ] {
234 regsub "c\\+\\+" "$OBJCXX_UNDER_TEST" "gcc" OBJCXX_UNDER_TEST
237 if ![is_remote host] {
238 if { [which $OBJCXX_UNDER_TEST] == 0 } then {
239 perror "OBJCXX_UNDER_TEST ($OBJCXX_UNDER_TEST) does not exist"
240 exit 1
243 if ![info exists tmpdir] {
244 set tmpdir "/tmp"
247 if [info exists gluefile] {
248 unset gluefile
251 obj-c++_maybe_build_wrapper "${tmpdir}/obj-c++-testglue.o"
253 set ALWAYS_OBJCXXFLAGS ""
255 if ![is_remote host] {
256 if [info exists TOOL_OPTIONS] {
257 lappend ALWAYS_OBJCXXFLAGS "additional_flags=[obj-c++_include_flags [get_multilibs ${TOOL_OPTIONS}] ]";
258 lappend ALWAYS_OBJCXXFLAGS "ldflags=[obj-c++_link_flags [get_multilibs ${TOOL_OPTIONS}] ]";
259 } else {
260 lappend ALWAYS_OBJCXXFLAGS "additional_flags=[obj-c++_include_flags [get_multilibs] ]";
261 lappend ALWAYS_OBJCXXFLAGS "ldflags=[obj-c++_link_flags [get_multilibs] ]";
265 if [info exists TOOL_OPTIONS] {
266 lappend ALWAYS_OBJCXXFLAGS "additional_flags=$TOOL_OPTIONS";
269 # Make sure that lines are not wrapped. That can confuse the
270 # error-message parsing machinery.
271 lappend ALWAYS_OBJCXXFLAGS "additional_flags=-fmessage-length=0"
273 if { [string match "powerpc-*-darwin*" $target_triplet] } {
274 lappend ALWAYS_OBJCXXFLAGS "ldflags=-multiply_defined suppress"
277 verbose -log "ALWAYS_OBJCXXFLAGS set to $ALWAYS_OBJCXXFLAGS"
279 verbose "obj-c++ is initialized" 3
283 # obj-c++_target_compile -- compile a source file
286 proc obj-c++_target_compile { source dest type options } {
287 global tmpdir
288 global srcdir
289 global gpp_compile_options
290 global gluefile wrap_flags
291 global ALWAYS_OBJCXXFLAGS
292 global OBJCXX_UNDER_TEST
294 lappend options "libs=-lobjc"
296 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
297 lappend options "libs=${gluefile}"
298 lappend options "ldflags=${wrap_flags}"
301 # If we have built libobjc along with the compiler (which usually
302 # _is not_ the case on Mac OS X systems), point the test harness
303 # at it (and associated headers).
305 set objcpath "[get_multilibs]"
307 set libobjc_dir [lookfor_file ${objcpath} libobjc/.libs/libobjc.a]
308 if { $libobjc_dir == ""} {
309 verbose "see if we have -fgnu-runtime in [target_info name]"
310 if [regexp ".*-fgnu-runtime.*" [target_info name]] {
311 set libobjc_dir [lookfor_file ${objcpath} libobjc/.libs/libobjc-gnu.a]
314 if { $libobjc_dir != "" } {
315 set objc_include_dir "${srcdir}/../../libobjc"
316 lappend options "additional_flags=-I${objc_include_dir}"
317 set libobjc_dir [file dirname ${libobjc_dir}]
318 set objc_link_flags "-L${libobjc_dir}"
319 lappend options "additional_flags=${objc_link_flags}"
320 append ld_library_path ":${libobjc_dir}"
323 lappend options "additional_flags=[libio_include_flags]"
324 lappend options "compiler=$OBJCXX_UNDER_TEST";
326 set options [concat $gpp_compile_options $options]
328 set options [concat "$ALWAYS_OBJCXXFLAGS" $options];
330 if { [regexp "(^| )-frepo( |$)" $options] && \
331 [regexp "\.o(|bj)$" $dest] } then {
332 regsub "\.o(|bj)$" $dest ".rpo" rponame
333 exec rm -f $rponame
336 set options [dg-additional-files-options $options $source]
338 set result [target_compile $source $dest $type $options]
340 return $result
344 # ${tool}_option_help
347 proc ${tool}_option_help { } {
348 send_user " --additional_options,OPTIONS\t\tUse OPTIONS to compile the testcase files. OPTIONS should be comma-separated.\n"
352 # ${tool}_option_proc
355 proc ${tool}_option_proc { option } {
356 if [regexp "^--additional_options," $option] {
357 global gpp_compile_options
358 regsub "--additional_options," $option "" option
359 foreach x [split $option ","] {
360 lappend gpp_compile_options "additional_flags=$x"
362 return 1;
363 } else {
364 return 0