OSDN Git Service

gcc/
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / lib / objc.exp
1 # Copyright (C) 1992, 1993, 1994, 1996, 1997, 2000, 2001, 2002, 2004, 2005,
2 # 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 # Currently maintained by Doug Evans (dje@cygnus.com)
20
21 # This file is loaded by the tool init file (eg: unix.exp).  It provides
22 # default definitions for objc_start, etc. and other supporting cast members.
23
24 # These globals are used by objc_start if no compiler arguments are provided.
25 # They are also used by the various testsuites to define the environment:
26 # where to find stdio.h, libc.a, etc.
27
28 load_lib libgloss.exp
29 load_lib prune.exp
30 load_lib gcc-defs.exp
31 load_lib timeout.exp
32 load_lib target-libpath.exp
33
34 #
35 # OBJC_UNDER_TEST is the compiler under test.
36 #
37
38 #
39 # default_objc_version -- extract and print the version number of the compiler
40 #
41
42 proc default_objc_version { } {
43     global OBJC_UNDER_TEST
44
45     objc_init
46
47     # ignore any arguments after the command
48     set compiler [lindex $OBJC_UNDER_TEST 0]
49
50     if ![is_remote host] {
51         set compiler_name [which $compiler]
52     } else {
53         set compiler_name $compiler
54     }
55
56     # verify that the compiler exists
57     if { $compiler_name != 0 } then {
58         set tmp [remote_exec host "$compiler -v"]
59         set status [lindex $tmp 0]
60         set output [lindex $tmp 1]
61         regexp " version \[^\n\r\]*" $output version
62         if { $status == 0 && [info exists version] } then {
63             clone_output "$compiler_name $version\n"
64         } else {
65             clone_output "Couldn't determine version of $compiler_name: $output\n"
66         }
67     } else {
68         # compiler does not exist (this should have already been detected)
69         warning "$compiler does not exist"
70     }
71 }
72
73 #
74 # Call objc_version. We do it this way so we can override it if needed.
75 #
76 proc objc_version { } {
77     default_objc_version
78 }
79
80 #
81 # objc_init -- called at the start of each .exp script.
82 #
83 # There currently isn't much to do, but always using it allows us to
84 # make some enhancements without having to go back and rewrite the scripts.
85 #
86
87 set objc_initialized 0
88
89 proc objc_init { args } {
90     global rootme
91     global tmpdir
92     global libdir
93     global gluefile wrap_flags
94     global objc_initialized
95     global OBJC_UNDER_TEST
96     global TOOL_EXECUTABLE
97     global objc_libgcc_s_path
98
99     # We set LC_ALL and LANG to C so that we get the same error messages as expected.
100     setenv LC_ALL C
101     setenv LANG C
102
103     if { $objc_initialized == 1 } { return; }
104
105     if ![info exists OBJC_UNDER_TEST] then {
106         if [info exists TOOL_EXECUTABLE] {
107             set OBJC_UNDER_TEST $TOOL_EXECUTABLE
108         } else {
109             set OBJC_UNDER_TEST [find_gcc]
110         }
111     }
112
113     if ![info exists tmpdir] then {
114         set tmpdir /tmp
115     }
116
117     objc_maybe_build_wrapper "${tmpdir}/objc-testglue.o"
118
119     set objc_libgcc_s_path [gcc-set-multilib-library-path $OBJC_UNDER_TEST]
120 }
121
122 proc objc_target_compile { source dest type options } {
123     global rootme
124     global tmpdir
125     global gluefile wrap_flags
126     global srcdir
127     global OBJC_UNDER_TEST
128     global TOOL_OPTIONS
129     global ld_library_path
130     global objc_libgcc_s_path
131     global shlib_ext
132
133     set ld_library_path ".:${objc_libgcc_s_path}"
134     lappend options "libs=-lobjc"
135     set shlib_ext [get_shlib_extension]
136     verbose "shared lib extension: $shlib_ext"
137
138     if { [target_info needs_status_wrapper]!="" && [info exists gluefile] } {
139         lappend options "libs=${gluefile}"
140         lappend options "ldflags=$wrap_flags"
141     }
142
143     if [target_info exists objc,stack_size] {
144         lappend options "additional_flags=-DSTACK_SIZE=[target_info objc,stack_size]"
145     }
146     if [target_info exists objc,no_trampolines] {
147         lappend options "additional_flags=-DNO_TRAMPOLINES"
148     }
149     if [target_info exists objc,no_label_values] {
150         lappend options "additional_flags=-DNO_LABEL_VALUES"
151     }
152     # TOOL_OPTIONS must come first, so that it doesn't override testcase
153     # specific options.
154     if [info exists TOOL_OPTIONS] {
155         set options [concat "{additional_flags=$TOOL_OPTIONS}" $options]
156     }
157
158     # If we have built libobjc along with the compiler (which usually
159     # _is not_ the case on Mac OS X systems), point the test harness
160     # at it (and associated headers).
161
162     set objcpath "[get_multilibs]"
163
164     set libobjc_dir [lookfor_file ${objcpath} libobjc/.libs/libobjc.a]
165     if { $libobjc_dir == ""} {
166       verbose "see if we have -fgnu-runtime in options"
167       if [regexp ".*-fgnu-runtime.*" "${options}"] {
168         set libobjc_dir [lookfor_file ${objcpath} libobjc/.libs/libobjc-gnu.a]
169       }
170     }
171     # Now check if we have a shared only build.
172     if { $libobjc_dir == ""} {
173      set libobjc_dir \
174          [lookfor_file ${objcpath} libobjc/.libs/libobjc.${shlib_ext}]
175     }
176     if { $libobjc_dir == ""} {
177         verbose "see if we have -fgnu-runtime in options"
178         if [regexp ".*-fgnu-runtime.*" "${options}"] {
179          set libobjc_dir \
180              [lookfor_file ${objcpath} libobjc/.libs/libobjc-gnu.${shlib_ext}]
181         }
182     }
183     if { $libobjc_dir != "" } {
184         set objc_include_dir "${srcdir}/../../libobjc"
185         lappend options "additional_flags=-I${objc_include_dir}"
186         set libobjc_dir [file dirname ${libobjc_dir}]
187         set objc_link_flags "-L${libobjc_dir}"
188         lappend options "additional_flags=${objc_link_flags}"
189         append ld_library_path ":${libobjc_dir}"
190     }
191     if { $type == "precompiled_header" } {
192         # If we generating a precompiled header, we have say this is an
193         # objective-C header
194         set source [concat "-x objective-c-header" $source]
195     }
196     lappend options "compiler=$OBJC_UNDER_TEST"
197     lappend options "timeout=[timeout_value]
198
199     set_ld_library_path_env_vars
200
201     return [target_compile $source $dest $type $options]
202 }
203
204 #
205 # objc_pass -- utility to record a testcase passed
206 #
207
208 proc objc_pass { testcase cflags } {
209     if { "$cflags" == "" } {
210         pass "$testcase"
211     } else {
212         pass "$testcase, $cflags"
213     }
214 }
215
216 #
217 # objc_fail -- utility to record a testcase failed
218 #
219
220 proc objc_fail { testcase cflags } {
221     if { "$cflags" == "" } {
222         fail "$testcase"
223     } else {
224         fail "$testcase, $cflags"
225     }
226 }
227
228 #
229 # objc_finish -- called at the end of every .exp script that calls objc_init
230 #
231 # The purpose of this proc is to hide all quirks of the testing environment
232 # from the testsuites.  It also exists to undo anything that objc_init did
233 # (that needs undoing).
234 #
235
236 proc objc_finish { } {
237     # The testing harness apparently requires this.
238     global errorInfo
239
240     if [info exists errorInfo] then {
241         unset errorInfo
242     }
243
244     # Might as well reset these (keeps our caller from wondering whether
245     # s/he has to or not).
246     global prms_id bug_id
247     set prms_id 0
248     set bug_id 0
249 }
250
251 proc objc_exit { } {
252     global gluefile
253
254     if [info exists gluefile] {
255         file_on_build delete $gluefile
256         unset gluefile
257     }
258 }
259     
260 # If this is an older version of dejagnu (without runtest_file_p),
261 # provide one and assume the old syntax: foo1.exp bar1.c foo2.exp bar2.c.
262 # This can be deleted after next dejagnu release.
263
264 if { [info procs runtest_file_p] == "" } then {
265     proc runtest_file_p { runtests testcase } {
266         if { $runtests != "" && [regexp "\[.\]\[cC\]" $runtests] } then {
267             if { [lsearch $runtests [file tail $testcase]] >= 0 } then {
268                 return 1
269             } else {
270                 return 0
271             }
272         }
273         return 1
274     }
275 }
276
277 # Provide a definition of this if missing (delete after next dejagnu release).
278
279 if { [info procs prune_warnings] == "" } then {
280     proc prune_warnings { text } {
281         return $text
282     }
283 }
284
285 # Utility used by mike-gcc.exp and c-torture.exp.
286 # Check the compiler(/assembler/linker) output for text indicating that
287 # the testcase should be marked as "unsupported".
288 #
289 # When dealing with a large number of tests, it's difficult to weed out the
290 # ones that are too big for a particular cpu (eg: 16 bit with a small amount
291 # of memory).  There are various ways to deal with this.  Here's one.
292 # Fortunately, all of the cases where this is likely to happen will be using
293 # gld so we can tell what the error text will look like.
294
295 proc ${tool}_check_unsupported_p { output } {
296     if [regexp "(^|\n)\[^\n\]*: region \[^\n\]* is full" $output] {
297         return "memory full"
298     }
299     return ""
300 }
301
302 # Prune messages from objc that aren't useful.
303
304 proc prune_objc_output { text } {
305     #send_user "Before:$text\n"
306     regsub -all "(^|\n)\[^\n\]*: In (function|method) \[^\n\]*" $text "" text
307     regsub -all "(^|\n)\[^\n\]*: At top level:\[^\n\]*" $text "" text
308
309     # It would be nice to avoid passing anything to objc that would cause it to
310     # issue these messages (since ignoring them seems like a hack on our part),
311     # but that's too difficult in the general case.  For example, sometimes
312     # you need to use -B to point objc at crt0.o, but there are some targets
313     # that don't have crt0.o.
314     regsub -all "(^|\n)\[^\n\]*file path prefix \[^\n\]* never used" $text "" text
315     regsub -all "(^|\n)\[^\n\]*linker input file unused since linking not done" $text "" text
316
317     #send_user "After:$text\n"
318
319     return $text
320 }
321