OSDN Git Service

gcc/
[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 timeout.exp
27 load_lib target-libpath.exp
28
29 #
30 # OBJCXX_UNDER_TEST is the compiler under test.
31 #
32
33
34 set gpp_compile_options ""
35
36 #
37 # obj-c++_version -- extract and print the version number of the compiler
38 #
39
40 proc obj-c++_version { } {
41     global OBJCXX_UNDER_TEST
42     
43     obj-c++_init
44
45     # ignore any arguments after the command
46     set compiler [lindex $OBJCXX_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 # obj-c++_include_flags -- provide new version of obj-c++_include_flags
71 # (originally from libgloss.exp) which knows about the gcc tree structure
72 #
73 proc obj-c++_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 # obj-c++_link_flags -- provide new version of obj-c++_link_flags
96 # (originally from libgloss.exp) which knows about the gcc tree structure
97 #
98
99 proc obj-c++_link_flags { paths } {
100     global rootme
101     global srcdir
102     global ld_library_path
103     global OBJCXX_UNDER_TEST
104     global shlib_ext
105
106     set gccpath ${paths}
107     set libio_dir ""
108     set flags ""
109     set ld_library_path "."
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       if [file exists "${gccpath}/libiberty/libiberty.a"] {
135           append flags "-L${gccpath}/libiberty "
136       }
137       if [file exists "${gccpath}/librx/librx.a"] {
138           append flags "-L${gccpath}/librx "
139       }
140
141       set objcpath "[get_multilibs]"
142       set libobjc_dir [lookfor_file ${objcpath} libobjc/.libs/libobjc.a]
143       if { $libobjc_dir == ""} {
144           set libobjc_dir [lookfor_file ${objcpath} libobjc/.libs/libobjc-gnu.a]
145       }
146       # Now check if we have a shared only build.
147       if { $libobjc_dir == ""} {
148           set libobjc_dir \
149               [lookfor_file ${objcpath} libobjc/.libs/libobjc.${shlib_ext}]
150       }
151       if { $libobjc_dir == ""} {
152           set libobjc_dir \
153               [lookfor_file ${objcpath} libobjc/.libs/libobjc-gnu.${shlib_ext}]
154       }
155
156       verbose "libobjc_dir: $libobjc_dir"
157
158       if { $libobjc_dir != "" } {
159           set libobjc_dir [file dirname ${libobjc_dir}]
160           append flags "-L${libobjc_dir}"
161           append ld_library_path ":${libobjc_dir}"
162       }
163       append ld_library_path \
164           [gcc-set-multilib-library-path $OBJCXX_UNDER_TEST]
165
166     } else {
167       global tool_root_dir;
168
169       set libgpp [lookfor_file ${tool_root_dir} libg++];
170       if { $libgpp != "" } {
171           append flags "-L${libgpp} ";
172           append ld_library_path ":${libgpp}"
173       }
174       set libstdcpp [lookfor_file ${tool_root_dir} libstdc++];
175       if { $libstdcpp != "" } {
176           append flags "-L${libstdcpp} ";
177           append ld_library_path ":${libstdcpp}"
178       }
179       set libiberty [lookfor_file ${tool_root_dir} libiberty];
180       if { $libiberty != "" } {
181           append flags "-L${libiberty} ";
182       }
183       set librx [lookfor_file ${tool_root_dir} librx];
184       if { $librx != "" } {
185           append flags "-L${librx} ";
186       }
187     }
188
189     set_ld_library_path_env_vars
190
191     return "$flags"
192 }
193
194 #
195 # obj-c++_init -- called at the start of each subdir of tests
196 #
197
198 proc obj-c++_init { args } {
199     global subdir
200     global gpp_initialized
201     global base_dir
202     global tmpdir
203     global libdir
204     global gluefile wrap_flags;
205     global objdir srcdir
206     global ALWAYS_OBJCXXFLAGS
207     global TOOL_EXECUTABLE TOOL_OPTIONS
208     global OBJCXX_UNDER_TEST
209     global TESTING_IN_BUILD_TREE
210     global target_triplet
211
212     if ![info exists OBJCXX_UNDER_TEST] then {
213         if [info exists TOOL_EXECUTABLE] {
214             set OBJCXX_UNDER_TEST $TOOL_EXECUTABLE;
215         } else {
216             if { [is_remote host] || ! [info exists TESTING_IN_BUILD_TREE] } {
217                 set OBJCXX_UNDER_TEST [transform c++]
218             } else {
219                 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++]]]
220             }
221         }
222     }
223
224     # Bleah, nasty. Bad taste.
225     if [ishost "*-dos-*" ] {
226         regsub "c\\+\\+" "$OBJCXX_UNDER_TEST" "gcc" OBJCXX_UNDER_TEST
227     }
228
229     if ![is_remote host] {
230         if { [which $OBJCXX_UNDER_TEST] == 0 } then {
231             perror "OBJCXX_UNDER_TEST ($OBJCXX_UNDER_TEST) does not exist"
232             exit 1
233         }
234     }
235     if ![info exists tmpdir] {
236         set tmpdir "/tmp"
237     }
238
239     if [info exists gluefile] {
240         unset gluefile
241     }
242
243     obj-c++_maybe_build_wrapper "${tmpdir}/obj-c++-testglue.o" "-fexceptions"
244
245     set ALWAYS_OBJCXXFLAGS ""
246
247     if ![is_remote host] {
248         if [info exists TOOL_OPTIONS] {
249             lappend ALWAYS_OBJCXXFLAGS "additional_flags=[obj-c++_include_flags [get_multilibs ${TOOL_OPTIONS}] ]";
250             lappend ALWAYS_OBJCXXFLAGS "ldflags=[obj-c++_link_flags [get_multilibs ${TOOL_OPTIONS}] ]";
251         } else {
252             lappend ALWAYS_OBJCXXFLAGS "additional_flags=[obj-c++_include_flags [get_multilibs] ]";
253             lappend ALWAYS_OBJCXXFLAGS "ldflags=[obj-c++_link_flags [get_multilibs] ]";
254         }
255     }
256
257     if [info exists TOOL_OPTIONS] {
258         lappend ALWAYS_OBJCXXFLAGS "additional_flags=$TOOL_OPTIONS";
259     }
260
261     # Make sure that lines are not wrapped.  That can confuse the
262     # error-message parsing machinery.
263     lappend ALWAYS_OBJCXXFLAGS "additional_flags=-fmessage-length=0"
264
265     if { [string match "*-*-darwin*" $target_triplet] } {
266         lappend ALWAYS_OBJCXXFLAGS "ldflags=-multiply_defined suppress"
267        }
268
269     verbose -log "ALWAYS_OBJCXXFLAGS set to $ALWAYS_OBJCXXFLAGS"
270
271     verbose "obj-c++ is initialized" 3
272 }
273
274 #
275 # obj-c++_target_compile -- compile a source file
276 #
277
278 proc obj-c++_target_compile { source dest type options } {
279     global tmpdir
280     global srcdir
281     global gpp_compile_options
282     global gluefile wrap_flags
283     global ALWAYS_OBJCXXFLAGS
284     global OBJCXX_UNDER_TEST
285     global shlib_ext
286
287     lappend options "libs=-lobjc"
288     set shlib_ext [get_shlib_extension]
289     verbose "shared lib extension: $shlib_ext"
290
291     if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
292         lappend options "libs=${gluefile}"
293         lappend options "ldflags=${wrap_flags}"
294     }
295
296     # If we have built libobjc along with the compiler (which usually
297     # _is not_ the case on Mac OS X systems), point the test harness
298     # at it (and associated headers).
299
300     set objcpath "[get_multilibs]"
301
302     set libobjc_dir [lookfor_file ${objcpath} libobjc/.libs/libobjc.a]
303     if { $libobjc_dir == ""} {
304       verbose "see if we have -fgnu-runtime in options"
305       if [regexp ".*-fgnu-runtime.*" "${options}" ] {
306           set libobjc_dir [lookfor_file ${objcpath} libobjc/.libs/libobjc-gnu.a]
307       }
308     }
309     if { $libobjc_dir == ""} {
310         set libobjc_dir \
311             [lookfor_file ${objcpath} libobjc/.libs/libobjc.${shlib_ext}]
312     }
313     if { $libobjc_dir == ""} {
314         verbose "see if we have -fgnu-runtime in options"
315         if [regexp ".*-fgnu-runtime.*" "${options}"] {
316          set libobjc_dir \
317              [lookfor_file ${objcpath} libobjc/.libs/libobjc-gnu.${shlib_ext}]
318         }
319     }
320
321     if { $libobjc_dir != "" } {
322         set objc_include_dir "${srcdir}/../../libobjc"
323         lappend options "additional_flags=-I${objc_include_dir}"
324     }
325
326     lappend options "additional_flags=[libio_include_flags]"
327     lappend options "compiler=$OBJCXX_UNDER_TEST";
328     lappend options "timeout=[timeout_value]"
329
330     set options [concat $gpp_compile_options $options]
331
332     set options [concat "$ALWAYS_OBJCXXFLAGS" $options];
333
334     if { [regexp "(^| )-frepo( |$)" $options] && \
335          [regexp "\.o(|bj)$" $dest] } then {
336         regsub "\.o(|bj)$" $dest ".rpo" rponame
337         exec rm -f $rponame
338     }
339
340     set options [dg-additional-files-options $options $source]
341
342     set result [target_compile $source $dest $type $options]
343
344     return $result
345 }
346
347 #
348 # ${tool}_option_help
349 #
350
351 proc ${tool}_option_help { } {
352     send_user " --additional_options,OPTIONS\t\tUse OPTIONS to compile the testcase files. OPTIONS should be comma-separated.\n"
353 }
354
355 #
356 # ${tool}_option_proc
357 #
358
359 proc ${tool}_option_proc { option } {
360     if [regexp "^--additional_options," $option] {
361         global gpp_compile_options
362         regsub "--additional_options," $option "" option
363         foreach x [split $option ","] {
364             lappend gpp_compile_options "additional_flags=$x"
365         }
366         return 1;
367     } else {
368         return 0
369     }
370 }