]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/testsuite/lib/objc.exp
Update copyright years in gcc/
[thirdparty/gcc.git] / gcc / testsuite / lib / objc.exp
CommitLineData
23a5b65a 1# Copyright (C) 1992-2014 Free Software Foundation, Inc.
d636ae0b
OP
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
cd976c16 5# the Free Software Foundation; either version 3 of the License, or
d636ae0b 6# (at your option) any later version.
2e58f311 7#
d636ae0b
OP
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.
2e58f311 12#
d636ae0b 13# You should have received a copy of the GNU General Public License
cd976c16
NC
14# along with GCC; see the file COPYING3. If not see
15# <http://www.gnu.org/licenses/>.
d636ae0b
OP
16
17# This file was written by Rob Savoye (rob@cygnus.com)
18# Currently maintained by Doug Evans (dje@cygnus.com)
19
20# This file is loaded by the tool init file (eg: unix.exp). It provides
21# default definitions for objc_start, etc. and other supporting cast members.
22
23# These globals are used by objc_start if no compiler arguments are provided.
24# They are also used by the various testsuites to define the environment:
25# where to find stdio.h, libc.a, etc.
26
47ffd48a
SS
27load_lib libgloss.exp
28load_lib prune.exp
29load_lib gcc-defs.exp
d4038ca2 30load_lib timeout.exp
1df8e834 31load_lib target-libpath.exp
47ffd48a 32
d636ae0b
OP
33#
34# OBJC_UNDER_TEST is the compiler under test.
35#
36
37#
38# default_objc_version -- extract and print the version number of the compiler
39#
40
41proc default_objc_version { } {
42 global OBJC_UNDER_TEST
43
11289ef9 44 objc_init
d636ae0b 45
9debda96 46 # Ignore any arguments after the command.
d636ae0b
OP
47 set compiler [lindex $OBJC_UNDER_TEST 0]
48
49 if ![is_remote host] {
11289ef9 50 set compiler_name [which $compiler]
d636ae0b 51 } else {
11289ef9 52 set compiler_name $compiler
d636ae0b
OP
53 }
54
9debda96 55 # Verify that the compiler exists.
d636ae0b
OP
56 if { $compiler_name != 0 } then {
57 set tmp [remote_exec host "$compiler -v"]
11289ef9
BE
58 set status [lindex $tmp 0]
59 set output [lindex $tmp 1]
fb0737c2 60 regexp " version \[^\n\r\]*" $output version
d636ae0b
OP
61 if { $status == 0 && [info exists version] } then {
62 clone_output "$compiler_name $version\n"
63 } else {
64 clone_output "Couldn't determine version of $compiler_name: $output\n"
65 }
66 } else {
9debda96 67 # Compiler does not exist (this should have already been detected).
d636ae0b
OP
68 warning "$compiler does not exist"
69 }
70}
71
72#
73# Call objc_version. We do it this way so we can override it if needed.
74#
75proc objc_version { } {
11289ef9 76 default_objc_version
d636ae0b
OP
77}
78
79#
80# objc_init -- called at the start of each .exp script.
81#
82# There currently isn't much to do, but always using it allows us to
83# make some enhancements without having to go back and rewrite the scripts.
84#
85
86set objc_initialized 0
87
88proc objc_init { args } {
2937267b 89 global rootme
d636ae0b
OP
90 global tmpdir
91 global libdir
92 global gluefile wrap_flags
93 global objc_initialized
94 global OBJC_UNDER_TEST
95 global TOOL_EXECUTABLE
2937267b 96 global objc_libgcc_s_path
512e7d7f
DA
97 global gcc_warning_prefix
98 global gcc_error_prefix
d636ae0b 99
9debda96
IS
100 # We set LC_ALL and LANG to C so that we get the same error messages as
101 # expected.
690e11b8
AP
102 setenv LC_ALL C
103 setenv LANG C
104
17f35e23
DK
105 # Many hosts now default to a non-ASCII C locale, however, so
106 # they can set a charset encoding here if they need.
107 if { [ishost "*-*-cygwin*"] } {
108 setenv LC_ALL C.ASCII
109 setenv LANG C.ASCII
110 }
111
d636ae0b
OP
112 if { $objc_initialized == 1 } { return; }
113
114 if ![info exists OBJC_UNDER_TEST] then {
115 if [info exists TOOL_EXECUTABLE] {
11289ef9 116 set OBJC_UNDER_TEST $TOOL_EXECUTABLE
d636ae0b
OP
117 } else {
118 set OBJC_UNDER_TEST [find_gcc]
119 }
120 }
121
122 if ![info exists tmpdir] then {
123 set tmpdir /tmp
124 }
8800e533 125
512e7d7f
DA
126 set gcc_warning_prefix "warning:"
127 set gcc_error_prefix "error:"
128
8800e533 129 objc_maybe_build_wrapper "${tmpdir}/objc-testglue.o"
2937267b 130
33cde516 131 set objc_libgcc_s_path [gcc-set-multilib-library-path $OBJC_UNDER_TEST]
d636ae0b
OP
132}
133
134proc objc_target_compile { source dest type options } {
11289ef9
BE
135 global rootme
136 global tmpdir
137 global gluefile wrap_flags
bbeb33f2 138 global srcdir
d636ae0b
OP
139 global OBJC_UNDER_TEST
140 global TOOL_OPTIONS
822c7fe2 141 global ld_library_path
2937267b 142 global objc_libgcc_s_path
2e58f311 143 global shlib_ext
c875f596 144 global TEST_ALWAYS_FLAGS
9debda96
IS
145
146 set shlib_ext [get_shlib_extension]
33cde516 147 set ld_library_path ".:${objc_libgcc_s_path}"
9debda96
IS
148
149 # We have to figure out which runtime will be used on darwin because
150 # we need to add the include path for the gnu runtime if that is in
151 # use.
152 # First set the default...
19073ebc 153 if { [istarget *-*-darwin*] } {
9debda96
IS
154 set nextruntime 1
155 } else {
156 set nextruntime 0
157 }
158 verbose "initial next runtime state : $nextruntime" 2
159 # Next, see if we define the option in dg-options...
160 foreach opt $options {
161 if [regexp ".*-fnext-runtime.*" $opt] {
162 set nextruntime 1
163 }
164 if [regexp ".*-fgnu-runtime.*" $opt] {
165 set nextruntime 0
166 }
167 }
168 verbose "next runtime state after dg opts: $nextruntime" 2
169
170 set tgt [target_info name]
171 if [board_info $tgt exists multilib_flags] {
172 set lb [board_info $tgt multilib_flags]
173 verbose "board multilib_flags $lb" 2
174 foreach opt $lb {
175 if [regexp ".*-fnext-runtime.*" $opt] {
176 set nextruntime 1
177 }
178 if [regexp ".*-fgnu-runtime.*" $opt] {
179 set nextruntime 0
180 }
181 }
182 }
183 verbose "next runtime state after any multilib opts: $nextruntime" 2
184
d636ae0b 185 lappend options "libs=-lobjc"
9debda96 186 verbose "shared lib extension: $shlib_ext" 3
822c7fe2 187
d636ae0b
OP
188 if { [target_info needs_status_wrapper]!="" && [info exists gluefile] } {
189 lappend options "libs=${gluefile}"
190 lappend options "ldflags=$wrap_flags"
191 }
192
193 if [target_info exists objc,stack_size] {
194 lappend options "additional_flags=-DSTACK_SIZE=[target_info objc,stack_size]"
195 }
196 if [target_info exists objc,no_trampolines] {
197 lappend options "additional_flags=-DNO_TRAMPOLINES"
198 }
199 if [target_info exists objc,no_label_values] {
200 lappend options "additional_flags=-DNO_LABEL_VALUES"
201 }
c875f596
DN
202
203 # TEST_ALWAYS_FLAGS are flags that should be passed to every
204 # compilation. They are passed first to allow individual
205 # tests to override them.
206 if [info exists TEST_ALWAYS_FLAGS] {
207 set options [concat "{additional_flags=$TEST_ALWAYS_FLAGS}" $options]
208 }
209
8a434e1d
KC
210 # TOOL_OPTIONS must come first, so that it doesn't override testcase
211 # specific options.
d636ae0b 212 if [info exists TOOL_OPTIONS] {
11289ef9 213 set options [concat "{additional_flags=$TOOL_OPTIONS}" $options]
d636ae0b 214 }
bbeb33f2 215
9debda96 216 # If we have built libobjc along with the compiler, point the test harness
264fa2db 217 # at it (and associated headers).
bbeb33f2 218
047fb009 219 set objcpath "[get_multilibs]"
a8252506 220
e457ca6a 221 set libobjc_dir [lookfor_file ${objcpath} libobjc/.libs/libobjc.a]
9debda96
IS
222 if { $libobjc_dir == "" } {
223 # On darwin there is, potentially, a gnu runtime too.
2e58f311 224 set libobjc_dir [lookfor_file ${objcpath} libobjc/.libs/libobjc-gnu.a]
9debda96
IS
225 }
226 # Perhaps we didn't build static libs.
227 if { $libobjc_dir == "" } {
228 set libobjc_dir [lookfor_file ${objcpath} libobjc/.libs/libobjc.${shlib_ext}]
229 # On darwin there is, potentially, a gnu runtime too.
230 if { $libobjc_dir == "" } {
231 set libobjc_dir [lookfor_file ${objcpath} libobjc/.libs/libobjc-gnu.${shlib_ext}]
2e58f311
AT
232 }
233 }
9debda96 234
047fb009 235 if { $libobjc_dir != "" } {
9debda96
IS
236 # If we are using the gnu runtime, add its includes.
237 if { $nextruntime == 0 } {
238 set objc_include_dir "${srcdir}/../../libobjc"
239 lappend options "additional_flags=-I${objc_include_dir}"
240 verbose "adding gnu runtime include dir: $objc_include_dir "
241 }
822c7fe2 242 set libobjc_dir [file dirname ${libobjc_dir}]
9debda96
IS
243 # Allow for %s spec substitutions..
244 set objc_link_flags " -B${libobjc_dir} "
245 lappend options "additional_flags=${objc_link_flags}"
246 set objc_link_flags " -L${libobjc_dir} "
047fb009 247 lappend options "additional_flags=${objc_link_flags}"
33cde516 248 append ld_library_path ":${libobjc_dir}"
047fb009 249 }
d2f9f9a6
AP
250 if { $type == "precompiled_header" } {
251 # If we generating a precompiled header, we have say this is an
9debda96 252 # objective-C header.
d2f9f9a6
AP
253 set source [concat "-x objective-c-header" $source]
254 }
d636ae0b 255 lappend options "compiler=$OBJC_UNDER_TEST"
32ab0ba4 256 lappend options "timeout=[timeout_value]"
12c3717e 257
1df8e834 258 set_ld_library_path_env_vars
12c3717e 259
5e247ae5
IS
260 set options [dg-additional-files-options $options $source]
261
d636ae0b
OP
262 return [target_compile $source $dest $type $options]
263}
264
265#
9debda96 266# objc_pass -- utility to record a testcase passed.
d636ae0b
OP
267#
268
269proc objc_pass { testcase cflags } {
270 if { "$cflags" == "" } {
271 pass "$testcase"
272 } else {
273 pass "$testcase, $cflags"
274 }
275}
276
277#
278# objc_fail -- utility to record a testcase failed
279#
280
281proc objc_fail { testcase cflags } {
282 if { "$cflags" == "" } {
283 fail "$testcase"
284 } else {
285 fail "$testcase, $cflags"
286 }
287}
288
289#
290# objc_finish -- called at the end of every .exp script that calls objc_init
291#
292# The purpose of this proc is to hide all quirks of the testing environment
293# from the testsuites. It also exists to undo anything that objc_init did
294# (that needs undoing).
295#
296
297proc objc_finish { } {
298 # The testing harness apparently requires this.
11289ef9 299 global errorInfo
d636ae0b
OP
300
301 if [info exists errorInfo] then {
302 unset errorInfo
303 }
304
305 # Might as well reset these (keeps our caller from wondering whether
306 # s/he has to or not).
307 global prms_id bug_id
308 set prms_id 0
309 set bug_id 0
310}
311
312proc objc_exit { } {
11289ef9 313 global gluefile
d636ae0b
OP
314
315 if [info exists gluefile] {
11289ef9
BE
316 file_on_build delete $gluefile
317 unset gluefile
d636ae0b
OP
318 }
319}
320
321# If this is an older version of dejagnu (without runtest_file_p),
322# provide one and assume the old syntax: foo1.exp bar1.c foo2.exp bar2.c.
323# This can be deleted after next dejagnu release.
324
325if { [info procs runtest_file_p] == "" } then {
326 proc runtest_file_p { runtests testcase } {
327 if { $runtests != "" && [regexp "\[.\]\[cC\]" $runtests] } then {
328 if { [lsearch $runtests [file tail $testcase]] >= 0 } then {
329 return 1
330 } else {
331 return 0
332 }
333 }
334 return 1
335 }
336}
337
338# Provide a definition of this if missing (delete after next dejagnu release).
339
340if { [info procs prune_warnings] == "" } then {
341 proc prune_warnings { text } {
342 return $text
343 }
344}
345
346# Utility used by mike-gcc.exp and c-torture.exp.
347# Check the compiler(/assembler/linker) output for text indicating that
348# the testcase should be marked as "unsupported".
349#
350# When dealing with a large number of tests, it's difficult to weed out the
351# ones that are too big for a particular cpu (eg: 16 bit with a small amount
352# of memory). There are various ways to deal with this. Here's one.
353# Fortunately, all of the cases where this is likely to happen will be using
354# gld so we can tell what the error text will look like.
355
356proc ${tool}_check_unsupported_p { output } {
357 if [regexp "(^|\n)\[^\n\]*: region \[^\n\]* is full" $output] {
358 return "memory full"
359 }
360 return ""
361}
362
363# Prune messages from objc that aren't useful.
364
365proc prune_objc_output { text } {
366 #send_user "Before:$text\n"
367 regsub -all "(^|\n)\[^\n\]*: In (function|method) \[^\n\]*" $text "" text
368 regsub -all "(^|\n)\[^\n\]*: At top level:\[^\n\]*" $text "" text
369
370 # It would be nice to avoid passing anything to objc that would cause it to
371 # issue these messages (since ignoring them seems like a hack on our part),
372 # but that's too difficult in the general case. For example, sometimes
373 # you need to use -B to point objc at crt0.o, but there are some targets
374 # that don't have crt0.o.
375 regsub -all "(^|\n)\[^\n\]*file path prefix \[^\n\]* never used" $text "" text
376 regsub -all "(^|\n)\[^\n\]*linker input file unused since linking not done" $text "" text
377
378 #send_user "After:$text\n"
379
380 return $text
381}
382