1 # Copyright
(C
) 1992-2018 Free Software Foundation
, Inc.
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.
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.
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
/>.
17 # This file was written by Rob Savoye
(rob@cygnus.com
)
18 # Currently maintained by Doug Evans
(dje@cygnus.com
)
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.
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.
31 load_lib target
-libpath.exp
32 load_lib target
-utils.exp
35 # OBJC_UNDER_TEST is the compiler under test.
39 # default_objc_version
-- extract and print the version number of the compiler
42 proc default_objc_version
{ } {
43 global OBJC_UNDER_TEST
47 # Ignore
any arguments after the command.
48 set compiler
[lindex $OBJC_UNDER_TEST
0]
50 if ![is_remote host
] {
51 set compiler_name
[which $compiler
]
53 set compiler_name $compiler
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"
65 clone_output
"Couldn't determine version of $compiler_name: $output\n"
68 # Compiler does not exist
(this should have already been detected
).
69 warning
"$compiler does not exist"
74 #
Call objc_version. We
do it this way so we can override it
if needed.
76 proc objc_version
{ } {
81 # objc_init
-- called at the start of each .exp script.
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.
87 set objc_initialized 0
89 proc objc_init { args } {
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 global gcc_warning_prefix
99 global gcc_error_prefix
101 # We set LC_ALL and LANG to C so that we get the same error messages as
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
113 if { $objc_initialized == 1 } { return; }
115 if ![info exists OBJC_UNDER_TEST] then {
116 if [info exists TOOL_EXECUTABLE] {
117 set OBJC_UNDER_TEST $TOOL_EXECUTABLE
119 set OBJC_UNDER_TEST [find_gcc]
123 if ![info exists tmpdir] then {
127 set gcc_warning_prefix "warning:"
128 set gcc_error_prefix "(fatal )?error:"
130 objc_maybe_build_wrapper "${tmpdir}/objc-testglue.o"
132 set objc_libgcc_s_path [gcc-set-multilib-library-path $OBJC_UNDER_TEST]
135 proc objc_target_compile { source dest type options } {
138 global gluefile wrap_flags
140 global OBJC_UNDER_TEST
142 global ld_library_path
143 global objc_libgcc_s_path
145 global TEST_ALWAYS_FLAGS
147 set shlib_ext [get_shlib_extension]
148 set ld_library_path ".:${objc_libgcc_s_path}"
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
153 # First set the default...
154 if { [istarget *-*-darwin*] } {
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] {
165 if [regexp ".*-fgnu-runtime.*" $opt] {
169 verbose "next runtime state after dg opts: $nextruntime" 2
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
176 if [regexp ".*-fnext-runtime.*" $opt] {
179 if [regexp ".*-fgnu-runtime.*" $opt] {
184 verbose "next runtime state after any multilib opts: $nextruntime" 2
186 lappend options "libs=-lobjc"
187 verbose "shared lib extension: $shlib_ext" 3
189 if { [target_info needs_status_wrapper]!="" && [info exists gluefile] } {
190 lappend options "libs=${gluefile}"
191 lappend options "ldflags=$wrap_flags"
194 # TEST_ALWAYS_FLAGS are flags that should be passed to every
195 # compilation. They are passed first to allow individual
196 # tests to override them.
197 if [info exists TEST_ALWAYS_FLAGS] {
198 set options [concat "{additional_flags=$TEST_ALWAYS_FLAGS}" $options]
201 # TOOL_OPTIONS must come first, so that it doesn't override testcase
203 if [info exists TOOL_OPTIONS
] {
204 set options
[concat
"{additional_flags=$TOOL_OPTIONS}" $options]
207 #
If we have built libobjc along with the compiler
, point the test harness
208 # at it
(and associated headers
).
210 set objcpath
"[get_multilibs]"
212 set libobjc_dir
[lookfor_file $
{objcpath
} libobjc
/.libs
/libobjc.a
]
213 if { $libobjc_dir
== "" } {
214 #
On darwin there is
, potentially
, a gnu runtime too.
215 set libobjc_dir
[lookfor_file $
{objcpath
} libobjc
/.libs
/libobjc
-gnu.a
]
217 # Perhaps we didn
't build static libs.
218 if { $libobjc_dir == "" } {
219 set libobjc_dir [lookfor_file ${objcpath} libobjc/.libs/libobjc.${shlib_ext}]
220 # On darwin there is, potentially, a gnu runtime too.
221 if { $libobjc_dir == "" } {
222 set libobjc_dir [lookfor_file ${objcpath} libobjc/.libs/libobjc-gnu.${shlib_ext}]
226 if { $libobjc_dir != "" } {
227 # If we are using the gnu runtime, add its includes.
228 if { $nextruntime == 0 } {
229 set objc_include_dir "${srcdir}/../../libobjc"
230 lappend options "additional_flags=-I${objc_include_dir}"
231 verbose "adding gnu runtime include dir: $objc_include_dir "
233 set libobjc_dir [file dirname ${libobjc_dir}]
234 # Allow for %s spec substitutions..
235 set objc_link_flags " -B${libobjc_dir} "
236 lappend options "additional_flags=${objc_link_flags}"
237 set objc_link_flags " -L${libobjc_dir} "
238 lappend options "additional_flags=${objc_link_flags}"
239 append ld_library_path ":${libobjc_dir}"
241 if { $type == "precompiled_header" } {
242 # If we generating a precompiled header, we have say this is an
243 # objective-C header.
244 set source [concat "-x objective-c-header" $source]
246 lappend options "compiler=$OBJC_UNDER_TEST"
247 lappend options "timeout=[timeout_value]"
249 set_ld_library_path_env_vars
251 set options [dg-additional-files-options $options $source]
253 return [target_compile $source $dest $type $options]
257 # objc_pass -- utility to record a testcase passed.
260 proc objc_pass { testcase cflags } {
261 if { "$cflags" == "" } {
264 pass "$testcase, $cflags"
269 # objc_fail -- utility to record a testcase failed
272 proc objc_fail { testcase cflags } {
273 if { "$cflags" == "" } {
276 fail "$testcase, $cflags"
281 # objc_finish -- called at the end of every .exp script that calls objc_init
283 # The purpose of this proc is to hide all quirks of the testing environment
284 # from the testsuites. It also exists to undo anything that objc_init did
285 # (that needs undoing).
288 proc objc_finish { } {
289 # The testing harness apparently requires this.
292 if [info exists errorInfo] then {
296 # Might as well reset these (keeps our caller from wondering whether
297 # s/he has to or not).
298 global prms_id bug_id
306 if [info exists gluefile] {
307 file_on_build delete $gluefile
312 # If this is an older version of dejagnu (without runtest_file_p),
313 # provide one and assume the old syntax: foo1.exp bar1.c foo2.exp bar2.c.
314 # This can be deleted after next dejagnu release.
316 if { [info procs runtest_file_p] == "" } then {
317 proc runtest_file_p { runtests testcase } {
318 if { $runtests != "" && [regexp "\[.\]\[cC\]" $runtests] } then {
319 if { [lsearch $runtests [file tail $testcase]] >= 0 } then {
329 # Provide a definition of this if missing (delete after next dejagnu release).
331 if { [info procs prune_warnings] == "" } then {
332 proc prune_warnings { text } {
337 # Prune messages from objc that aren't useful.
339 proc prune_objc_output
{ text } {
340 #send_user
"Before:$text\n"
341 regsub
-all
"(^|\n)\[^\n\]*: In (function|method) \[^\n\]*" $text "" text
342 regsub
-all
"(^|\n)\[^\n\]*: At top level:\[^\n\]*" $text "" text
344 # It would be nice to avoid passing anything to objc that would cause it to
345 # issue these messages
(since ignoring them seems like a hack
on our part
),
346 # but that
's too difficult in the general case. For example, sometimes
347 # you need to use -B to point objc at crt0.o, but there are some targets
348 # that don't have crt0.o.
349 regsub
-all
"(^|\n)\[^\n\]*file path prefix \[^\n\]* never used" $text "" text
350 regsub
-all
"(^|\n)\[^\n\]*linker input file unused since linking not done" $text "" text
352 #send_user
"After:$text\n"