OSDN Git Service

2007-09-17 Benjamin Kosnik <bkoz@redhat.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / testsuite / lib / libstdc++.exp
1 # libstdc++ "tool init file" for DejaGNU
2
3 # Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
4 # Free Software Foundation, Inc.
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 # 02110-1301, USA.
20
21
22 # Define callbacks and load other libraries.  This file is loaded relatively
23 # early, and before any other file we write ourselves.  "load_lib" will
24 # find anything in the DejaGNU installation tree, or in our lib directory.
25 # "load_gcc_lib" will search the core compiler's .exp collection instead.
26 #
27 # The naming rule is that dg.exp looks for "tool-" and runtest.exp looks
28 # for "tool_" when finding callbacks.  Utility routines we define for
29 # our callbacks begin with "v3-".
30 #
31 # libstdc++_* callbacks we don't define, but could:
32 # ..._option_help           prints additional --help output
33 # ..._option_proc (--foo)   process our own options
34 # ..._init (normal.exp)     called once per test file
35 # ..._finish                bracketing function for libstdc++_init
36 # ...-dg-prune              removing output text, see top of system dg.exp
37 #
38 # Useful hook:  if ${hostname}_init exists, it will be called, almost
39 # the last thing before testing begins.  This can be defined in, e.g.,
40 # ~/.dejagnurc or $DEJAGNU.
41
42 proc load_gcc_lib { filename } {
43     global srcdir
44     load_file $srcdir/../../gcc/testsuite/lib/$filename
45 }
46
47 # system routines
48 load_lib dg.exp
49 load_lib libgloss.exp
50 # compiler routines, then ours
51 load_gcc_lib target-supports.exp
52 load_gcc_lib target-supports-dg.exp
53 load_lib prune.exp
54 load_lib dg-options.exp
55 load_gcc_lib target-libpath.exp
56 load_gcc_lib wrapper.exp
57
58 # Useful for debugging.  Pass the name of a variable and the verbosity
59 # threshold (number of -v's on the command line).
60 proc v3track { var n } {
61     upvar $var val
62     verbose "++ $var is $val" $n
63 }
64
65 # Called by v3-init below.  "Static" to this file.
66 proc v3-copy-files {srcfiles} {
67     foreach f $srcfiles {
68         if { [catch { set symlink [file readlink $f] } x] } then {
69             remote_download target $f
70         } else {
71             if { [regexp "^/" "$symlink"] } then {
72                 remote_download target $symlink
73             } else {
74                 set dirname [file dirname $f]
75                 remote_download target $dirname/$symlink
76             }
77         }
78     }
79 }
80
81 # Called once, during runtest.exp setup.
82 proc libstdc++_init { testfile } {
83     global env
84     global v3-sharedlib 
85     global srcdir blddir objdir tool_root_dir
86     global cc cxx cxxflags cxxldflags
87     global includes
88     global gluefile wrap_flags
89     global ld_library_path
90     global target_triplet
91     global flags_file
92
93     # We set LC_ALL and LANG to C so that we get the same error
94     # messages as expected.
95     setenv LC_ALL C
96     setenv LANG C
97
98     set blddir [lookfor_file [get_multilibs] libstdc++-v3]
99     set flags_file "${blddir}/scripts/testsuite_flags"
100     v3track flags_file 2
101
102     # If a test doesn't have special options, use DEFAULT_CXXFLAGS.
103     # Use this variable if the behavior
104     #   1) only applies to libstdc++ testing
105     #   2) might need to be negated 
106     # In particular, some tests have to be run without precompiled
107     # headers, or without assertions.
108     global DEFAULT_CXXFLAGS
109     if ![info exists DEFAULT_CXXFLAGS] then {
110         set DEFAULT_CXXFLAGS ""
111         # Host specific goo here.
112         if { [string match "powerpc-*-darwin*" $target_triplet] } {
113             append DEFAULT_CXXFLAGS " -multiply_defined suppress"
114         } 
115     }
116     v3track DEFAULT_CXXFLAGS 2
117
118     # By default, we assume we want to run program images.
119     global dg-do-what-default
120     set dg-do-what-default run
121
122     # Copy any required data files.
123     v3-copy-files [glob -nocomplain "$srcdir/data/*.tst"]
124     v3-copy-files [glob -nocomplain "$srcdir/data/*.txt"]
125
126     set ld_library_path_tmp ""
127
128     # Locate libgcc.a so we don't need to account for different values of
129     # SHLIB_EXT on different platforms
130     set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a]
131     if {$gccdir != ""} {
132         set gccdir [file dirname $gccdir]
133         append ld_library_path_tmp ":${gccdir}"
134     }
135     v3track gccdir 3
136
137     # Locate libgomp. This is only required for parallel mode.
138     set libgompdir [lookfor_file $blddir/../libgomp .libs/libgomp.so]
139     if {$libgompdir != ""} {
140         set libgompdir [file dirname $libgompdir]
141         append ld_library_path_tmp ":${libgompdir}"
142     }
143     v3track libgompdir 3
144
145     # Locate libstdc++ shared library. (ie libstdc++.so.)
146     set v3-sharedlib 0
147     set sharedlibdir [lookfor_file $blddir src/.libs/libstdc++.so]
148     if {$sharedlibdir != ""} {
149         if { [string match "*-*-linux*" $target_triplet] && [isnative] } {
150             set v3-sharedlib 1
151             verbose -log "shared library support detected"
152         } 
153     }
154     v3track v3-sharedlib 3
155
156     # Compute what needs to be added to the existing LD_LIBRARY_PATH.
157     if {$gccdir != ""} {
158         set compiler ${gccdir}/g++
159         set ld_library_path ${ld_library_path_tmp}
160         append ld_library_path ":${blddir}/src/.libs"
161
162         if { [is_remote host] == 0 && [which $compiler] != 0 } {
163           foreach i "[exec $compiler --print-multi-lib]" {
164             set mldir ""
165             regexp -- "\[a-z0-9=_/\.-\]*;" $i mldir
166             set mldir [string trimright $mldir "\;@"]
167             if { "$mldir" == "." } {
168               continue
169             }
170             if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] >= 1 } {
171               append ld_library_path ":${gccdir}/${mldir}"
172             }
173           }
174         }
175
176         set_ld_library_path_env_vars
177         if [info exists env(LD_LIBRARY_PATH)] {
178           verbose -log "LD_LIBRARY_PATH = $env(LD_LIBRARY_PATH)"
179         }
180     } else {
181         set compiler [transform "g++"]
182     }
183
184     # Default settings.
185     set cxx [transform "g++"]
186     set cxxflags "-g -O2 -D_GLIBCXX_ASSERT -fmessage-length=0"
187     set cxxldflags ""
188     set cc [transform "gcc"]
189     # Locate testsuite_hooks.h and other testsuite headers.
190     set includes "-I${srcdir}/util"
191     # Adapt the defaults for special circumstances.
192     if [is_remote host] {
193         # A remote host does not, in general, have access to the
194         # $srcdir so we copy the testsuite headers into the current
195         # directory, and then add that to the search path.
196         foreach src [glob "${srcdir}/util/*.h" \
197                           "${srcdir}/util/*.cc" \
198                           "${srcdir}/util/*/*.hpp" \
199                           "${srcdir}/util/*/*.cc" \
200                           "${srcdir}/util/*/*.hpp" \
201                           "${srcdir}/util/*/*/*.cc" \
202                           "${srcdir}/util/*/*/*.hpp" \
203                           "${srcdir}/util/*/*/*/*.cc" \
204                           "${srcdir}/util/*/*/*/*.hpp" \
205                           "${srcdir}/util/*/*/*/*/*.cc" \
206                           "${srcdir}/util/*/*/*/*/*.hpp" ] {
207             # Remove everything up to "util/..."
208             set dst [string range $src [string length "${srcdir}/"] end]
209             # Create the directory containing the file.
210             set dir [file dirname $dst]
211             remote_exec host "mkdir" [list "-p" "$dir"]
212             # Download the file.
213             set result [remote_download host $src $dst]
214             if { $result == "" } {
215                 verbose -log "Unable to download ${srcdir}/${src} to host."
216                 return "untested"
217             }
218         }
219         set includes "-Iutil"
220     } elseif { [file exists $flags_file] } {
221         # If we find a testsuite_flags file, we're testing in the build dir.
222         set cxx [exec sh $flags_file --build-cxx]
223         set cxxflags [exec sh $flags_file --cxxflags]
224         set cxxldflags [exec sh $flags_file --cxxldflags]
225         set cc [exec sh $flags_file --build-cc]
226         set includes [exec sh $flags_file --build-includes]
227     }
228     append cxxflags " "
229     append cxxflags [getenv CXXFLAGS]
230     v3track cxxflags 2
231
232     # Always use MO files built by this test harness.
233     set cxxflags "$cxxflags -DLOCALEDIR=\".\""
234     set ccflags "$cxxflags -DLOCALEDIR=\".\""
235
236     # If a PCH file is available, use it.  We must delay performing
237     # this check until $cxx and such have been initialized because we
238     # perform a test compilation.  (Ideally, gcc --print-file-name would
239     # list PCH files, but it does not.)
240     global PCH_CXXFLAGS
241     if ![info exists PCH_CXXFLAGS] then {
242         set src "config[pid].cc"
243         set f [open $src "w"]
244         puts $f "int main () {}"
245         close $f
246
247         set lines [v3_target_compile $src "config[pid].o" object \
248                  "additional_flags=-include additional_flags=bits/stdtr1c++.h"]
249         if {$lines == "" } {
250 #           set PCH_CXXFLAGS "-include bits/extc++.h"
251 #           set PCH_CXXFLAGS "-include bits/stdtr1c++.h"
252             set PCH_CXXFLAGS "-include bits/stdc++.h"
253         } else {
254             set PCH_CXXFLAGS ""
255         }
256         file delete $src
257         v3track PCH_CXXFLAGS 2
258     }
259
260     libstdc++_maybe_build_wrapper "${objdir}/testglue.o" "-fexceptions"
261 }
262
263 # Callback for cleanup routines.
264 proc libstdc++_exit { } {
265     global gluefile;
266
267     if [info exists gluefile] {
268         file_on_build delete $gluefile;
269         unset gluefile;
270     }
271 }
272
273 # Callback from system dg-test.
274 proc libstdc++-dg-test { prog do_what extra_tool_flags } {
275     # Set up the compiler flags, based on what we're going to do.
276     switch $do_what {
277         "preprocess" {
278             set compile_type "preprocess"
279             set output_file "[file rootname [file tail $prog]].i"
280         }
281         "compile" {
282             set compile_type "assembly"
283             set output_file "[file rootname [file tail $prog]].s"
284         }
285         "assemble" {
286             set compile_type "object"
287             set output_file "[file rootname [file tail $prog]].o"
288         }
289         "link" {
290             set compile_type "executable"
291             set output_file "./[file rootname [file tail $prog]].exe"
292         }
293         "run" {
294             set compile_type "executable"
295             # FIXME: "./" is to cope with "." not being in $PATH.
296             # Should this be handled elsewhere?
297             # YES.
298             set output_file "./[file rootname [file tail $prog]].exe"
299             # This is the only place where we care if an executable was
300             # created or not.  If it was, dg.exp will try to run it.
301             catch { remote_file build delete $output_file }
302         }
303         default {
304             perror "$do_what: not a valid dg-do keyword"
305             return ""
306         }
307     }
308
309     # Short-circut a bunch of complicated goo here for the special
310     # case of compiling a test file as a "C" file, not as C++. Why? So
311     # -nostdc++ doesn't trip us up. So all the extra object files
312     # don't trip us up. So automatically linking in libstdc++ doesn't
313     # happen. So CXXFLAGS don't error.
314     set select_compile "v3_target_compile"
315     set options ""
316     if { $extra_tool_flags != "" } {
317         verbose -log "extra_tool_flags are:"
318         verbose -log $extra_tool_flags
319         if { [string first "-x c" $extra_tool_flags ] != -1 } {
320             verbose -log "compiling and executing as C, not C++"
321             set edit_tool_flags $extra_tool_flags
322             regsub -all ".x c" $edit_tool_flags "" edit_tool_flags
323             lappend options "additional_flags=$edit_tool_flags"
324             set select_compile "v3_target_compile_as_c"
325         } else {
326             lappend options "additional_flags=$extra_tool_flags"
327         }
328     }
329
330     # There is a libstdc++_compile made for us by default (via the tool-
331     # and-target file), but the defaults are lacking in goodness.
332     set comp_output [$select_compile "$prog" "$output_file" "$compile_type" $options];
333     set comp_output [ prune_g++_output $comp_output ];
334
335     return [list $comp_output $output_file]
336 }
337
338 # True if the library supports wchar_t.
339 set v3-wchar_t 0
340
341 # True if the library supports threads.
342 set v3-threads 0
343
344 # True if the library supports symbol versioning.
345 set v3-symver 0
346
347 # Called from libstdc++-dg-test above.  Calls back into system's
348 # target_compile to actually do the work.
349 proc v3_target_compile { source dest type options } {
350     global gluefile 
351     global wrap_flags
352     global cxx
353     global cxxflags
354     global cxxldflags
355     global includes
356
357     if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
358         lappend options "libs=${gluefile}"
359         lappend options "ldflags=${wrap_flags}"
360     }
361
362     set cxx_final $cxx
363     set cxxlibglossflags  [libgloss_link_flags]
364     set cxx_final [concat $cxx_final $cxxlibglossflags]
365     set cxx_final [concat $cxx_final $cxxflags]
366     set cxx_final [concat $cxx_final $includes]
367
368     # Flag setting based on type argument.
369     if { $type == "executable" } {
370         # Link the support objects into executables.
371         set cxx_final [concat $cxx_final $cxxldflags]
372         lappend options "additional_flags=./libtestc++.a"
373     } else {
374         if { $type == "sharedlib" } {
375             # Don't link in anything.
376             set type "executable"
377         }
378     }
379
380     lappend options "compiler=$cxx_final"
381     lappend options "timeout=600"
382
383     return [target_compile $source $dest $type $options]
384 }
385
386
387 # Called from libstdc++-dg-test above, but only for "C" compilation.
388 # Calls back into system's target_compile to actually do the work.
389 proc v3_target_compile_as_c { source dest type options } {
390     global gluefile 
391     global wrap_flags
392     global includes
393     global flags_file
394     global blddir
395     global cc
396     global cxxflags
397
398     if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
399         lappend options "libs=${gluefile}"
400         lappend options "ldflags=${wrap_flags}"
401     }
402
403     set tname [target_info name]
404     set cc_final $cc
405     set cxxlibglossflags [libgloss_link_flags]
406     set cc_final [concat $cc_final $cxxlibglossflags]
407     set cc_final [concat $cc_final $cxxflags]
408     set cc_final [concat $cc_final $includes]
409     regsub -all {\s[-]nostdinc[+][+]} $cc_final "" cc_final
410
411     # This is needed for "C" tests, as this type of test may need the
412     # C++ includes. And if we're not testing in the build directory,
413     # the includes variable is not likely to include the necessary
414     # info.
415     if { ![file exists $flags_file] } {
416         # ??? We need a --print-include-dirs option to GCC, so that
417         # we can avoid these hacks.  The heuristics here will not
418         # work with non-standard --with-includedir= options.
419         set version [remote_exec host ${cc} -dumpversion]
420         # Remove the trailing newline from the output.
421         set version [string trimright [lindex $version 1]]
422         set machine [remote_exec host ${cc} -dumpmachine]
423         set machine [string trimright [lindex $machine 1]]
424         set comp_base_dir [remote_exec host ${cc} --print-prog-name=cc1]
425         set comp_base_dir [lindex $comp_base_dir 1]
426         set comp_base_dir [file dirname [file dirname [file dirname [file dirname [file dirname $comp_base_dir]]]]]
427         # For a cross compiler, the header files will be located in a
428         # machine-specific subdirectory.
429         set crossbase "${comp_base_dir}/${machine}/include/c++/${version}"
430         set crosstarget "${crossbase}/${machine}"
431         set cc_final [concat $cc_final "-I$crossbase -I$crosstarget"]
432         # For a native compiler, the header files will be located at 
433         # the top level.
434         set includesbase "${comp_base_dir}/include/c++/${version}"
435         set includestarget "${includesbase}/${machine}"
436         set cc_final [concat $cc_final "-I$includesbase -I$includestarget"]
437
438         set libsup "${comp_base_dir}/lib"
439     } else {
440         set libsup "${blddir}/libsupc++/.libs"
441     }
442
443     set cc_final [concat $cc_final "-L$libsup"]
444
445     lappend options "compiler=$cc_final"
446     lappend options "timeout=600"
447
448     return [target_compile $source $dest $type $options]
449 }
450
451 # Build the support objects linked in with the libstdc++ tests.  In
452 # addition, set v3-wchar_t, v3-threads, and v3-symver appropriately.
453 proc v3-build_support { } {
454     global env
455     global srcdir
456     global v3-wchar_t
457     global v3-threads
458     global v3-symver
459     global v3-sharedlib
460
461     # Figure out whether or not the library supports certain features.
462     set v3-wchar_t 0
463     set v3-threads 0
464     set v3-symver 0
465     set libtest_objs ""
466
467     set config_src "config.cc"
468     set config_out "config.ii"
469     set f [open $config_src "w"]
470     puts $f "#include <bits/c++config.h>"
471     puts $f "#include <bits/gthr.h>"
472     close $f
473     v3_target_compile $config_src $config_out preprocess "additional_flags=-dN"
474     set file [open $config_out r]
475     set preprocessed [read $file]
476     close $file
477     if { [string first "_GLIBCXX_USE_WCHAR_T" $preprocessed] != -1 } {
478         verbose -log "wchar_t support detected"
479         set v3-wchar_t 1
480     }
481     if { [string first "_GLIBCXX_SYMVER" $preprocessed] != -1 } {
482         verbose -log "symbol versioning support detected"
483         set v3-symver 1
484     }
485     if { [string first "__GTHREADS" $preprocessed] != -1 } {
486         verbose -log "thread support detected"
487         set v3-threads 1
488     }
489
490     # Try to build the MO files that are used by some of the locale
491     # tests.  If we can't build them, that's OK; it just means that
492     # those tests will fail.
493     foreach lang [list "fr" "de"] {
494         catch {
495             file mkdir "$lang/LC_MESSAGES"
496             remote_exec "build" "msgfmt" "-o $lang/LC_MESSAGES/libstdc++.mo $srcdir/../po/$lang.po"
497             if [is_remote host] {
498                 remote_exec "host" "mkdir" "-p $lang/LC_MESSAGES"
499                 remote_download "host" "$lang/LC_MESSAGES/libstdc++.mo" "$lang/LC_MESSAGES/libstdc++.mo"
500             }
501         }
502     }
503
504     # Build the support objects.
505     set source_files [list testsuite_abi.cc testsuite_allocator.cc \
506                           testsuite_character.cc testsuite_hooks.cc \
507                  rng/twister_rand_gen.cc io/verified_cmd_line_input.cc \
508                           io/prog_bar.cc performance/time/elapsed_timer.cc ]
509     foreach f $source_files {
510         set obj [file rootname $f].o
511         set object_file [file tail $obj]
512         # Compile with "-w" so that warnings issued by the compiler
513         # do not prevent compilation.
514         if { [v3_target_compile $srcdir/util/$f $object_file "object" \
515                   [list "incdir=$srcdir" "additional_flags=-w"]]
516              != "" } {
517             error "could not compile $f"
518         }
519         append libtest_objs "$object_file "
520     }
521
522     # Collect into libtestc++.a
523     if  [info exists env(AR)] {
524         set ar $env(AR)
525     } else {
526         set ar [transform "ar"]
527     }
528     set arargs "-rc ./libtestc++.a ${libtest_objs}"
529     verbose -log "$ar $arargs"
530     set result [lindex [remote_exec host "$ar" "$arargs"] 0]
531     verbose "link result is $result"
532     if { $result == 0 } {
533         if  [info exists env(RANLIB)] {
534             set ranlib $env(RANLIB)
535         } else {
536             set ranlib [transform "ranlib"]
537         }
538         set ranlibargs "./libtestc++.a"
539         verbose -log "$ranlib $ranlibargs"
540         set result [lindex [remote_exec host "$ranlib" "$ranlibargs"] 0]
541         if { $result != 0 } {
542             error "could not link libtestc++.a"
543         }
544     }
545
546     # Build any shared objects needed for regression testing.
547     if { ${v3-sharedlib} == 1 } {
548         set source_files [list testsuite_shared.cc]
549         foreach f $source_files {
550             set object_file [file rootname $f].so
551             # Compile with "-w" so that warnings issued by the compiler
552             # do not prevent compilation.
553             if { [v3_target_compile $srcdir/util/$f $object_file "sharedlib" \
554              [list "incdir=$srcdir" "additional_flags=-w -shared -fPIC -DPIC"]]
555                  != "" } {
556                 error "could not compile $f"
557             }
558         }
559     }
560 }
561
562 proc check_v3_target_fileio { } {
563     global et_fileio_saved
564     global et_fileio_target_name
565     global tool 
566
567     if { ![info exists et_fileio_target_name] } {
568         set et_fileio_target_name ""
569     }
570
571     # If the target has changed since we set the cached value, clear it.
572     set current_target [current_target_name]
573     if { $current_target != $et_fileio_target_name } {
574         verbose "check_v3_target_fileio: `$et_fileio_target_name'" 2
575         set et_fileio_target_name $current_target
576         if [info exists et_fileio_saved] {
577             verbose "check_v3_target_fileio: removing cached result" 2
578             unset et_fileio_saved
579         }
580     }
581
582     if [info exists et_fileio_saved] {
583         verbose "check_v3_target_fileio: using cached result" 2
584     } else {
585         set et_fileio_saved 0
586
587         # Set up, compile, and execute a C++ test program that tries to use
588         # the file functions
589         set src fileio[pid].cc
590         set exe fileio[pid].x
591
592         set f [open $src "w"]
593         puts $f "#include <sys/types.h>"
594         puts $f "#include <sys/stat.h>"
595         puts $f "#include <fcntl.h>"
596         puts $f "#include <unistd.h>"
597         puts $f "#include <errno.h>"
598         puts $f "using namespace std;"  
599         puts $f "int main ()"
600         puts $f "{"
601         puts $f "  int fd  = open (\".\", O_RDONLY);"
602         puts $f "  if (fd == -1)"
603         puts $f "  {"
604         puts $f "    int err = errno;"
605         puts $f "    if (err == EIO || err == ENOSYS)"
606         puts $f "      return 1;"
607         puts $f "  }"
608         puts $f "  else"
609         puts $f "    close (fd);"
610         puts $f "  return 0;"
611         puts $f "}" 
612         close $f
613
614         set lines [v3_target_compile $src $exe executable ""]
615         file delete $src
616
617         if [string match "" $lines] {
618             # No error message, compilation succeeded.
619             set result [${tool}_load "./$exe" "" ""]
620             set status [lindex $result 0]
621             remote_file build delete $exe
622
623             verbose "check_v3_target_fileio: status is <$status>" 2
624
625             if { $status == "pass" } {
626                 set et_fileio_saved 1
627             }
628         } else {
629             verbose "check_v3_target_fileio: compilation failed" 2
630         }
631     }
632     return $et_fileio_saved
633 }
634
635 # Eventually we want C90/C99 determining and switching from this.
636 proc check_v3_target_c_std { } {
637     global et_c_std_saved
638     global et_c_std_target_name
639     global tool 
640
641     if { ![info exists et_c_std_target_name] } {
642         set et_c_std_target_name ""
643     }
644
645     # If the target has changed since we set the cached value, clear it.
646     set current_target [current_target_name]
647     if { $current_target != $et_c_std_target_name } {
648         verbose "check_v3_target_c_std: `$et_c_std_target_name'" 2
649         set et_c_std_target_name $current_target
650         if [info exists et_c_std_saved] {
651             verbose "check_v3_target_c_std: removing cached result" 2
652             unset et_c_std_saved
653         }
654     }
655
656     if [info exists et_c_std_saved] {
657         verbose "check_v3_target_c_std: using cached result" 2
658     } else {
659         set et_c_std_saved 0
660
661         # Set up, compile, and execute a C++ test program that tries to use
662         # C99 functionality.
663         # For math bits, could use check_effective_target_c99_math.
664         set src fileio[pid].cc
665         set exe fileio[pid].x
666
667         set f [open $src "w"]
668         puts $f "#include <tr1/cmath>"
669         puts $f "#include <cstdlib>"
670         puts $f "int main ()"
671         puts $f "{"
672         puts $f "  float f = 45.55;"
673         puts $f "  int i = std::tr1::isnan(f);"
674         puts $f "  "
675         puts $f "  using std::wctomb;"
676         puts $f "  return 0;"
677         puts $f "}" 
678         close $f
679
680         set lines [v3_target_compile $src $exe executable ""]
681         file delete $src
682
683         if [string match "" $lines] {
684             # No error message, compilation succeeded.
685             set result [${tool}_load "./$exe" "" ""]
686             set status [lindex $result 0]
687             remote_file build delete $exe
688
689             verbose "check_v3_target_c_std: status is <$status>" 2
690
691             if { $status == "pass" } {
692                 set et_c_std_saved 1
693             }
694         } else {
695             verbose "check_v3_target_c_std: compilation failed" 2
696         }
697     }
698     return $et_c_std_saved
699 }
700
701 proc check_v3_target_sharedlib { } {
702     global v3-sharedlib
703     return ${v3-sharedlib}
704 }
705
706 proc check_v3_target_time { } {
707     global et_time_saved
708     global et_time_target_name
709     global tool 
710
711     if { ![info exists et_time_target_name] } {
712         set et_time_target_name ""
713     }
714
715     # If the target has changed since we set the cached value, clear it.
716     set current_target [current_target_name]
717     if { $current_target != $et_time_target_name } {
718         verbose "check_v3_target_time: `$et_time_target_name'" 2
719         set et_time_target_name $current_target
720         if [info exists et_time_saved] {
721             verbose "check_v3_target_time: removing cached result" 2
722             unset et_time_saved
723         }
724     }
725
726     if [info exists et_time_saved] {
727         verbose "check_v3_target_time: using cached result" 2
728     } else {
729         set et_time_saved 0
730
731         # Set up and compile a C++ test program that tries to use
732         # the time function
733         set src time[pid].cc
734         set exe time[pid].x
735
736         set f [open $src "w"]
737         puts $f "#include <time.h>"
738         puts $f "using namespace std;"  
739         puts $f "int main ()"
740         puts $f "{"
741         puts $f "  time (0);"   
742         puts $f "}" 
743         close $f
744
745         set lines [v3_target_compile $src $exe executable ""]
746         file delete $src
747
748         if [string match "" $lines] {
749             # No error message, compilation succeeded.
750             verbose "check_v3_target_time: compilation succeeded" 2
751             remote_file build delete $exe
752             set et_time_saved 1
753         } else {
754             verbose "check_v3_target_time: compilation failed" 2
755         }
756     }
757     return $et_time_saved
758 }
759
760 proc check_v3_target_namedlocale { } {
761     global et_namedlocale_saved
762     global et_namedlocale_target_name
763     global tool 
764
765     if { ![info exists et_namedlocale_target_name] } {
766         set et_namedlocale_target_name ""
767     }
768
769     # If the target has changed since we set the cached value, clear it.
770     set current_target [current_target_name]
771     if { $current_target != $et_namedlocale_target_name } {
772         verbose "check_v3_target_namedlocale: `$et_namedlocale_target_name'" 2
773         set et_namedlocale_target_name $current_target
774         if [info exists et_namedlocale_saved] {
775             verbose "check_v3_target_namedlocale: removing cached result" 2
776             unset et_namedlocale_saved
777         }
778     }
779
780     if [info exists et_namedlocale_saved] {
781         verbose "check_v3_target_namedlocale: using cached result" 2
782     } else {
783         set et_namedlocale_saved 0
784
785         # Set up, compile, and execute a C++ test program that tries to use
786         # all the required named locales.
787         set src nlocale[pid].cc
788         set exe nlocale[pid].x
789
790         set f [open $src "w"]
791         puts $f "#include <locale>"
792         puts $f "using namespace std;"  
793         puts $f "int main ()"
794         puts $f "{"
795         puts $f "  try" 
796         puts $f "  {" 
797         puts $f "     locale(\"\");"
798         puts $f "     locale(\"de_DE\");"
799         puts $f "     locale(\"de_DE.ISO-8859-15@euro\");"
800         puts $f "     locale(\"de_DE@euro\");"
801         puts $f "     locale(\"en_HK\");"
802         puts $f "     locale(\"en_PH\");"
803         puts $f "     locale(\"en_US\");"
804         puts $f "     locale(\"en_US.ISO-8859-1\");"
805         puts $f "     locale(\"en_US.ISO-8859-15\");"
806         puts $f "     locale(\"en_US.UTF-8\");"
807         puts $f "     locale(\"es_ES\");"
808         puts $f "     locale(\"es_MX\");"
809         puts $f "     locale(\"fr_FR\");"
810         puts $f "     locale(\"fr_FR@euro\");"
811         puts $f "     locale(\"is_IS\");"
812         puts $f "     locale(\"is_IS.UTF-8\");"
813         puts $f "     locale(\"it_IT\");"
814         puts $f "     locale(\"ja_JP.eucjp\");"
815         puts $f "     locale(\"se_NO.UTF-8\");"
816         puts $f "     locale(\"ta_IN\");"
817         puts $f "     locale(\"zh_TW\");"
818         puts $f "     return 0;"
819         puts $f "  }"
820         puts $f "  catch(...)"
821         puts $f "  {"
822         puts $f "     return 1;"
823         puts $f "  }"   
824         puts $f "}"
825         close $f
826
827         set lines [v3_target_compile $src $exe executable ""]
828         file delete $src
829
830         if [string match "" $lines] {
831             # No error message, compilation succeeded.
832             set result [${tool}_load "./$exe" "" ""]
833             set status [lindex $result 0]
834             remote_file build delete $exe
835
836             verbose "check_v3_target_namedlocale: status is <$status>" 2
837
838             if { $status == "pass" } {
839                 set et_namedlocale_saved 1
840             }
841         } else {
842             verbose "check_v3_target_namedlocale: compilation failed" 2
843         }
844     }
845     return $et_namedlocale_saved
846 }
847
848 proc check_v3_target_debug_mode { } {
849     global cxxflags
850     global et_debug_mode
851     global tool 
852
853     if { ![info exists et_debug_mode_target_name] } {
854         set et_debug_mode_target_name ""
855     }
856
857     # If the target has changed since we set the cached value, clear it.
858     set current_target [current_target_name]
859     if { $current_target != $et_debug_mode_target_name } {
860         verbose "check_v3_target_debug_mode: `$et_debug_mode_target_name'" 2
861         set et_debug_mode_target_name $current_target
862         if [info exists et_debug_mode] {
863             verbose "check_v3_target_debug_mode: removing cached result" 2
864             unset et_debug_mode
865         }
866     }
867
868     if [info exists et_debug_mode] {
869         verbose "check_v3_target_debug_mode: using cached result" 2
870     } else {
871         set et_debug_mode 0
872
873         # Set up, compile, and execute a C++ test program that depends
874         # on debug mode working.
875         set src debug_mode[pid].cc
876         set exe debug_mode[pid].exe
877
878         set f [open $src "w"]
879         puts $f "#include <string>"
880         puts $f "using namespace std;"  
881         puts $f "int main()"
882         puts $f "{ return 0; }"
883         close $f
884
885         set cxxflags_saved $cxxflags
886         set cxxflags "$cxxflags -Werror -O0 -D_GLIBCXX_DEBUG"
887         set lines [v3_target_compile $src $exe executable ""]
888         set cxxflags $cxxflags_saved
889         file delete $src
890
891         if [string match "" $lines] {
892             # No error message, compilation succeeded.
893             set et_debug_mode 1
894         }
895     }
896     verbose "check_v3_target_debug_mode: $et_debug_mode" 2
897     return $et_debug_mode
898 }
899
900 proc check_v3_target_parallel_mode { } {
901     global cxxflags
902     global DEFAULT_CXXFLAGS
903     global et_parallel_mode
904
905     global tool 
906
907     if { ![info exists et_parallel_mode_target_name] } {
908         set et_parallel_mode_target_name ""
909     }
910
911     # If the target has changed since we set the cached value, clear it.
912     set current_target [current_target_name]
913     if { $current_target != $et_parallel_mode_target_name } {
914         verbose "check_v3_target_parallel_mode: `$et_parallel_mode_target_name'" 2
915         set et_parallel_mode_target_name $current_target
916         if [info exists et_parallel_mode] {
917             verbose "check_v3_target_parallel_mode: removing cached result" 2
918             unset et_parallel_mode
919         }
920     }
921
922     if [info exists et_parallel_mode] {
923         verbose "check_v3_target_parallel_mode: using cached result" 2
924     } else {
925         set et_parallel_mode 0
926
927         # Set up, compile, and execute a C++ test program that depends
928         # on parallel mode working.
929         set src parallel_mode[pid].cc
930         set exe parallel_mode[pid].exe
931
932         set f [open $src "w"]
933         puts $f "#include <omp.h>"
934         puts $f "int main()"
935         puts $f "{ return 0; }"
936         close $f
937
938         set cxxflags_saved $cxxflags
939         set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror"
940
941         set lines [v3_target_compile $src $exe executable ""]
942         set cxxflags $cxxflags_saved
943         file delete $src
944
945         if [string match "" $lines] {
946             # No error message, compilation succeeded.
947             set et_parallel_mode 1
948         } else {
949             verbose "check_v3_target_parallel_mode: compilation failed" 2
950         }
951     }
952     verbose "check_v3_target_parallel_mode: $et_parallel_mode" 2
953     return $et_parallel_mode
954 }