]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/lib/libstdc++.exp
libjava.exp (libjava_init): Recognize multilib directory names containing underscores.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / lib / libstdc++.exp
CommitLineData
23834577 1# libstdc++ "tool init file" for DejaGNU
2cb1c928 2
f63a8495 3# Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
23834577 4#
b3f2a032
PE
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, write to the Free Software
2f9f6cef
BK
17# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18# 02110-1301, USA.
2cb1c928 19
b3f2a032 20
23834577
PE
21# Define callbacks and load other libraries. This file is loaded relatively
22# early, and before any other file we write ourselves. "load_lib" will
23# find anything in the DejaGNU installation tree, or in our lib directory.
24# "load_gcc_lib" will search the core compiler's .exp collection instead.
25#
26# The naming rule is that dg.exp looks for "tool-" and runtest.exp looks
27# for "tool_" when finding callbacks. Utility routines we define for
28# our callbacks begin with "v3-".
29#
30# libstdc++_* callbacks we don't define, but could:
31# ..._option_help prints additional --help output
32# ..._option_proc (--foo) process our own options
23834577
PE
33# ..._init (normal.exp) called once per test file
34# ..._finish bracketing function for libstdc++_init
35# ...-dg-prune removing output text, see top of system dg.exp
36#
37# Useful hook: if ${hostname}_init exists, it will be called, almost
38# the last thing before testing begins. This can be defined in, e.g.,
39# ~/.dejagnurc or $DEJAGNU.
40
41proc load_gcc_lib { filename } {
42 global srcdir
43 load_file $srcdir/../../gcc/testsuite/lib/$filename
44}
45
46# system routines
b3f2a032
PE
47load_lib dg.exp
48load_lib libgloss.exp
23834577 49# compiler routines, then ours
58adf39c 50load_gcc_lib target-supports.exp
75d1ddc1 51load_gcc_lib target-supports-dg.exp
b3f2a032 52load_lib prune.exp
23834577 53load_lib dg-options.exp
1df8e834 54load_gcc_lib target-libpath.exp
90c609e5 55load_gcc_lib wrapper.exp
23834577
PE
56
57# Useful for debugging. Pass the name of a variable and the verbosity
58# threshold (number of -v's on the command line).
59proc v3track { var n } {
60 upvar $var val
61 verbose "++ $var is $val" $n
62}
b3f2a032 63
caf21254 64# Called by v3-init below. "Static" to this file.
d8fe7b29 65proc v3-copy-files {srcfiles} {
b3f2a032 66 foreach f $srcfiles {
caf21254 67 if { [catch { set symlink [file readlink $f] } x] } then {
d8fe7b29 68 remote_download target $f
caf21254
PE
69 } else {
70 if { [regexp "^/" "$symlink"] } then {
d8fe7b29 71 remote_download target $symlink
caf21254
PE
72 } else {
73 set dirname [file dirname $f]
d8fe7b29 74 remote_download target $dirname/$symlink
caf21254
PE
75 }
76 }
b3f2a032
PE
77 }
78}
79
23834577
PE
80# Called once, during runtest.exp setup.
81proc libstdc++_init { testfile } {
82 global env
2f9f6cef 83 global v3-sharedlib
d8fe7b29 84 global srcdir blddir objdir tool_root_dir
952c7b74 85 global cxx cxxflags cxxldflags
b3f2a032 86 global includes
b3f2a032 87 global gluefile wrap_flags
1df8e834 88 global ld_library_path
23834577 89 global target_triplet
b3f2a032 90
5305b1ae
BK
91 # We set LC_ALL and LANG to C so that we get the same error
92 # messages as expected.
690e11b8
AP
93 setenv LC_ALL C
94 setenv LANG C
95
b3f2a032 96 set blddir [lookfor_file [get_multilibs] libstdc++-v3]
23834577
PE
97 set flags_file "${blddir}/scripts/testsuite_flags"
98 v3track flags_file 2
99
100 # If a test doesn't have special options, use DEFAULT_CXXFLAGS.
101 # Use this variable if the behavior
102 # 1) only applies to libstdc++ testing
103 # 2) might need to be negated
104 # In particular, some tests have to be run without precompiled
105 # headers, or without assertions.
106 global DEFAULT_CXXFLAGS
107 if ![info exists DEFAULT_CXXFLAGS] then {
8b60fb43 108 set DEFAULT_CXXFLAGS ""
23834577
PE
109 # Host specific goo here.
110 if { [string match "powerpc-*-darwin*" $target_triplet] } {
111 append DEFAULT_CXXFLAGS " -multiply_defined suppress"
112 }
113 }
114 v3track DEFAULT_CXXFLAGS 2
b3f2a032
PE
115
116 # By default, we assume we want to run program images.
117 global dg-do-what-default
118 set dg-do-what-default run
119
120 # Copy any required data files.
d8fe7b29
DJ
121 v3-copy-files [glob -nocomplain "$srcdir/data/*.tst"]
122 v3-copy-files [glob -nocomplain "$srcdir/data/*.txt"]
b3f2a032 123
645112dd 124 # Locate libgcc.a so we don't need to account for different values of
b3f2a032
PE
125 # SHLIB_EXT on different platforms
126 set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a]
127 if {$gccdir != ""} {
caf21254 128 set gccdir [file dirname $gccdir]
b3f2a032 129 }
23834577 130 v3track gccdir 3
b3f2a032 131
2f9f6cef
BK
132 # Look for shared library. (ie libstdc++.so.)
133 set v3-sharedlib 0
134 set sharedlibdir [lookfor_file $blddir src/.libs/libstdc++.so]
135 if {$sharedlibdir != ""} {
f05c19d1 136 if { [string match "*-*-linux*" $target_triplet] && [isnative] } {
f81ab296
BK
137 set v3-sharedlib 1
138 verbose -log "shared library support detected"
139 }
2f9f6cef
BK
140 }
141 v3track v3-sharedlib 3
142
645112dd 143 # Compute what needs to be added to the existing LD_LIBRARY_PATH.
0b3deaaf
MM
144 if {$gccdir != ""} {
145 set ld_library_path ""
146 append ld_library_path ":${gccdir}"
147 set compiler ${gccdir}/g++
148 append ld_library_path ":${blddir}/src/.libs"
149
150 if { [is_remote host] == 0 && [which $compiler] != 0 } {
151 foreach i "[exec $compiler --print-multi-lib]" {
152 set mldir ""
615baed7 153 regexp -- "\[a-z0-9=_/\.-\]*;" $i mldir
0b3deaaf
MM
154 set mldir [string trimright $mldir "\;@"]
155 if { "$mldir" == "." } {
156 continue
157 }
158 if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] >= 1 } {
159 append ld_library_path ":${gccdir}/${mldir}"
160 }
161 }
162 }
b3f2a032 163
0b3deaaf
MM
164 set_ld_library_path_env_vars
165 if [info exists env(LD_LIBRARY_PATH)] {
166 verbose -log "LD_LIBRARY_PATH = $env(LD_LIBRARY_PATH)"
167 }
168 } else {
169 set compiler [transform "g++"]
1df8e834 170 }
b3f2a032
PE
171
172 # Do a bunch of handstands and backflips for cross compiling and
173 # finding simulators...
174 if [is_remote host] {
175 set header [remote_download host ${blddir}/testsuite/testsuite_hooks.h]
176 if { $header == "" } {
177 verbose -log "Unable to download ${blddir}/testsuite/testsuite_hooks.h to host."
178 return "untested"
179 }
180 set cxx [transform "g++"]
c85b032a 181 set cxxflags "-ggdb3"
952c7b74 182 set cxxldflags ""
b3f2a032
PE
183 set includes "-I./"
184 } else {
185 # If we find a testsuite_flags file, we're testing in the build dir.
b3f2a032
PE
186 if { [file exists $flags_file] } {
187 set cxx [exec sh $flags_file --build-cxx]
c85b032a 188 set cxxflags [exec sh $flags_file --cxxflags]
952c7b74 189 set cxxldflags [exec sh $flags_file --cxxldflags]
b3f2a032
PE
190 set includes [exec sh $flags_file --build-includes]
191 } else {
192 set cxx [transform "g++"]
b3f2a032 193 set includes "-I${srcdir}"
952c7b74
BK
194 set cxxldflags ""
195 set cxxflags "-g -O2 -D_GLIBCXX_ASSERT -fmessage-length=0"
b3f2a032
PE
196 }
197 }
198
b5b3739a
MM
199 # Always use MO files built by this test harness.
200 set cxxflags "$cxxflags -DLOCALEDIR=\".\""
201
8b60fb43
MM
202 # If a PCH file is available, use it. We must delay performing
203 # this check until $cxx and such have been initialized because we
204 # perform a test compilation. (Ideally, gcc --print-file-name would
205 # list PCH files, but it does not.)
206 global PCH_CXXFLAGS
207 if ![info exists PCH_CXXFLAGS] then {
208 set src "config[pid].cc"
209 set f [open $src "w"]
210 puts $f "int main () {}"
211 close $f
212
213 set lines [v3_target_compile $src "config[pid].o" object \
214 "additional_flags=-include additional_flags=bits/stdc++.h"]
215 if {$lines == "" } {
216 set PCH_CXXFLAGS "-include bits/stdc++.h"
217 } else {
218 set PCH_CXXFLAGS ""
219 }
220 file delete $src
221 v3track PCH_CXXFLAGS 2
222 }
223
90c609e5 224 libstdc++_maybe_build_wrapper "${objdir}/testglue.o"
b3f2a032
PE
225}
226
ebd9dfc9 227# Callback for cleanup routines.
446e8778
RE
228proc libstdc++_exit { } {
229 global gluefile;
230
231 if [info exists gluefile] {
232 file_on_build delete $gluefile;
233 unset gluefile;
234 }
235}
236
b3f2a032 237# Callback from system dg-test.
caf21254 238proc libstdc++-dg-test { prog do_what extra_tool_flags } {
b3f2a032 239 # Set up the compiler flags, based on what we're going to do.
b3f2a032 240 switch $do_what {
caf21254
PE
241 "preprocess" {
242 set compile_type "preprocess"
243 set output_file "[file rootname [file tail $prog]].i"
244 }
245 "compile" {
246 set compile_type "assembly"
247 set output_file "[file rootname [file tail $prog]].s"
248 }
249 "assemble" {
250 set compile_type "object"
251 set output_file "[file rootname [file tail $prog]].o"
252 }
253 "link" {
254 set compile_type "executable"
255 set output_file "./[file rootname [file tail $prog]].exe"
256 }
257 "run" {
258 set compile_type "executable"
259 # FIXME: "./" is to cope with "." not being in $PATH.
260 # Should this be handled elsewhere?
261 # YES.
262 set output_file "./[file rootname [file tail $prog]].exe"
263 # This is the only place where we care if an executable was
264 # created or not. If it was, dg.exp will try to run it.
8e289297 265 catch { remote_file build delete $output_file }
caf21254 266 }
cddfb1c7 267 default {
caf21254
PE
268 perror "$do_what: not a valid dg-do keyword"
269 return ""
270 }
b3f2a032 271 }
cddfb1c7 272
b3f2a032
PE
273 set options ""
274 if { $extra_tool_flags != "" } {
cddfb1c7
BK
275 verbose -log "extra_tool_flags are:"
276 verbose -log $extra_tool_flags
277 if { [string first "-x c" $extra_tool_flags ] != -1 } {
278 # Short-circut a bunch of complicated goo here for the
279 # special case of compiling a test file as a "C" file, not
280 # as C++: just use target_compile, instead of the usual
281 # gimmicks.
282 verbose -log "compiling and executing as C, not C++"
283 set compile_type "executable"
284 set output_file "./[file rootname [file tail $prog]].exe"
285 remote_file build delete $output_file;
286 lappend options "additional_flags=$extra_tool_flags"
287 set comp_output [target_compile "$prog" "$output_file" "$compile_type" $options];
288 set comp_output [ prune_g++_output $comp_output ];
289 return [list $comp_output $output_file]
290 } else {
291 lappend options "additional_flags=$extra_tool_flags"
292 }
b3f2a032
PE
293 }
294
23834577
PE
295 # There is a libstdc++_compile made for us by default (via the tool-
296 # and-target file), but the defaults are lacking in goodness.
caf21254 297 set comp_output [v3_target_compile "$prog" "$output_file" "$compile_type" $options];
b3f2a032
PE
298 set comp_output [ prune_g++_output $comp_output ];
299
300 return [list $comp_output $output_file]
301}
302
0b3deaaf 303# True if the library supports wchar_t.
0b694555 304set v3-wchar_t 0
0b3deaaf
MM
305
306# True if the library supports threads.
0b694555 307set v3-threads 0
0b3deaaf 308
84946e72
BK
309# True if the library supports symbol versioning.
310set v3-symver 0
311
0b3deaaf 312# A string naming object files to be linked into all tests.
0b694555 313set v3-test_objs ""
0b3deaaf 314
caf21254 315# Called from libstdc++-dg-test above. Calls back into system's
b3f2a032 316# target_compile to actually do the work.
caf21254 317proc v3_target_compile { source dest type options } {
b3f2a032
PE
318 global gluefile
319 global wrap_flags
320 global cxx
321 global cxxflags
952c7b74 322 global cxxldflags
b3f2a032 323 global includes
c85b032a 324 global blddir
0b694555 325 global v3-test_objs
b3f2a032
PE
326
327 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
caf21254
PE
328 lappend options "libs=${gluefile}"
329 lappend options "ldflags=${wrap_flags}"
b3f2a032
PE
330 }
331
332 set cxx_final $cxx
333 set cxxlibglossflags [libgloss_link_flags]
334 set cxx_final [concat $cxx_final $cxxlibglossflags]
335 set cxx_final [concat $cxx_final $cxxflags]
336 set cxx_final [concat $cxx_final $includes]
31a7113e
BK
337
338 # Flag setting based on type argument.
0b3deaaf 339 if { $type == "executable" } {
31a7113e 340 # Link the support objects into executables.
0b694555 341 set cxx_final [concat $cxx_final ${v3-test_objs}]
952c7b74 342 set cxx_final [concat $cxx_final $cxxldflags]
31a7113e
BK
343 } else {
344 if { $type == "sharedlib" } {
345 # Don't link in anything.
346 set type "executable"
347 }
0b3deaaf 348 }
b3f2a032
PE
349
350 lappend options "compiler=$cxx_final"
351
b3f2a032
PE
352 return [target_compile $source $dest $type $options]
353}
354
5305b1ae 355
0b3deaaf 356# Build the support objects linked in with the libstdc++ tests. In
84946e72 357# addition, set v3-wchar_t, v3-threads, v3-test_objs, and v3-symver
0b3deaaf 358# appropriately.
451e92db 359proc v3-build_support { } {
c85b032a 360 global srcdir
0b694555
MM
361 global v3-wchar_t
362 global v3-threads
363 global v3-test_objs
84946e72 364 global v3-symver
2f9f6cef 365 global v3-sharedlib
0b3deaaf
MM
366
367 # Figure out whether or not the library supports certain features.
0b694555
MM
368 set v3-wchar_t 0
369 set v3-threads 0
84946e72 370 set v3-symver 0
0b694555 371 set v3-test_objs ""
0b3deaaf
MM
372
373 set config_src "config.cc"
374 set f [open $config_src "w"]
375 puts $f "#include <bits/c++config.h>"
08cce8fe 376 puts $f "#include <bits/gthr.h>"
0b3deaaf
MM
377 close $f
378 set preprocessed [v3_target_compile $config_src "" \
379 preprocess "additional_flags=-dN"]
08cce8fe
MM
380 if { [string first "_GLIBCXX_USE_WCHAR_T" $preprocessed] != -1 } {
381 verbose -log "wchar_t support detected"
382 set v3-wchar_t 1
383 }
84946e72
BK
384 if { [string first "_GLIBCXX_SYMVER" $preprocessed] != -1 } {
385 verbose -log "symbol versioning support detected"
386 set v3-symver 1
387 }
08cce8fe
MM
388 if { [string first "__GTHREADS" $preprocessed] != -1 } {
389 verbose -log "thread support detected"
390 set v3-threads 1
0b3deaaf 391 }
c85b032a 392
b5b3739a
MM
393 # Try to build the MO files that are used by some of the locale
394 # tests. If we can't build them, that's OK; it just means that
395 # those tests will fail.
396 foreach lang [list "fr" "de"] {
397 catch {
398 file mkdir "$lang/LC_MESSAGES"
399 remote_exec "build" "msgfmt" "-o $lang/LC_MESSAGES/libstdc++.mo $srcdir/../po/$lang.po"
400 if [is_remote host] {
401 remote_exec "host" "mkdir" "-p $lang/LC_MESSAGES"
402 remote_download "host" "$lang/LC_MESSAGES/libstdc++.mo" "$lang/LC_MESSAGES/libstdc++.mo"
403 }
404 }
405 }
406
0b3deaaf
MM
407 # Build the support objects.
408 set source_files \
2f9f6cef 409 [list testsuite_abi.cc testsuite_allocator.cc testsuite_character.cc testsuite_hooks.cc ]
0b3deaaf
MM
410 foreach f $source_files {
411 set object_file [file rootname $f].o
510d8ecc
MM
412 # Compile with "-w" so that warnings issued by the compiler
413 # do not prevent compilation.
0b3deaaf 414 if { [v3_target_compile $srcdir/$f $object_file "object" \
510d8ecc 415 [list "incdir=$srcdir" "additional_flags=-w"]]
0b3deaaf
MM
416 != "" } {
417 error "could not compile $f"
418 }
0b694555 419 append v3-test_objs "$object_file "
b3f2a032 420 }
2f9f6cef
BK
421
422 # Build the shared support objects.
423 if { ${v3-sharedlib} == 1 } {
424 set source_files \
425 [list testsuite_shared.cc]
426 foreach f $source_files {
427 set object_file [file rootname $f].so
428 # Compile with "-w" so that warnings issued by the compiler
429 # do not prevent compilation.
31a7113e 430 if { [v3_target_compile $srcdir/$f $object_file "sharedlib" \
2f9f6cef
BK
431 [list "incdir=$srcdir" "additional_flags=-w -shared -fPIC -DPIC"]]
432 != "" } {
433 error "could not compile $f"
434 }
435 }
436 }
437}
438
439proc check_v3_target_sharedlib { } {
440 global v3-sharedlib
441 return ${v3-sharedlib}
b3f2a032 442}
f63a8495
PC
443
444proc check_v3_target_namedlocale { } {
445 global et_namedlocale_saved
446 global et_namedlocale_target_name
447 global tool
448
449 if { ![info exists et_namedlocale_target_name] } {
450 set et_namedlocale_target_name ""
451 }
452
453 # If the target has changed since we set the cached value, clear it.
454 set current_target [current_target_name]
455 if { $current_target != $et_namedlocale_target_name } {
456 verbose "check_v3_target_namedlocale: `$et_namedlocale_target_name'" 2
457 set et_namedlocale_target_name $current_target
458 if [info exists et_namedlocale_saved] {
459 verbose "check_v3_target_namedlocale: removing cached result" 2
460 unset et_namedlocale_saved
461 }
462 }
463
464 if [info exists et_namedlocale_saved] {
465 verbose "check_v3_target_namedlocale: using cached result" 2
466 } else {
467 set et_namedlocale_saved 0
468
469 # Set up, compile, and execute a C++ test program that tries to use
470 # all the required named locales.
471 set src nlocale[pid].cc
472 set exe nlocale[pid].x
473
474 set f [open $src "w"]
475 puts $f "#include <locale>"
476 puts $f "using namespace std;"
477 puts $f "int main ()"
478 puts $f "{"
479 puts $f " try"
480 puts $f " {"
481 puts $f " locale(\"\");"
482 puts $f " locale(\"de_DE\");"
483 puts $f " locale(\"de_DE.ISO-8859-15@euro\");"
484 puts $f " locale(\"de_DE@euro\");"
485 puts $f " locale(\"en_HK\");"
486 puts $f " locale(\"en_PH\");"
487 puts $f " locale(\"en_US\");"
488 puts $f " locale(\"en_US.ISO-8859-1\");"
489 puts $f " locale(\"en_US.ISO-8859-15\");"
490 puts $f " locale(\"en_US.UTF-8\");"
491 puts $f " locale(\"es_ES\");"
492 puts $f " locale(\"es_MX\");"
493 puts $f " locale(\"fr_FR\");"
494 puts $f " locale(\"fr_FR@euro\");"
495 puts $f " locale(\"is_IS\");"
496 puts $f " locale(\"is_IS.UTF-8\");"
497 puts $f " locale(\"it_IT\");"
498 puts $f " locale(\"ja_JP.eucjp\");"
499 puts $f " locale(\"se_NO.UTF-8\");"
500 puts $f " locale(\"ta_IN\");"
501 puts $f " locale(\"zh_TW\");"
502 puts $f " return 0;"
503 puts $f " }"
504 puts $f " catch(...)"
505 puts $f " {"
506 puts $f " return 1;"
507 puts $f " }"
508 puts $f "}"
509 close $f
510
511 set lines [v3_target_compile $src $exe executable ""]
512 file delete $src
513
514 if [string match "" $lines] {
515 # No error message, compilation succeeded.
516 set result [${tool}_load "./$exe" "" ""]
517 set status [lindex $result 0]
518 remote_file build delete $exe
519
520 verbose "check_v3_target_namedlocale: status is <$status>" 2
521
522 if { $status == "pass" } {
523 set et_namedlocale_saved 1
524 }
525 } else {
526 verbose "check_v3_target_namedlocale: compilation failed" 2
527 }
528 }
529 return $et_namedlocale_saved
530}
a1340af7
BK
531
532proc check_v3_target_cxa_atexit { } {
533 global et_cxa_atexit
534 global et_cxa_atexit_target_name
535 global tool
536
537 if { ![info exists et_cxa_atexit_target_name] } {
538 set et_cxa_atexit_target_name ""
539 }
540
541 # If the target has changed since we set the cached value, clear it.
542 set current_target [current_target_name]
543 if { $current_target != $et_cxa_atexit_target_name } {
544 verbose "check_v3_target_cxa_atexit: `$et_cxa_atexit_target_name'" 2
545 set et_cxa_atexit_target_name $current_target
546 if [info exists et_cxa_atexit] {
547 verbose "check_v3_target_cxa_atexit: removing cached result" 2
548 unset et_cxa_atexit
549 }
550 }
551
552 if [info exists et_cxa_atexit] {
553 verbose "check_v3_target_cxa_atexit: using cached result" 2
554 } else {
555 set et_cxa_atexit 0
556
d14630d6
BK
557 # Set up, compile, and execute a C++ test program that depends
558 # on correct ordering of static object destructors. This is
559 # indicative of the presence and use of __cxa_atexit.
a1340af7
BK
560 set src cxaatexit[pid].cc
561 set exe cxaatexit[pid].x
562
563 set f [open $src "w"]
564 puts $f "#include <stdlib.h>"
565 puts $f "static unsigned int count;"
566 puts $f "struct X"
567 puts $f "{"
2f9f6cef
BK
568 puts $f " X() { count = 1; }"
569 puts $f " ~X()"
570 puts $f " {"
571 puts $f " if (count != 3)"
572 puts $f " exit(1);"
573 puts $f " count = 4;"
574 puts $f " }"
a1340af7
BK
575 puts $f "};"
576 puts $f "void f()"
577 puts $f "{"
2f9f6cef 578 puts $f " static X x;"
a1340af7
BK
579 puts $f "}"
580 puts $f "struct Y"
581 puts $f "{"
2f9f6cef
BK
582 puts $f " Y() { f(); count = 2; }"
583 puts $f " ~Y()"
584 puts $f " {"
585 puts $f " if (count != 2)"
586 puts $f " exit(1);"
587 puts $f " count = 3;"
588 puts $f " }"
a1340af7
BK
589 puts $f "};"
590 puts $f "Y y;"
591 puts $f "int main()"
592 puts $f "{ return 0; }"
593 close $f
594
595 set lines [v3_target_compile $src $exe executable ""]
596 file delete $src
597
598 if [string match "" $lines] {
599 # No error message, compilation succeeded.
600 set result [${tool}_load "./$exe" "" ""]
601 set status [lindex $result 0]
602 remote_file build delete $exe
603
604 verbose "check_v3_target_cxa_atexit: status is <$status>" 2
605
606 if { $status == "pass" } {
607 set et_cxa_atexit 1
608 }
609 } else {
610 verbose "check_v3_target_cxa_atexit: compilation failed" 2
611 }
612 }
613 return $et_cxa_atexit
614}
451e92db
BK
615
616proc check_v3_target_debug_mode { } {
617 global cxxflags
618 global et_debug_mode
619
620 global tool
621
622 if { ![info exists et_debug_mode_target_name] } {
623 set et_debug_mode_target_name ""
624 }
625
626 # If the target has changed since we set the cached value, clear it.
627 set current_target [current_target_name]
628 if { $current_target != $et_debug_mode_target_name } {
629 verbose "check_v3_target_debug_mode: `$et_debug_mode_target_name'" 2
630 set et_debug_mode_target_name $current_target
631 if [info exists et_debug_mode] {
632 verbose "check_v3_target_debug_mode: removing cached result" 2
633 unset et_debug_mode
634 }
635 }
636
637 if [info exists et_debug_mode] {
638 verbose "check_v3_target_debug_mode: using cached result" 2
639 } else {
640 set et_debug_mode 0
641
642 # Set up, compile, and execute a C++ test program that depends
cddfb1c7 643 # on debug mode working.
451e92db 644 set src debug_mode[pid].cc
797308b2 645 set exe debug_mode[pid].exe
451e92db
BK
646
647 set f [open $src "w"]
648 puts $f "#include <string>"
649 puts $f "using namespace std;"
650 puts $f "int main()"
651 puts $f "{ return 0; }"
652 close $f
653
654 set cxxflags_saved $cxxflags
655 set cxxflags "$cxxflags -Werror -O0 -D_GLIBCXX_DEBUG"
656 set lines [v3_target_compile $src $exe executable ""]
657 set cxxflags $cxxflags_saved
658 file delete $src
659
660 if [string match "" $lines] {
661 # No error message, compilation succeeded.
662 set et_debug_mode 1
663 }
664 }
665 verbose "check_v3_target_debug_mode: $et_debug_mode" 2
666 return $et_debug_mode
667}