]>
Commit | Line | Data |
---|---|---|
f1717362 | 1 | # Copyright (C) 1992-2016 Free Software Foundation, Inc. |
ff79b0cf | 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 | |
f63ff66b | 5 | # the Free Software Foundation; either version 3 of the License, or |
ff79b0cf | 6 | # (at your option) any later version. |
903355fc | 7 | # |
ff79b0cf | 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. | |
903355fc | 12 | # |
ff79b0cf | 13 | # You should have received a copy of the GNU General Public License |
f63ff66b | 14 | # along with GCC; see the file COPYING3. If not see |
15 | # <http://www.gnu.org/licenses/>. | |
ff79b0cf | 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 | ||
02ba0754 | 27 | load_lib libgloss.exp |
28 | load_lib prune.exp | |
29 | load_lib gcc-defs.exp | |
0557b60a | 30 | load_lib timeout.exp |
c0e31427 | 31 | load_lib target-libpath.exp |
dc8a5e0f | 32 | load_lib target-utils.exp |
02ba0754 | 33 | |
ff79b0cf | 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 | ||
d4213587 | 45 | objc_init |
ff79b0cf | 46 | |
161ed364 | 47 | # Ignore any arguments after the command. |
ff79b0cf | 48 | set compiler [lindex $OBJC_UNDER_TEST 0] |
49 | ||
50 | if ![is_remote host] { | |
d4213587 | 51 | set compiler_name [which $compiler] |
ff79b0cf | 52 | } else { |
d4213587 | 53 | set compiler_name $compiler |
ff79b0cf | 54 | } |
55 | ||
161ed364 | 56 | # Verify that the compiler exists. |
ff79b0cf | 57 | if { $compiler_name != 0 } then { |
58 | set tmp [remote_exec host "$compiler -v"] | |
d4213587 | 59 | set status [lindex $tmp 0] |
60 | set output [lindex $tmp 1] | |
da97e61f | 61 | regexp " version \[^\n\r\]*" $output version |
ff79b0cf | 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 { | |
161ed364 | 68 | # Compiler does not exist (this should have already been detected). |
ff79b0cf | 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 { } { | |
d4213587 | 77 | default_objc_version |
ff79b0cf | 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 } { | |
6af61abe | 90 | global rootme |
ff79b0cf | 91 | global tmpdir |
92 | global libdir | |
93 | global gluefile wrap_flags | |
94 | global objc_initialized | |
95 | global OBJC_UNDER_TEST | |
96 | global TOOL_EXECUTABLE | |
6af61abe | 97 | global objc_libgcc_s_path |
d3207f3f | 98 | global gcc_warning_prefix |
99 | global gcc_error_prefix | |
ff79b0cf | 100 | |
161ed364 | 101 | # We set LC_ALL and LANG to C so that we get the same error messages as |
102 | # expected. | |
e899394f | 103 | setenv LC_ALL C |
104 | setenv LANG C | |
105 | ||
9cf0a538 | 106 | # Many hosts now default to a non-ASCII C locale, however, so |
107 | # they can set a charset encoding here if they need. | |
108 | if { [ishost "*-*-cygwin*"] } { | |
109 | setenv LC_ALL C.ASCII | |
110 | setenv LANG C.ASCII | |
111 | } | |
112 | ||
ff79b0cf | 113 | if { $objc_initialized == 1 } { return; } |
114 | ||
115 | if ![info exists OBJC_UNDER_TEST] then { | |
116 | if [info exists TOOL_EXECUTABLE] { | |
d4213587 | 117 | set OBJC_UNDER_TEST $TOOL_EXECUTABLE |
ff79b0cf | 118 | } else { |
119 | set OBJC_UNDER_TEST [find_gcc] | |
120 | } | |
121 | } | |
122 | ||
123 | if ![info exists tmpdir] then { | |
124 | set tmpdir /tmp | |
125 | } | |
ac8cb22b | 126 | |
d3207f3f | 127 | set gcc_warning_prefix "warning:" |
8f51a05f | 128 | set gcc_error_prefix "(fatal )?error:" |
d3207f3f | 129 | |
ac8cb22b | 130 | objc_maybe_build_wrapper "${tmpdir}/objc-testglue.o" |
6af61abe | 131 | |
f09e0522 | 132 | set objc_libgcc_s_path [gcc-set-multilib-library-path $OBJC_UNDER_TEST] |
ff79b0cf | 133 | } |
134 | ||
135 | proc objc_target_compile { source dest type options } { | |
d4213587 | 136 | global rootme |
137 | global tmpdir | |
138 | global gluefile wrap_flags | |
ded736d4 | 139 | global srcdir |
ff79b0cf | 140 | global OBJC_UNDER_TEST |
141 | global TOOL_OPTIONS | |
ca8d6a9d | 142 | global ld_library_path |
6af61abe | 143 | global objc_libgcc_s_path |
903355fc | 144 | global shlib_ext |
224d9f3d | 145 | global TEST_ALWAYS_FLAGS |
161ed364 | 146 | |
147 | set shlib_ext [get_shlib_extension] | |
f09e0522 | 148 | set ld_library_path ".:${objc_libgcc_s_path}" |
161ed364 | 149 | |
150 | # We have to figure out which runtime will be used on darwin because | |
151 | # we need to add the include path for the gnu runtime if that is in | |
152 | # use. | |
153 | # First set the default... | |
80fad4aa | 154 | if { [istarget *-*-darwin*] } { |
161ed364 | 155 | set nextruntime 1 |
156 | } else { | |
157 | set nextruntime 0 | |
158 | } | |
159 | verbose "initial next runtime state : $nextruntime" 2 | |
160 | # Next, see if we define the option in dg-options... | |
161 | foreach opt $options { | |
162 | if [regexp ".*-fnext-runtime.*" $opt] { | |
163 | set nextruntime 1 | |
164 | } | |
165 | if [regexp ".*-fgnu-runtime.*" $opt] { | |
166 | set nextruntime 0 | |
167 | } | |
168 | } | |
169 | verbose "next runtime state after dg opts: $nextruntime" 2 | |
170 | ||
171 | set tgt [target_info name] | |
172 | if [board_info $tgt exists multilib_flags] { | |
173 | set lb [board_info $tgt multilib_flags] | |
174 | verbose "board multilib_flags $lb" 2 | |
175 | foreach opt $lb { | |
176 | if [regexp ".*-fnext-runtime.*" $opt] { | |
177 | set nextruntime 1 | |
178 | } | |
179 | if [regexp ".*-fgnu-runtime.*" $opt] { | |
180 | set nextruntime 0 | |
181 | } | |
182 | } | |
183 | } | |
184 | verbose "next runtime state after any multilib opts: $nextruntime" 2 | |
185 | ||
ff79b0cf | 186 | lappend options "libs=-lobjc" |
161ed364 | 187 | verbose "shared lib extension: $shlib_ext" 3 |
ca8d6a9d | 188 | |
ff79b0cf | 189 | if { [target_info needs_status_wrapper]!="" && [info exists gluefile] } { |
190 | lappend options "libs=${gluefile}" | |
191 | lappend options "ldflags=$wrap_flags" | |
192 | } | |
193 | ||
194 | if [target_info exists objc,stack_size] { | |
195 | lappend options "additional_flags=-DSTACK_SIZE=[target_info objc,stack_size]" | |
196 | } | |
197 | if [target_info exists objc,no_trampolines] { | |
198 | lappend options "additional_flags=-DNO_TRAMPOLINES" | |
199 | } | |
200 | if [target_info exists objc,no_label_values] { | |
201 | lappend options "additional_flags=-DNO_LABEL_VALUES" | |
202 | } | |
224d9f3d | 203 | |
204 | # TEST_ALWAYS_FLAGS are flags that should be passed to every | |
205 | # compilation. They are passed first to allow individual | |
206 | # tests to override them. | |
207 | if [info exists TEST_ALWAYS_FLAGS] { | |
208 | set options [concat "{additional_flags=$TEST_ALWAYS_FLAGS}" $options] | |
209 | } | |
210 | ||
118a91b1 | 211 | # TOOL_OPTIONS must come first, so that it doesn't override testcase |
212 | # specific options. | |
ff79b0cf | 213 | if [info exists TOOL_OPTIONS] { |
d4213587 | 214 | set options [concat "{additional_flags=$TOOL_OPTIONS}" $options] |
ff79b0cf | 215 | } |
ded736d4 | 216 | |
161ed364 | 217 | # If we have built libobjc along with the compiler, point the test harness |
c17b85ea | 218 | # at it (and associated headers). |
ded736d4 | 219 | |
6a780f1a | 220 | set objcpath "[get_multilibs]" |
370b291b | 221 | |
99d5607a | 222 | set libobjc_dir [lookfor_file ${objcpath} libobjc/.libs/libobjc.a] |
161ed364 | 223 | if { $libobjc_dir == "" } { |
224 | # On darwin there is, potentially, a gnu runtime too. | |
903355fc | 225 | set libobjc_dir [lookfor_file ${objcpath} libobjc/.libs/libobjc-gnu.a] |
161ed364 | 226 | } |
227 | # Perhaps we didn't build static libs. | |
228 | if { $libobjc_dir == "" } { | |
229 | set libobjc_dir [lookfor_file ${objcpath} libobjc/.libs/libobjc.${shlib_ext}] | |
230 | # On darwin there is, potentially, a gnu runtime too. | |
231 | if { $libobjc_dir == "" } { | |
232 | set libobjc_dir [lookfor_file ${objcpath} libobjc/.libs/libobjc-gnu.${shlib_ext}] | |
903355fc | 233 | } |
234 | } | |
161ed364 | 235 | |
6a780f1a | 236 | if { $libobjc_dir != "" } { |
161ed364 | 237 | # If we are using the gnu runtime, add its includes. |
238 | if { $nextruntime == 0 } { | |
239 | set objc_include_dir "${srcdir}/../../libobjc" | |
240 | lappend options "additional_flags=-I${objc_include_dir}" | |
241 | verbose "adding gnu runtime include dir: $objc_include_dir " | |
242 | } | |
ca8d6a9d | 243 | set libobjc_dir [file dirname ${libobjc_dir}] |
161ed364 | 244 | # Allow for %s spec substitutions.. |
245 | set objc_link_flags " -B${libobjc_dir} " | |
246 | lappend options "additional_flags=${objc_link_flags}" | |
247 | set objc_link_flags " -L${libobjc_dir} " | |
6a780f1a | 248 | lappend options "additional_flags=${objc_link_flags}" |
f09e0522 | 249 | append ld_library_path ":${libobjc_dir}" |
6a780f1a | 250 | } |
7eb56ad3 | 251 | if { $type == "precompiled_header" } { |
252 | # If we generating a precompiled header, we have say this is an | |
161ed364 | 253 | # objective-C header. |
7eb56ad3 | 254 | set source [concat "-x objective-c-header" $source] |
255 | } | |
ff79b0cf | 256 | lappend options "compiler=$OBJC_UNDER_TEST" |
ff670bee | 257 | lappend options "timeout=[timeout_value]" |
78b53d56 | 258 | |
c0e31427 | 259 | set_ld_library_path_env_vars |
78b53d56 | 260 | |
c791077c | 261 | set options [dg-additional-files-options $options $source] |
262 | ||
ff79b0cf | 263 | return [target_compile $source $dest $type $options] |
264 | } | |
265 | ||
266 | # | |
161ed364 | 267 | # objc_pass -- utility to record a testcase passed. |
ff79b0cf | 268 | # |
269 | ||
270 | proc objc_pass { testcase cflags } { | |
271 | if { "$cflags" == "" } { | |
272 | pass "$testcase" | |
273 | } else { | |
274 | pass "$testcase, $cflags" | |
275 | } | |
276 | } | |
277 | ||
278 | # | |
279 | # objc_fail -- utility to record a testcase failed | |
280 | # | |
281 | ||
282 | proc objc_fail { testcase cflags } { | |
283 | if { "$cflags" == "" } { | |
284 | fail "$testcase" | |
285 | } else { | |
286 | fail "$testcase, $cflags" | |
287 | } | |
288 | } | |
289 | ||
290 | # | |
291 | # objc_finish -- called at the end of every .exp script that calls objc_init | |
292 | # | |
293 | # The purpose of this proc is to hide all quirks of the testing environment | |
294 | # from the testsuites. It also exists to undo anything that objc_init did | |
295 | # (that needs undoing). | |
296 | # | |
297 | ||
298 | proc objc_finish { } { | |
299 | # The testing harness apparently requires this. | |
d4213587 | 300 | global errorInfo |
ff79b0cf | 301 | |
302 | if [info exists errorInfo] then { | |
303 | unset errorInfo | |
304 | } | |
305 | ||
306 | # Might as well reset these (keeps our caller from wondering whether | |
307 | # s/he has to or not). | |
308 | global prms_id bug_id | |
309 | set prms_id 0 | |
310 | set bug_id 0 | |
311 | } | |
312 | ||
313 | proc objc_exit { } { | |
d4213587 | 314 | global gluefile |
ff79b0cf | 315 | |
316 | if [info exists gluefile] { | |
d4213587 | 317 | file_on_build delete $gluefile |
318 | unset gluefile | |
ff79b0cf | 319 | } |
320 | } | |
321 | ||
322 | # If this is an older version of dejagnu (without runtest_file_p), | |
323 | # provide one and assume the old syntax: foo1.exp bar1.c foo2.exp bar2.c. | |
324 | # This can be deleted after next dejagnu release. | |
325 | ||
326 | if { [info procs runtest_file_p] == "" } then { | |
327 | proc runtest_file_p { runtests testcase } { | |
328 | if { $runtests != "" && [regexp "\[.\]\[cC\]" $runtests] } then { | |
329 | if { [lsearch $runtests [file tail $testcase]] >= 0 } then { | |
330 | return 1 | |
331 | } else { | |
332 | return 0 | |
333 | } | |
334 | } | |
335 | return 1 | |
336 | } | |
337 | } | |
338 | ||
339 | # Provide a definition of this if missing (delete after next dejagnu release). | |
340 | ||
341 | if { [info procs prune_warnings] == "" } then { | |
342 | proc prune_warnings { text } { | |
343 | return $text | |
344 | } | |
345 | } | |
346 | ||
ff79b0cf | 347 | # Prune messages from objc that aren't useful. |
348 | ||
349 | proc prune_objc_output { text } { | |
350 | #send_user "Before:$text\n" | |
351 | regsub -all "(^|\n)\[^\n\]*: In (function|method) \[^\n\]*" $text "" text | |
352 | regsub -all "(^|\n)\[^\n\]*: At top level:\[^\n\]*" $text "" text | |
353 | ||
354 | # It would be nice to avoid passing anything to objc that would cause it to | |
355 | # issue these messages (since ignoring them seems like a hack on our part), | |
356 | # but that's too difficult in the general case. For example, sometimes | |
357 | # you need to use -B to point objc at crt0.o, but there are some targets | |
358 | # that don't have crt0.o. | |
359 | regsub -all "(^|\n)\[^\n\]*file path prefix \[^\n\]* never used" $text "" text | |
360 | regsub -all "(^|\n)\[^\n\]*linker input file unused since linking not done" $text "" text | |
361 | ||
362 | #send_user "After:$text\n" | |
363 | ||
364 | return $text | |
365 | } | |
366 |