1 # Copyright
(C
) 2004-2023 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 # Many modifications by Jeffrey Wheat
(cassidy@cygnus.com
)
19 # With modifications by Mike Stump
<mrs@cygnus.com
>.
22 #
obj-c
++ support library routines
27 load_lib target
-libpath.exp
30 # OBJCXX_UNDER_TEST is the compiler under test.
34 set gpp_compile_options
""
37 #
obj-c
++_version
-- extract and print the version number of the compiler
40 proc
obj-c
++_version
{ } {
41 global OBJCXX_UNDER_TEST
45 # Ignore
any arguments after the command.
46 set compiler
[lindex $OBJCXX_UNDER_TEST
0]
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 {
56 clone_output
"$compiler $version\n"
58 clone_output
"[which $compiler] $version\n"
61 clone_output
"Couldn't determine version of [which $compiler]\n"
64 # Compiler does not exist
(this should have already been detected
)
65 warning
"$compiler does not exist"
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
73 proc
obj-c
++_include_flags
{ paths
} {
75 global HAVE_LIBSTDCXX_V3
76 global TESTING_IN_BUILD_TREE
80 if { [is_remote host
] ||
! [info exists TESTING_IN_BUILD_TREE
] } {
86 set odir
[lookfor_file $
{gccpath
} libstdc
++-v3
]
87 if { $
{odir
} != "" } {
88 append flags
[exec sh $
{odir
}/scripts
/testsuite_flags
--build
-includes
]
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.
99 proc
obj-c
++_link_flags
{ paths
} {
102 global ld_library_path
103 global OBJCXX_UNDER_TEST
109 set ld_library_path
"."
110 set shlib_ext
[get_shlib_extension
]
111 verbose
"shared lib extension: $shlib_ext"
113 if { $gccpath
!= "" } {
114 if [file
exists "${gccpath}/lib/libstdc++.a"] {
115 append ld_library_path
":${gccpath}/lib"
117 if [file
exists "${gccpath}/libg++/libg++.a"] {
118 append flags
" -L${gccpath}/libg++ "
119 append ld_library_path
":${gccpath}/libg++"
121 if [file
exists "${gccpath}/libstdc++/libstdc++.a"] {
122 append flags
" -L${gccpath}/libstdc++ "
123 append ld_library_path
":${gccpath}/libstdc++"
125 if [file
exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.a"] {
126 # Allow
for %s spec substitutions
127 append flags
" -B${gccpath}/libstdc++-v3/src/.libs "
128 append flags
" -L${gccpath}/libstdc++-v3/src/.libs "
129 append ld_library_path
":${gccpath}/libstdc++-v3/src/.libs"
131 # Look
for libstdc
++.$
{shlib_ext
}.
132 if [file
exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.${shlib_ext}"] {
133 # Allow
for %s spec substitutions
134 append flags
" -B${gccpath}/libstdc++-v3/src/.libs "
135 append flags
" -L${gccpath}/libstdc++-v3/src/.libs "
136 append ld_library_path
":${gccpath}/libstdc++-v3/src/.libs"
138 if [file
exists "${gccpath}/libiberty/libiberty.a"] {
139 append flags
" -L${gccpath}/libiberty "
141 if [file
exists "${gccpath}/librx/librx.a"] {
142 append flags
" -L${gccpath}/librx "
145 set objcpath
"[get_multilibs]"
146 set libobjc_dir
[lookfor_file $
{objcpath
} libobjc
/.libs
/libobjc.a
]
147 if { $libobjc_dir
== ""} {
148 set libobjc_dir
[lookfor_file $
{objcpath
} libobjc
/.libs
/libobjc
-gnu.a
]
150 # Now check
if we have a shared only build.
151 if { $libobjc_dir
== ""} {
152 set libobjc_dir
[lookfor_file $
{objcpath
} libobjc
/.libs
/libobjc.$
{shlib_ext
}]
153 if { $libobjc_dir
== ""} {
154 set libobjc_dir
[lookfor_file $
{objcpath
} libobjc
/.libs
/libobjc
-gnu.$
{shlib_ext
}]
158 verbose
"libobjc_dir: $libobjc_dir"
160 if { $libobjc_dir
!= "" } {
161 set libobjc_dir
[file dirname $
{libobjc_dir
}]
162 # Allow
for %s spec substitutions
163 append flags
" -B${libobjc_dir} "
164 append flags
" -L${libobjc_dir} "
165 append ld_library_path
":${libobjc_dir}"
167 append ld_library_path \
168 [gcc
-set-multilib
-library
-path $OBJCXX_UNDER_TEST
]
170 global tool_root_dir
;
172 set libgpp
[lookfor_file $
{tool_root_dir
} libg
++];
173 if { $libgpp
!= "" } {
174 append flags
"-L${libgpp} ";
175 append ld_library_path
":${libgpp}"
177 set libstdcpp
[lookfor_file $
{tool_root_dir
} libstdc
++];
178 if { $libstdcpp
!= "" } {
179 append flags
"-L${libstdcpp} ";
180 append ld_library_path
":${libstdcpp}"
182 set libiberty
[lookfor_file $
{tool_root_dir
} libiberty
];
183 if { $libiberty
!= "" } {
184 append flags
"-L${libiberty} ";
186 set librx
[lookfor_file $
{tool_root_dir
} librx
];
187 if { $librx
!= "" } {
188 append flags
"-L${librx} ";
192 set_ld_library_path_env_vars
198 #
obj-c
++_init
-- called at the start of each subdir of tests
201 proc
obj-c
++_init
{ args } {
203 global gpp_initialized
207 global gluefile wrap_flags
;
209 global ALWAYS_OBJCXXFLAGS
210 global TOOL_EXECUTABLE TOOL_OPTIONS
211 global OBJCXX_UNDER_TEST
212 global TESTING_IN_BUILD_TREE
213 global gcc_warning_prefix
214 global gcc_error_prefix
215 global TEST_ALWAYS_FLAGS
217 if ![info exists OBJCXX_UNDER_TEST
] then {
218 if [info exists TOOL_EXECUTABLE
] {
219 set OBJCXX_UNDER_TEST $TOOL_EXECUTABLE
;
221 if { [is_remote host
] ||
! [info exists TESTING_IN_BUILD_TREE
] } {
222 set OBJCXX_UNDER_TEST
[transform c
++]
224 set OBJCXX_UNDER_TEST
[findfile $base_dir
/..
/..
/xg
++ "$base_dir/../../xg++ -B$base_dir/../../" [findfile $base_dir/xg++ "$base_dir/xg++ -B$base_dir/" [transform c++]]]
229 # Bleah
, nasty. Bad taste.
230 if [ishost
"*-dos-*" ] {
231 regsub
"c\\+\\+" "$OBJCXX_UNDER_TEST" "gcc" OBJCXX_UNDER_TEST
234 if ![is_remote host
] {
235 if { [which $OBJCXX_UNDER_TEST
] == 0 } then {
236 perror
"OBJCXX_UNDER_TEST ($OBJCXX_UNDER_TEST) does not exist"
240 if ![info exists tmpdir
] {
244 if [info exists gluefile
] {
248 obj-c
++_maybe_build_wrapper
"${tmpdir}/obj-c++-testglue.o" "-fexceptions"
250 set ALWAYS_OBJCXXFLAGS
""
252 # TEST_ALWAYS_FLAGS are flags that should be passed to
every
253 # compilation. They are passed first to allow individual
254 # tests to override them.
255 if [info exists TEST_ALWAYS_FLAGS
] {
256 lappend ALWAYS_OBJCXXFLAGS
"additional_flags=$TEST_ALWAYS_FLAGS"
259 if ![is_remote host
] {
260 if [info exists TOOL_OPTIONS
] {
261 lappend ALWAYS_OBJCXXFLAGS
"additional_flags=[obj-c++_include_flags [get_multilibs ${TOOL_OPTIONS}] ]";
262 lappend ALWAYS_OBJCXXFLAGS
"ldflags=[obj-c++_link_flags [get_multilibs ${TOOL_OPTIONS}] ]";
264 lappend ALWAYS_OBJCXXFLAGS
"additional_flags=[obj-c++_include_flags [get_multilibs] ]";
265 lappend ALWAYS_OBJCXXFLAGS
"ldflags=[obj-c++_link_flags [get_multilibs] ]";
269 if [info exists TOOL_OPTIONS
] {
270 lappend ALWAYS_OBJCXXFLAGS
"additional_flags=$TOOL_OPTIONS";
273 # Make sure that lines are not wrapped. That can confuse the
274 # error
-message parsing machinery.
275 lappend ALWAYS_OBJCXXFLAGS
"additional_flags=-fmessage-length=0"
277 set gcc_warning_prefix
"warning:"
278 set gcc_error_prefix
"(fatal )?error:"
280 verbose
-log "ALWAYS_OBJCXXFLAGS set to $ALWAYS_OBJCXXFLAGS"
282 verbose
"obj-c++ is initialized" 3
286 #
obj-c
++_target_compile
-- compile a source file
289 proc
obj-c
++_target_compile
{ source dest type options
} {
292 global gpp_compile_options
293 global gluefile wrap_flags
294 global ALWAYS_OBJCXXFLAGS
295 global OBJCXX_UNDER_TEST
298 set shlib_ext
[get_shlib_extension
]
299 verbose
"input-options: $options" 4
301 # We have to figure out which runtime will be used
on darwin because
302 # we need to add the
include path
for the gnu runtime
if that is in
304 # First
, set the default...
305 if { [istarget
*-*-darwin
*] } {
310 verbose
"initial next runtime state : $nextruntime" 2
311 # Next
, see
if we
define the option in dg
-options...
312 foreach opt $options
{
313 if [regexp
".*-fnext-runtime.*" $opt] {
316 if [regexp
".*-fgnu-runtime.*" $opt] {
320 verbose
"next runtime state after dg opts: $nextruntime" 2
322 set tgt
[target_info
name]
323 if [board_info $tgt
exists multilib_flags
] {
324 set lb
[board_info $tgt multilib_flags
]
325 verbose
"board multilib_flags $lb" 2
327 if [regexp
".*-fnext-runtime.*" $opt] {
330 if [regexp
".*-fgnu-runtime.*" $opt] {
335 verbose
"next runtime state after any multilib opts: $nextruntime" 2
337 lappend options
"libs=-lobjc"
339 if { [target_info needs_status_wrapper
] != "" && [info exists gluefile] } {
340 lappend options
"libs=${gluefile}"
341 lappend options
"ldflags=${wrap_flags}"
344 #
If we have built libobjc along with the compiler
, point the test harness
345 # at it
(and associated headers
).
347 set objcpath
"[get_multilibs]"
349 set libobjc_dir
[lookfor_file $
{objcpath
} libobjc
/.libs
/libobjc.a
]
350 if { $libobjc_dir
== ""} {
351 set libobjc_dir
[lookfor_file $
{objcpath
} libobjc
/.libs
/libobjc
-gnu.a
]
353 if { $libobjc_dir
== ""} {
354 set libobjc_dir
[lookfor_file $
{objcpath
} libobjc
/.libs
/libobjc.$
{shlib_ext
}]
355 if { $libobjc_dir
== ""} {
356 set libobjc_dir
[lookfor_file $
{objcpath
} libobjc
/.libs
/libobjc
-gnu.$
{shlib_ext
}]
360 if { $libobjc_dir
!= "" } {
361 #
If we are using the gnu runtime
, add its includes.
362 if { $nextruntime
== 0 } {
363 set objc_include_dir
"${srcdir}/../../libobjc"
364 lappend options
"additional_flags=-I${objc_include_dir}"
368 lappend options
"additional_flags=[libio_include_flags]"
369 lappend options
"compiler=$OBJCXX_UNDER_TEST";
370 lappend options
"timeout=[timeout_value]"
372 set options
[concat $gpp_compile_options $options
]
374 set options
[concat
"$ALWAYS_OBJCXXFLAGS" $options];
376 set options
[dg
-additional
-files
-options $options $source
]
378 set result
[target_compile $source $dest $type $options
]
384 # $
{tool
}_option_help
387 proc $
{tool
}_option_help
{ } {
388 send_user
" --additional_options,OPTIONS\t\tUse OPTIONS to compile the testcase files. OPTIONS should be comma-separated.\n"
392 # $
{tool
}_option_proc
395 proc $
{tool
}_option_proc
{ option
} {
396 if [regexp
"^--additional_options," $option] {
397 global gpp_compile_options
398 regsub
"--additional_options," $option "" option
399 foreach x
[split $option
","] {
400 lappend gpp_compile_options
"additional_flags=$x"