OSDN Git Service

PR c++/34238
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / lib / obj-c++.exp
1 # Copyright (C) 2004, 2005, 2007 Free Software Foundation, Inc.
2
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 3 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.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with GCC; see the file COPYING3.  If not see
15 # <http://www.gnu.org/licenses/>.
16
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>.
20
21 #
22 # obj-c++ support library routines
23 #
24 load_lib prune.exp
25 load_lib gcc-defs.exp
26 load_lib target-libpath.exp
27
28 #
29 # OBJCXX_UNDER_TEST is the compiler under test.
30 #
31
32
33 set gpp_compile_options ""
34
35 #
36 # obj-c++_version -- extract and print the version number of the compiler
37 #
38
39 proc obj-c++_version { } {
40     global OBJCXX_UNDER_TEST
41     
42     obj-c++_init
43
44     # ignore any arguments after the command
45     set compiler [lindex $OBJCXX_UNDER_TEST 0]
46     
47     # verify that the compiler exists
48     if { [is_remote host] || [which $compiler] != 0 } then {
49         set tmp [remote_exec host "$compiler -v"]
50         set status [lindex $tmp 0];
51         set output [lindex $tmp 1];
52         regexp " version \[^\n\r\]*" $output version
53         if { $status == 0 && [info exists version] } then {
54             if [is_remote host] {
55                 clone_output "$compiler $version\n"
56             } else {
57                 clone_output "[which $compiler] $version\n"
58             }
59         } else {
60             clone_output "Couldn't determine version of [which $compiler]\n"
61         }
62     } else {
63         # compiler does not exist (this should have already been detected)
64         warning "$compiler does not exist"
65     }
66 }
67
68 #
69 # obj-c++_include_flags -- provide new version of obj-c++_include_flags
70 # (originally from libgloss.exp) which knows about the gcc tree structure
71 #
72 proc obj-c++_include_flags { paths } {
73     global srcdir
74     global HAVE_LIBSTDCXX_V3
75     global TESTING_IN_BUILD_TREE
76
77     set flags ""
78
79     if { [is_remote host] || ! [info exists TESTING_IN_BUILD_TREE] } {
80       return "${flags}"
81     }
82
83     set gccpath ${paths}
84
85     set odir [lookfor_file ${gccpath} libstdc++-v3]
86     if { ${odir} != "" } {
87       append flags [exec sh ${odir}/scripts/testsuite_flags --build-includes]  
88     }
89
90     return "$flags"
91 }
92
93 #
94 # obj-c++_link_flags -- provide new version of obj-c++_link_flags
95 # (originally from libgloss.exp) which knows about the gcc tree structure
96 #
97
98 proc obj-c++_link_flags { paths } {
99     global rootme
100     global srcdir
101     global ld_library_path
102     global OBJCXX_UNDER_TEST
103     global shlib_ext
104
105     set gccpath ${paths}
106     set libio_dir ""
107     set flags ""
108     set ld_library_path "."
109     set shlib_ext [get_shlib_extension]
110     verbose "shared lib extension: $shlib_ext"
111
112     if { $gccpath != "" } {
113       if [file exists "${gccpath}/lib/libstdc++.a"] {
114           append ld_library_path ":${gccpath}/lib"
115       }
116       if [file exists "${gccpath}/libg++/libg++.a"] {
117           append flags "-L${gccpath}/libg++ "
118           append ld_library_path ":${gccpath}/libg++"
119       }
120       if [file exists "${gccpath}/libstdc++/libstdc++.a"] {
121           append flags "-L${gccpath}/libstdc++ "
122           append ld_library_path ":${gccpath}/libstdc++"
123       }
124       if [file exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.a"] {
125           append flags " -L${gccpath}/libstdc++-v3/src/.libs "
126           append ld_library_path ":${gccpath}/libstdc++-v3/src/.libs"
127       }
128       # Look for libstdc++.${shlib_ext}.
129       if [file exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.${shlib_ext}"] {
130           append flags " -L${gccpath}/libstdc++-v3/src/.libs "
131           append ld_library_path ":${gccpath}/libstdc++-v3/src/.libs"
132       }
133       if [file exists "${gccpath}/libiberty/libiberty.a"] {
134           append flags "-L${gccpath}/libiberty "
135       }
136       if [file exists "${gccpath}/librx/librx.a"] {
137           append flags "-L${gccpath}/librx "
138       }
139
140       set objcpath "[get_multilibs]"
141       set libobjc_dir [lookfor_file ${objcpath} libobjc/.libs/libobjc.a]
142       if { $libobjc_dir == ""} {
143           set libobjc_dir [lookfor_file ${objcpath} libobjc/.libs/libobjc-gnu.a]
144       }
145       # Now check if we have a shared only build.
146       if { $libobjc_dir == ""} {
147           set libobjc_dir \
148               [lookfor_file ${objcpath} libobjc/.libs/libobjc.${shlib_ext}]
149       }
150       if { $libobjc_dir == ""} {
151           set libobjc_dir \
152               [lookfor_file ${objcpath} libobjc/.libs/libobjc-gnu.${shlib_ext}]
153       }
154
155       verbose "libobjc_dir: $libobjc_dir"
156
157       if { $libobjc_dir != "" } {
158           set libobjc_dir [file dirname ${libobjc_dir}]
159           append flags "-L${libobjc_dir}"
160           append ld_library_path ":${libobjc_dir}"
161       }
162       append ld_library_path \
163           [gcc-set-multilib-library-path $OBJCXX_UNDER_TEST]
164
165     } else {
166       global tool_root_dir;
167
168       set libgpp [lookfor_file ${tool_root_dir} libg++];
169       if { $libgpp != "" } {
170           append flags "-L${libgpp} ";
171           append ld_library_path ":${libgpp}"
172       }
173       set libstdcpp [lookfor_file ${tool_root_dir} libstdc++];
174       if { $libstdcpp != "" } {
175           append flags "-L${libstdcpp} ";
176           append ld_library_path ":${libstdcpp}"
177       }
178       set libiberty [lookfor_file ${tool_root_dir} libiberty];
179       if { $libiberty != "" } {
180           append flags "-L${libiberty} ";
181       }
182       set librx [lookfor_file ${tool_root_dir} librx];
183       if { $librx != "" } {
184           append flags "-L${librx} ";
185       }
186     }
187
188     set_ld_library_path_env_vars
189
190     return "$flags"
191 }
192
193 #
194 # obj-c++_init -- called at the start of each subdir of tests
195 #
196
197 proc obj-c++_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_OBJCXXFLAGS
206     global TOOL_EXECUTABLE TOOL_OPTIONS
207     global OBJCXX_UNDER_TEST
208     global TESTING_IN_BUILD_TREE
209     global target_triplet
210
211     if ![info exists OBJCXX_UNDER_TEST] then {
212         if [info exists TOOL_EXECUTABLE] {
213             set OBJCXX_UNDER_TEST $TOOL_EXECUTABLE;
214         } else {
215             if { [is_remote host] || ! [info exists TESTING_IN_BUILD_TREE] } {
216                 set OBJCXX_UNDER_TEST [transform c++]
217             } else {
218                 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++]]]
219             }
220         }
221     }
222
223     # Bleah, nasty. Bad taste.
224     if [ishost "*-dos-*" ] {
225         regsub "c\\+\\+" "$OBJCXX_UNDER_TEST" "gcc" OBJCXX_UNDER_TEST
226     }
227
228     if ![is_remote host] {
229         if { [which $OBJCXX_UNDER_TEST] == 0 } then {
230             perror "OBJCXX_UNDER_TEST ($OBJCXX_UNDER_TEST) does not exist"
231             exit 1
232         }
233     }
234     if ![info exists tmpdir] {
235         set tmpdir "/tmp"
236     }
237
238     if [info exists gluefile] {
239         unset gluefile
240     }
241
242     obj-c++_maybe_build_wrapper "${tmpdir}/obj-c++-testglue.o" "-fexceptions"
243
244     set ALWAYS_OBJCXXFLAGS ""
245
246     if ![is_remote host] {
247         if [info exists TOOL_OPTIONS] {
248             lappend ALWAYS_OBJCXXFLAGS "additional_flags=[obj-c++_include_flags [get_multilibs ${TOOL_OPTIONS}] ]";
249             lappend ALWAYS_OBJCXXFLAGS "ldflags=[obj-c++_link_flags [get_multilibs ${TOOL_OPTIONS}] ]";
250         } else {
251             lappend ALWAYS_OBJCXXFLAGS "additional_flags=[obj-c++_include_flags [get_multilibs] ]";
252             lappend ALWAYS_OBJCXXFLAGS "ldflags=[obj-c++_link_flags [get_multilibs] ]";
253         }
254     }
255
256     if [info exists TOOL_OPTIONS] {
257         lappend ALWAYS_OBJCXXFLAGS "additional_flags=$TOOL_OPTIONS";
258     }
259
260     # Make sure that lines are not wrapped.  That can confuse the
261     # error-message parsing machinery.
262     lappend ALWAYS_OBJCXXFLAGS "additional_flags=-fmessage-length=0"
263
264     if { [string match "*-*-darwin*" $target_triplet] } {
265         lappend ALWAYS_OBJCXXFLAGS "ldflags=-multiply_defined suppress"
266        }
267
268     verbose -log "ALWAYS_OBJCXXFLAGS set to $ALWAYS_OBJCXXFLAGS"
269
270     verbose "obj-c++ is initialized" 3
271 }
272
273 #
274 # obj-c++_target_compile -- compile a source file
275 #
276
277 proc obj-c++_target_compile { source dest type options } {
278     global tmpdir
279     global srcdir
280     global gpp_compile_options
281     global gluefile wrap_flags
282     global ALWAYS_OBJCXXFLAGS
283     global OBJCXX_UNDER_TEST
284     global shlib_ext
285
286     lappend options "libs=-lobjc"
287     set shlib_ext [get_shlib_extension]
288     verbose "shared lib extension: $shlib_ext"
289
290     if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
291         lappend options "libs=${gluefile}"
292         lappend options "ldflags=${wrap_flags}"
293     }
294
295     # If we have built libobjc along with the compiler (which usually
296     # _is not_ the case on Mac OS X systems), point the test harness
297     # at it (and associated headers).
298
299     set objcpath "[get_multilibs]"
300
301     set libobjc_dir [lookfor_file ${objcpath} libobjc/.libs/libobjc.a]
302     if { $libobjc_dir == ""} {
303       verbose "see if we have -fgnu-runtime in options"
304       if [regexp ".*-fgnu-runtime.*" "${options}" ] {
305           set libobjc_dir [lookfor_file ${objcpath} libobjc/.libs/libobjc-gnu.a]
306       }
307     }
308     if { $libobjc_dir == ""} {
309         set libobjc_dir \
310             [lookfor_file ${objcpath} libobjc/.libs/libobjc.${shlib_ext}]
311     }
312     if { $libobjc_dir == ""} {
313         verbose "see if we have -fgnu-runtime in options"
314         if [regexp ".*-fgnu-runtime.*" "${options}"] {
315          set libobjc_dir \
316              [lookfor_file ${objcpath} libobjc/.libs/libobjc-gnu.${shlib_ext}]
317         }
318     }
319
320     if { $libobjc_dir != "" } {
321         set objc_include_dir "${srcdir}/../../libobjc"
322         lappend options "additional_flags=-I${objc_include_dir}"
323     }
324
325     lappend options "additional_flags=[libio_include_flags]"
326     lappend options "compiler=$OBJCXX_UNDER_TEST";
327
328     set options [concat $gpp_compile_options $options]
329
330     set options [concat "$ALWAYS_OBJCXXFLAGS" $options];
331
332     if { [regexp "(^| )-frepo( |$)" $options] && \
333          [regexp "\.o(|bj)$" $dest] } then {
334         regsub "\.o(|bj)$" $dest ".rpo" rponame
335         exec rm -f $rponame
336     }
337
338     set options [dg-additional-files-options $options $source]
339
340     set result [target_compile $source $dest $type $options]
341
342     return $result
343 }
344
345 #
346 # ${tool}_option_help
347 #
348
349 proc ${tool}_option_help { } {
350     send_user " --additional_options,OPTIONS\t\tUse OPTIONS to compile the testcase files. OPTIONS should be comma-separated.\n"
351 }
352
353 #
354 # ${tool}_option_proc
355 #
356
357 proc ${tool}_option_proc { option } {
358     if [regexp "^--additional_options," $option] {
359         global gpp_compile_options
360         regsub "--additional_options," $option "" option
361         foreach x [split $option ","] {
362             lappend gpp_compile_options "additional_flags=$x"
363         }
364         return 1;
365     } else {
366         return 0
367     }
368 }