OSDN Git Service

2009-11-30 Dave Korn <dave.korn.cygwin@gmail.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, 2008, 2009
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 3 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; see the file COPYING3.  If not see
18 # <http://www.gnu.org/licenses/>.
19
20
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
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
41 proc load_gcc_lib { filename } {
42     global srcdir
43     load_file $srcdir/../../gcc/testsuite/lib/$filename
44 }
45
46 # system routines
47 load_lib dg.exp
48 load_lib libgloss.exp
49 # compiler routines, then ours
50 load_gcc_lib target-supports.exp
51 load_gcc_lib target-supports-dg.exp
52 load_lib prune.exp
53 load_lib dg-options.exp
54 load_gcc_lib target-libpath.exp
55 load_gcc_lib timeout.exp
56 load_gcc_lib timeout-dg.exp
57 load_gcc_lib wrapper.exp
58
59 # Useful for debugging.  Pass the name of a variable and the verbosity
60 # threshold (number of -v's on the command line).
61 proc v3track { var n } {
62     upvar $var val
63     verbose "++ $var is $val" $n
64 }
65
66 # Called by v3-init below.  "Static" to this file.
67 proc v3-copy-files {srcfiles} {
68     foreach f $srcfiles {
69         if { [catch { set symlink [file readlink $f] } x] } then {
70             remote_download target $f
71         } else {
72             if { [regexp "^/" "$symlink"] } then {
73                 remote_download target $symlink
74             } else {
75                 set dirname [file dirname $f]
76                 remote_download target $dirname/$symlink
77             }
78         }
79     }
80 }
81
82 # Called once, during runtest.exp setup.
83 proc libstdc++_init { testfile } {
84     global env
85     global v3-sharedlib v3-libgomp
86     global srcdir blddir objdir tool_root_dir
87     global cc cxx cxxflags cxxpchflags cxxldflags
88     global includes
89     global gluefile wrap_flags
90     global ld_library_path
91     global target_triplet
92     global flags_file
93     global tool_timeout
94
95     # We set LC_ALL and LANG to C so that we get the same error
96     # messages as expected.
97     setenv LC_ALL C
98     setenv LANG C
99
100     # Many hosts now default to a non-ASCII C locale, however, so
101     # they can set a charset encoding here if they need.
102     if { [ishost "*-*-cygwin*"] } {
103       setenv LC_ALL C.ASCII
104       setenv LANG C.ASCII
105     }
106
107     set blddir [lookfor_file [get_multilibs] libstdc++-v3]
108     set flags_file "${blddir}/scripts/testsuite_flags"
109     v3track flags_file 2
110
111     # If a test doesn't have special options, use DEFAULT_CXXFLAGS.
112     # Use this variable if the behavior
113     #   1) only applies to libstdc++ testing
114     #   2) might need to be negated 
115     # In particular, some tests have to be run without precompiled
116     # headers, or without assertions.
117     global DEFAULT_CXXFLAGS
118     if ![info exists DEFAULT_CXXFLAGS] then {
119         set DEFAULT_CXXFLAGS ""
120         # Host specific goo here.
121         if { [string match "powerpc-*-darwin*" $target_triplet] } {
122             append DEFAULT_CXXFLAGS " -multiply_defined suppress"
123         } 
124     }
125     v3track DEFAULT_CXXFLAGS 2
126
127     # By default, we assume we want to run program images.
128     global dg-do-what-default
129     set dg-do-what-default run
130
131     # Copy any required data files.
132     v3-copy-files [glob -nocomplain "$srcdir/data/*.tst"]
133     v3-copy-files [glob -nocomplain "$srcdir/data/*.txt"]
134
135     set ld_library_path_tmp ""
136
137     # Locate libgcc.a so we don't need to account for different values of
138     # SHLIB_EXT on different platforms
139     set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a]
140     if {$gccdir != ""} {
141         set gccdir [file dirname $gccdir]
142         append ld_library_path_tmp ":${gccdir}"
143     }
144     v3track gccdir 3
145
146     # Locate libgomp. This is only required for parallel mode.
147     set v3-libgomp 0
148     set libgompdir [lookfor_file $blddir/../libgomp .libs/libgomp.so]
149     if {$libgompdir != ""} {
150         set v3-libgomp 1
151         set libgompdir [file dirname $libgompdir]
152         append ld_library_path_tmp ":${libgompdir}"
153         verbose -log "libgomp support detected"
154     }
155     v3track libgompdir 3
156
157     # Locate libstdc++ shared library. (ie libstdc++.so.)
158     set v3-sharedlib 0
159     set sharedlibdir [lookfor_file $blddir src/.libs/libstdc++.so]
160     if {$sharedlibdir != ""} {
161         if { [string match "*-*-linux*" $target_triplet] && [isnative] } {
162             set v3-sharedlib 1
163             verbose -log "shared library support detected"
164         } 
165     }
166     v3track v3-sharedlib 3
167
168     # Compute what needs to be added to the existing LD_LIBRARY_PATH.
169     if {$gccdir != ""} {
170         set compiler ${gccdir}/g++
171         set ld_library_path ${ld_library_path_tmp}
172         append ld_library_path ":${blddir}/src/.libs"
173
174         if { [is_remote host] == 0 && [which $compiler] != 0 } {
175           foreach i "[exec $compiler --print-multi-lib]" {
176             set mldir ""
177             regexp -- "\[a-z0-9=_/\.-\]*;" $i mldir
178             set mldir [string trimright $mldir "\;@"]
179             if { "$mldir" == "." } {
180               continue
181             }
182             if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] >= 1 } {
183               append ld_library_path ":${gccdir}/${mldir}"
184             }
185           }
186         }
187
188         set_ld_library_path_env_vars
189         if [info exists env(LD_LIBRARY_PATH)] {
190           verbose -log "LD_LIBRARY_PATH = $env(LD_LIBRARY_PATH)"
191         }
192     } else {
193         set compiler [transform "g++"]
194     }
195
196     # Set the default timeout for v3 tests.
197     set tool_timeout 600
198
199     # Default settings.
200     set cxx [transform "g++"]
201     set cxxflags "-g -O2 -D_GLIBCXX_ASSERT -fmessage-length=0"
202     set cxxpchflags ""
203     set cxxldflags ""
204     set cc [transform "gcc"]
205     # Locate testsuite_hooks.h and other testsuite headers.
206     set includes "-I${srcdir}/util"
207     # Adapt the defaults for special circumstances.
208     if [is_remote host] {
209         # A remote host does not, in general, have access to the
210         # $srcdir so we copy the testsuite headers into the current
211         # directory, and then add that to the search path.
212         foreach src [glob "${srcdir}/util/*.h" \
213                           "${srcdir}/util/*.cc" \
214                           "${srcdir}/util/*.tcc" \
215                           "${srcdir}/util/*.hpp" \
216                           "${srcdir}/util/*/*.h" \
217                           "${srcdir}/util/*/*.cc" \
218                           "${srcdir}/util/*/*.tcc" \
219                           "${srcdir}/util/*/*.hpp" \
220                           "${srcdir}/util/*/*/*.h" \
221                           "${srcdir}/util/*/*/*.cc" \
222                           "${srcdir}/util/*/*/*.tcc" \
223                           "${srcdir}/util/*/*/*.hpp" \
224                           "${srcdir}/util/*/*/*/*.h" \
225                           "${srcdir}/util/*/*/*/*.cc" \
226                           "${srcdir}/util/*/*/*/*.tcc" \
227                           "${srcdir}/util/*/*/*/*.hpp" \
228                           "${srcdir}/util/*/*/*/*/*.h" \
229                           "${srcdir}/util/*/*/*/*/*.cc" \
230                           "${srcdir}/util/*/*/*/*/*.tcc" \
231                           "${srcdir}/util/*/*/*/*/*.hpp" ] {
232             # Remove everything up to "util/..."
233             set dst [string range $src [string length "${srcdir}/"] end]
234             # Create the directory containing the file.
235             set dir [file dirname $dst]
236             remote_exec host "mkdir" [list "-p" "$dir"]
237             # Download the file.
238             set result [remote_download host $src $dst]
239             if { $result == "" } {
240                 verbose -log "Unable to download ${srcdir}/${src} to host."
241                 return "untested"
242             }
243         }
244         set includes "-Iutil"
245     } elseif { [file exists $flags_file] } {
246         # If we find a testsuite_flags file, we're testing in the build dir.
247         set cxx [exec sh $flags_file --build-cxx]
248         set cxxflags [exec sh $flags_file --cxxflags]
249         set cxxpchflags [exec sh $flags_file --cxxpchflags]
250         set cxxldflags [exec sh $flags_file --cxxldflags]
251         set cc [exec sh $flags_file --build-cc]
252         set includes [exec sh $flags_file --build-includes]
253     }
254     append cxxflags " "
255     append cxxflags [getenv CXXFLAGS]
256     v3track cxxflags 2
257
258     # Always use MO files built by this test harness.
259     set cxxflags "$cxxflags -DLOCALEDIR=\".\""
260     set ccflags "$cxxflags -DLOCALEDIR=\".\""
261
262     # If a PCH file is available, use it.  We must delay performing
263     # this check until $cxx and such have been initialized because we
264     # perform a test compilation.  (Ideally, gcc --print-file-name would
265     # list PCH files, but it does not.)
266     if { $cxxpchflags != "" } {
267         set src "config[pid].cc"
268         set f [open $src "w"]
269         puts $f "int main () {}"
270         close $f
271
272         # Fixme: "additional_flags=$cxxpchflags" fails, but would be
273         # useful as then the requested variant of the pre-build PCH
274         # files could be tested to see if it works.
275         set lines [v3_target_compile $src "config[pid].o" object \
276                    "additional_flags=-include additional_flags=bits/stdc++.h"]
277         if { $lines != "" } {
278             verbose -log "Requested PCH file: $cxxpchflags"
279             verbose -log "is not working, and will not be used."
280             set cxxpchflags ""
281         } 
282         file delete $src
283      } 
284     v3track cxxpchflags 2
285
286     global PCH_CXXFLAGS
287     if ![info exists PCH_CXXFLAGS] then {
288         set PCH_CXXFLAGS $cxxpchflags
289         v3track PCH_CXXFLAGS 2
290     }
291
292     libstdc++_maybe_build_wrapper "${objdir}/testglue.o" "-fexceptions"
293 }
294
295 # Callback for cleanup routines.
296 proc libstdc++_exit { } {
297     global gluefile;
298
299     if [info exists gluefile] {
300         file_on_build delete $gluefile;
301         unset gluefile;
302     }
303 }
304
305 # Callback from system dg-test.
306 proc libstdc++-dg-test { prog do_what extra_tool_flags } {
307     # Set up the compiler flags, based on what we're going to do.
308     switch $do_what {
309         "preprocess" {
310             set compile_type "preprocess"
311             set output_file "[file rootname [file tail $prog]].i"
312         }
313         "compile" {
314             set compile_type "assembly"
315             set output_file "[file rootname [file tail $prog]].s"
316         }
317         "assemble" {
318             set compile_type "object"
319             set output_file "[file rootname [file tail $prog]].o"
320         }
321         "link" {
322             set compile_type "executable"
323             set output_file "./[file rootname [file tail $prog]].exe"
324         }
325         "run" {
326             set compile_type "executable"
327             # FIXME: "./" is to cope with "." not being in $PATH.
328             # Should this be handled elsewhere?
329             # YES.
330             set output_file "./[file rootname [file tail $prog]].exe"
331             # This is the only place where we care if an executable was
332             # created or not.  If it was, dg.exp will try to run it.
333             catch { remote_file build delete $output_file }
334         }
335         default {
336             perror "$do_what: not a valid dg-do keyword"
337             return ""
338         }
339     }
340
341     # Short-circut a bunch of complicated goo here for the special
342     # case of compiling a test file as a "C" file, not as C++. Why? So
343     # -nostdc++ doesn't trip us up. So all the extra object files
344     # don't trip us up. So automatically linking in libstdc++ doesn't
345     # happen. So CXXFLAGS don't error.
346     set select_compile "v3_target_compile"
347     set options ""
348     if { $extra_tool_flags != "" } {
349         verbose -log "extra_tool_flags are:"
350         verbose -log $extra_tool_flags
351         if { [string first "-x c" $extra_tool_flags ] != -1 } {
352             verbose -log "compiling and executing as C, not C++"
353             set edit_tool_flags $extra_tool_flags
354             regsub -all ".x c" $edit_tool_flags "" edit_tool_flags
355             lappend options "additional_flags=$edit_tool_flags"
356             set select_compile "v3_target_compile_as_c"
357         } else {
358             lappend options "additional_flags=$extra_tool_flags"
359         }
360     }
361
362     # There is a libstdc++_compile made for us by default (via the tool-
363     # and-target file), but the defaults are lacking in goodness.
364     set comp_output [$select_compile "$prog" "$output_file" "$compile_type" $options];
365     set comp_output [ prune_g++_output $comp_output ];
366
367     return [list $comp_output $output_file]
368 }
369
370 # Override the DejaGnu dg-test in order to clear flags after a test, as
371 # is done for compiler tests in gcc-dg.exp.
372
373 if { [info procs saved-dg-test] == [list] } {
374     rename dg-test saved-dg-test
375
376     proc dg-test { args } {
377         global errorInfo
378
379         if { [ catch { eval saved-dg-test $args } errmsg ] } {
380             set saved_info $errorInfo
381             unset_timeout_vars
382             error $errmsg $saved_info
383         }
384         unset_timeout_vars
385     }
386 }
387
388 # True if the library supports wchar_t.
389 set v3-wchar_t 0
390
391 # True if the library supports threads.
392 set v3-threads 0
393
394 # True if the library supports symbol versioning.
395 set v3-symver 0
396
397 # Called from libstdc++-dg-test above.  Calls back into system's
398 # target_compile to actually do the work.
399 proc v3_target_compile { source dest type options } {
400     global gluefile 
401     global wrap_flags
402     global cxx
403     global cxxflags
404     global cxxldflags
405     global includes
406
407     if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
408         lappend options "libs=${gluefile}"
409         lappend options "ldflags=${wrap_flags}"
410     }
411
412     set cxx_final $cxx
413     set cxxlibglossflags  [libgloss_link_flags]
414     set cxx_final [concat $cxx_final $cxxlibglossflags]
415     set cxx_final [concat $cxx_final $cxxflags]
416     set cxx_final [concat $cxx_final $includes]
417
418     # Flag setting based on type argument.
419     if { $type == "executable" } {
420         # Link the support objects into executables.
421         lappend options "additional_flags=./libtestc++.a $cxxldflags"
422     } else {
423         if { $type == "sharedlib" } {
424             # Don't link in anything.
425             set type "executable"
426         }
427     }
428
429     lappend options "compiler=$cxx_final"
430     lappend options "timeout=[timeout_value]"
431
432     return [target_compile $source $dest $type $options]
433 }
434
435
436 # Called from libstdc++-dg-test above, but only for "C" compilation.
437 # Calls back into system's target_compile to actually do the work.
438 proc v3_target_compile_as_c { source dest type options } {
439     global gluefile 
440     global wrap_flags
441     global includes
442     global flags_file
443     global blddir
444     global cc
445     global cxxflags
446
447     if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
448         lappend options "libs=${gluefile}"
449         lappend options "ldflags=${wrap_flags}"
450     }
451
452     set tname [target_info name]
453     set cc_final $cc
454     set cxxlibglossflags [libgloss_link_flags]
455     set cc_final [concat $cc_final $cxxlibglossflags]
456     set cc_final [concat $cc_final $cxxflags]
457     set cc_final [concat $cc_final $includes]
458     regsub -all {\s[-]nostdinc[+][+]} $cc_final "" cc_final
459
460     # This is needed for "C" tests, as this type of test may need the
461     # C++ includes. And if we're not testing in the build directory,
462     # the includes variable is not likely to include the necessary
463     # info.
464     if { ![file exists $flags_file] } {
465         # ??? We need a --print-include-dirs option to GCC, so that
466         # we can avoid these hacks.  The heuristics here will not
467         # work with non-standard --with-includedir= options.
468         set version [remote_exec host ${cc} -dumpversion]
469         # Remove the trailing newline from the output.
470         set version [string trimright [lindex $version 1]]
471         set machine [remote_exec host ${cc} -dumpmachine]
472         set machine [string trimright [lindex $machine 1]]
473         set comp_base_dir [remote_exec host ${cc} --print-prog-name=cc1]
474         set comp_base_dir [lindex $comp_base_dir 1]
475         set comp_base_dir [file dirname [file dirname [file dirname [file dirname [file dirname $comp_base_dir]]]]]
476         # For a cross compiler, the header files will be located in a
477         # machine-specific subdirectory.
478         set crossbase "${comp_base_dir}/${machine}/include/c++/${version}"
479         set crosstarget "${crossbase}/${machine}"
480         set cc_final [concat $cc_final "-I$crossbase -I$crosstarget"]
481         # For a native compiler, the header files will be located at 
482         # the top level.
483         set includesbase "${comp_base_dir}/include/c++/${version}"
484         set includestarget "${includesbase}/${machine}"
485         set cc_final [concat $cc_final "-I$includesbase -I$includestarget"]
486
487         set libdir "-L${comp_base_dir}/lib"
488     } else {
489         set libdir "-L${blddir}/libsupc++/.libs"
490         set libdir [concat $libdir "-L${blddir}/src/.libs"]
491     }
492
493     set cc_final [concat $cc_final "$libdir"]
494
495     lappend options "compiler=$cc_final"
496     lappend options "timeout=[timeout_value]"
497
498     return [target_compile $source $dest $type $options]
499 }
500
501 # Build the support objects linked in with the libstdc++ tests.  In
502 # addition, set v3-wchar_t, v3-threads, and v3-symver appropriately.
503 proc v3-build_support { } {
504     global env
505     global srcdir
506     global v3-wchar_t
507     global v3-threads
508     global v3-symver
509     global v3-sharedlib
510
511     # Figure out whether or not the library supports certain features.
512     set v3-wchar_t 0
513     set v3-threads 0
514     set v3-symver 0
515     set libtest_objs ""
516
517     set config_src "config.cc"
518     set config_out "config.ii"
519     set f [open $config_src "w"]
520     puts $f "#include <bits/c++config.h>"
521     puts $f "#include <bits/gthr.h>"
522     close $f
523     v3_target_compile $config_src $config_out preprocess "additional_flags=-dN"
524     set file [open $config_out r]
525     set preprocessed [read $file]
526     close $file
527     if { [string first "_GLIBCXX_USE_WCHAR_T" $preprocessed] != -1 } {
528         verbose -log "wchar_t support detected"
529         set v3-wchar_t 1
530     }
531     if { [string first "_GLIBCXX_SYMVER" $preprocessed] != -1 } {
532         verbose -log "symbol versioning support detected"
533         set v3-symver 1
534     }
535     if { [string first "__GTHREADS" $preprocessed] != -1 } {
536         verbose -log "thread support detected"
537         set v3-threads 1
538     }
539
540     # Try to build the MO files that are used by some of the locale
541     # tests.  If we can't build them, that's OK; it just means that
542     # those tests will fail.
543     foreach lang [list "fr" "de"] {
544         catch {
545             file mkdir "$lang/LC_MESSAGES"
546             remote_exec "build" "msgfmt" "-o $lang/LC_MESSAGES/libstdc++.mo $srcdir/../po/$lang.po"
547             if [is_remote host] {
548                 remote_exec "host" "mkdir" "-p $lang/LC_MESSAGES"
549                 remote_download "host" "$lang/LC_MESSAGES/libstdc++.mo" "$lang/LC_MESSAGES/libstdc++.mo"
550             }
551         }
552     }
553
554     # Build the support objects.
555     set source_files [list testsuite_abi.cc testsuite_allocator.cc \
556                           testsuite_character.cc testsuite_hooks.cc \
557                           io/verified_cmd_line_input.cc \
558                           io/prog_bar.cc performance/time/elapsed_timer.cc ]
559     foreach f $source_files {
560         set obj [file rootname $f].o
561         set object_file [file tail $obj]
562         # Compile with "-w" so that warnings issued by the compiler
563         # do not prevent compilation.
564         if { [v3_target_compile $srcdir/util/$f $object_file "object" \
565                   [list "incdir=$srcdir" "additional_flags=-w"]]
566              != "" } {
567             error "could not compile $f"
568         }
569         append libtest_objs "$object_file "
570     }
571
572     # Collect into libtestc++.a
573     if  [info exists env(AR)] {
574         set ar $env(AR)
575     } else {
576         set ar [transform "ar"]
577     }
578     set arargs "-rc ./libtestc++.a ${libtest_objs}"
579     verbose -log "$ar $arargs"
580     set result [lindex [remote_exec host "$ar" "$arargs"] 0]
581     verbose "link result is $result"
582     if { $result == 0 } {
583         if  [info exists env(RANLIB)] {
584             set ranlib $env(RANLIB)
585         } else {
586             set ranlib [transform "ranlib"]
587         }
588         set ranlibargs "./libtestc++.a"
589         verbose -log "$ranlib $ranlibargs"
590         set result [lindex [remote_exec host "$ranlib" "$ranlibargs"] 0]
591         if { $result != 0 } {
592             error "could not link libtestc++.a"
593         }
594     }
595
596     # Build any shared objects needed for regression testing.
597     if { ${v3-sharedlib} == 1 } {
598         set source_files [list testsuite_shared.cc]
599         foreach f $source_files {
600             set object_file [file rootname $f].so
601             # Compile with "-w" so that warnings issued by the compiler
602             # do not prevent compilation.
603             if { [v3_target_compile $srcdir/util/$f $object_file "sharedlib" \
604              [list "incdir=$srcdir" "additional_flags=-w -shared -fPIC -DPIC"]]
605                  != "" } {
606                 error "could not compile $f"
607             }
608         }
609     }
610 }
611
612 proc check_v3_target_fileio { } {
613     global et_fileio_saved
614     global et_fileio_target_name
615     global tool 
616
617     if { ![info exists et_fileio_target_name] } {
618         set et_fileio_target_name ""
619     }
620
621     # If the target has changed since we set the cached value, clear it.
622     set current_target [current_target_name]
623     if { $current_target != $et_fileio_target_name } {
624         verbose "check_v3_target_fileio: `$et_fileio_target_name'" 2
625         set et_fileio_target_name $current_target
626         if [info exists et_fileio_saved] {
627             verbose "check_v3_target_fileio: removing cached result" 2
628             unset et_fileio_saved
629         }
630     }
631
632     if [info exists et_fileio_saved] {
633         verbose "check_v3_target_fileio: using cached result" 2
634     } else {
635         set et_fileio_saved 0
636
637         # Set up, compile, and execute a C++ test program that tries to use
638         # the file functions
639         set src fileio[pid].cc
640         set exe fileio[pid].x
641
642         set f [open $src "w"]
643         puts $f "#include <sys/types.h>"
644         puts $f "#include <sys/stat.h>"
645         puts $f "#include <fcntl.h>"
646         puts $f "#include <unistd.h>"
647         puts $f "#include <errno.h>"
648         puts $f "using namespace std;"  
649         puts $f "int main ()"
650         puts $f "{"
651         puts $f "  int fd  = open (\".\", O_RDONLY);"
652         puts $f "  int ret = 0;"
653         puts $f "  if (fd == -1)"
654         puts $f "  {"
655         puts $f "    int err = errno;"
656         puts $f "    if (err == EIO || err == ENOSYS)"
657         puts $f "      ret = 1;"
658         puts $f "  }"
659         puts $f "  else"
660         puts $f "  {"
661         puts $f "    if (lseek (fd, 0, SEEK_CUR) == -1)"
662         puts $f "      ret = 1;"
663         puts $f "    close (fd);"
664         puts $f "  }"
665         puts $f "  return ret;"
666         puts $f "}" 
667         close $f
668
669         set lines [v3_target_compile $src $exe executable ""]
670         file delete $src
671
672         if [string match "" $lines] {
673             # No error message, compilation succeeded.
674             set result [${tool}_load "./$exe" "" ""]
675             set status [lindex $result 0]
676             remote_file build delete $exe
677
678             verbose "check_v3_target_fileio: status is <$status>" 2
679
680             if { $status == "pass" } {
681                 set et_fileio_saved 1
682             }
683         } else {
684             verbose "check_v3_target_fileio: compilation failed" 2
685         }
686     }
687     return $et_fileio_saved
688 }
689
690 # Eventually we want C90/C99 determining and switching from this.
691 proc check_v3_target_c_std { } {
692     global et_c_std_saved
693     global et_c_std_target_name
694     global tool 
695
696     if { ![info exists et_c_std_target_name] } {
697         set et_c_std_target_name ""
698     }
699
700     # If the target has changed since we set the cached value, clear it.
701     set current_target [current_target_name]
702     if { $current_target != $et_c_std_target_name } {
703         verbose "check_v3_target_c_std: `$et_c_std_target_name'" 2
704         set et_c_std_target_name $current_target
705         if [info exists et_c_std_saved] {
706             verbose "check_v3_target_c_std: removing cached result" 2
707             unset et_c_std_saved
708         }
709     }
710
711     if [info exists et_c_std_saved] {
712         verbose "check_v3_target_c_std: using cached result" 2
713     } else {
714         set et_c_std_saved 0
715
716         # Set up, compile, and execute a C++ test program that tries to use
717         # C99 functionality.
718         # For math bits, could use check_effective_target_c99_math.
719         set src fileio[pid].cc
720         set exe fileio[pid].x
721
722         set f [open $src "w"]
723         puts $f "#include <tr1/cmath>"
724         puts $f "#include <cstdlib>"
725         puts $f "int main ()"
726         puts $f "{"
727         puts $f "  float f = 45.55;"
728         puts $f "  int i = std::tr1::isnan(f);"
729         puts $f "  "
730         puts $f "  using std::wctomb;"
731         puts $f "  return i;"
732         puts $f "}" 
733         close $f
734
735         set lines [v3_target_compile $src $exe executable ""]
736         file delete $src
737
738         if [string match "" $lines] {
739             # No error message, compilation succeeded.
740             set result [${tool}_load "./$exe" "" ""]
741             set status [lindex $result 0]
742             remote_file build delete $exe
743
744             verbose "check_v3_target_c_std: status is <$status>" 2
745
746             if { $status == "pass" } {
747                 set et_c_std_saved 1
748             }
749         } else {
750             verbose "check_v3_target_c_std: compilation failed" 2
751         }
752     }
753     return $et_c_std_saved
754 }
755
756 proc check_v3_target_sharedlib { } {
757     global v3-sharedlib
758     return ${v3-sharedlib}
759 }
760
761 proc check_v3_target_time { } {
762     global et_time_saved
763     global et_time_target_name
764     global tool 
765
766     if { ![info exists et_time_target_name] } {
767         set et_time_target_name ""
768     }
769
770     # If the target has changed since we set the cached value, clear it.
771     set current_target [current_target_name]
772     if { $current_target != $et_time_target_name } {
773         verbose "check_v3_target_time: `$et_time_target_name'" 2
774         set et_time_target_name $current_target
775         if [info exists et_time_saved] {
776             verbose "check_v3_target_time: removing cached result" 2
777             unset et_time_saved
778         }
779     }
780
781     if [info exists et_time_saved] {
782         verbose "check_v3_target_time: using cached result" 2
783     } else {
784         set et_time_saved 0
785
786         # Set up and compile a C++ test program that tries to use
787         # the time function
788         set src time[pid].cc
789         set exe time[pid].x
790
791         set f [open $src "w"]
792         puts $f "#include <time.h>"
793         puts $f "using namespace std;"  
794         puts $f "int main ()"
795         puts $f "{"
796         puts $f "  time (0);"   
797         puts $f "}" 
798         close $f
799
800         set lines [v3_target_compile $src $exe executable ""]
801         file delete $src
802
803         if [string match "" $lines] {
804             # No error message, compilation succeeded.
805             verbose "check_v3_target_time: compilation succeeded" 2
806             remote_file build delete $exe
807             set et_time_saved 1
808         } else {
809             verbose "check_v3_target_time: compilation failed" 2
810         }
811     }
812     return $et_time_saved
813 }
814
815 proc check_v3_target_namedlocale { } {
816     global et_namedlocale_saved
817     global et_namedlocale_target_name
818     global tool 
819
820     if { ![info exists et_namedlocale_target_name] } {
821         set et_namedlocale_target_name ""
822     }
823
824     # If the target has changed since we set the cached value, clear it.
825     set current_target [current_target_name]
826     if { $current_target != $et_namedlocale_target_name } {
827         verbose "check_v3_target_namedlocale: `$et_namedlocale_target_name'" 2
828         set et_namedlocale_target_name $current_target
829         if [info exists et_namedlocale_saved] {
830             verbose "check_v3_target_namedlocale: removing cached result" 2
831             unset et_namedlocale_saved
832         }
833     }
834
835     if [info exists et_namedlocale_saved] {
836         verbose "check_v3_target_namedlocale: using cached result" 2
837     } else {
838         set et_namedlocale_saved 0
839
840         # Set up, compile, and execute a C++ test program that tries to use
841         # all the required named locales.
842         set src nlocale[pid].cc
843         set exe nlocale[pid].x
844
845         set f [open $src "w"]
846         puts $f "#include <locale>"
847         puts $f "using namespace std;"  
848         puts $f "int main ()"
849         puts $f "{"
850         puts $f "  try" 
851         puts $f "  {" 
852         puts $f "     locale(\"\");"
853         puts $f "     locale(\"de_DE\");"
854         puts $f "     locale(\"de_DE.ISO-8859-15@euro\");"
855         puts $f "     locale(\"de_DE@euro\");"
856         puts $f "     locale(\"en_HK\");"
857         puts $f "     locale(\"en_PH\");"
858         puts $f "     locale(\"en_US\");"
859         puts $f "     locale(\"en_US.ISO-8859-1\");"
860         puts $f "     locale(\"en_US.ISO-8859-15\");"
861         puts $f "     locale(\"en_US.UTF-8\");"
862         puts $f "     locale(\"es_ES\");"
863         puts $f "     locale(\"es_MX\");"
864         puts $f "     locale(\"fr_FR\");"
865         puts $f "     locale(\"fr_FR@euro\");"
866         puts $f "     locale(\"is_IS\");"
867         puts $f "     locale(\"is_IS.UTF-8\");"
868         puts $f "     locale(\"it_IT\");"
869         puts $f "     locale(\"ja_JP.eucjp\");"
870         puts $f "     locale(\"se_NO.UTF-8\");"
871         puts $f "     locale(\"ta_IN\");"
872         puts $f "     locale(\"zh_TW\");"
873         puts $f "     return 0;"
874         puts $f "  }"
875         puts $f "  catch(...)"
876         puts $f "  {"
877         puts $f "     return 1;"
878         puts $f "  }"   
879         puts $f "}"
880         close $f
881
882         set lines [v3_target_compile $src $exe executable ""]
883         file delete $src
884
885         if [string match "" $lines] {
886             # No error message, compilation succeeded.
887             set result [${tool}_load "./$exe" "" ""]
888             set status [lindex $result 0]
889             remote_file build delete $exe
890
891             verbose "check_v3_target_namedlocale: status is <$status>" 2
892
893             if { $status == "pass" } {
894                 set et_namedlocale_saved 1
895             }
896         } else {
897             verbose "check_v3_target_namedlocale: compilation failed" 2
898         }
899     }
900     return $et_namedlocale_saved
901 }
902
903 proc check_v3_target_debug_mode { } {
904     global cxxflags
905     global et_debug_mode
906     global tool 
907
908     if { ![info exists et_debug_mode_target_name] } {
909         set et_debug_mode_target_name ""
910     }
911
912     # If the target has changed since we set the cached value, clear it.
913     set current_target [current_target_name]
914     if { $current_target != $et_debug_mode_target_name } {
915         verbose "check_v3_target_debug_mode: `$et_debug_mode_target_name'" 2
916         set et_debug_mode_target_name $current_target
917         if [info exists et_debug_mode] {
918             verbose "check_v3_target_debug_mode: removing cached result" 2
919             unset et_debug_mode
920         }
921     }
922
923     if [info exists et_debug_mode] {
924         verbose "check_v3_target_debug_mode: using cached result" 2
925     } else {
926         set et_debug_mode 0
927
928         # Set up and compile a C++ test program that depends
929         # on debug mode working.
930         set src debug_mode[pid].cc
931         set exe debug_mode[pid].exe
932
933         set f [open $src "w"]
934         puts $f "#include <string>"
935         puts $f "using namespace std;"  
936         puts $f "int main()"
937         puts $f "{ return 0; }"
938         close $f
939
940         set cxxflags_saved $cxxflags
941         set cxxflags "$cxxflags -Werror -O0 -D_GLIBCXX_DEBUG"
942         set lines [v3_target_compile $src $exe executable ""]
943         set cxxflags $cxxflags_saved
944         file delete $src
945
946         if [string match "" $lines] {
947             # No error message, compilation succeeded.
948             set et_debug_mode 1
949         }
950     }
951     verbose "check_v3_target_debug_mode: $et_debug_mode" 2
952     return $et_debug_mode
953 }
954
955 proc check_v3_target_parallel_mode { } {
956     global cxxflags
957     global v3-libgomp
958     global et_parallel_mode
959
960     global tool 
961
962     if { ![info exists et_parallel_mode_target_name] } {
963         set et_parallel_mode_target_name ""
964     }
965
966     # If the target has changed since we set the cached value, clear it.
967     set current_target [current_target_name]
968     if { $current_target != $et_parallel_mode_target_name } {
969         verbose "check_v3_target_parallel_mode: `$et_parallel_mode_target_name'" 2
970         set et_parallel_mode_target_name $current_target
971         if [info exists et_parallel_mode] {
972             verbose "check_v3_target_parallel_mode: removing cached result" 2
973             unset et_parallel_mode
974         }
975     }
976
977     if [info exists et_parallel_mode] {
978         verbose "check_v3_target_parallel_mode: using cached result" 2
979     } else {
980         set et_parallel_mode 0
981
982         # If 'make check-parallel' is running the test succeeds.
983         if { ${v3-libgomp} == 1 && [regexp "libgomp" $cxxflags] } {
984             set et_parallel_mode 1
985         }
986     }
987     verbose "check_v3_target_parallel_mode: $et_parallel_mode" 2
988     return $et_parallel_mode
989 }
990
991 proc check_v3_target_cstdint { } {
992     global cxxflags
993     global DEFAULT_CXXFLAGS
994     global et_cstdint
995
996     global tool 
997
998     if { ![info exists et_cstdint_target_name] } {
999         set et_cstdint_target_name ""
1000     }
1001
1002     # If the target has changed since we set the cached value, clear it.
1003     set current_target [current_target_name]
1004     if { $current_target != $et_cstdint_target_name } {
1005         verbose "check_v3_target_cstdint: `$et_cstdint_target_name'" 2
1006         set et_cstdint_target_name $current_target
1007         if [info exists et_cstdint] {
1008             verbose "check_v3_target_cstdint: removing cached result" 2
1009             unset et_cstdint
1010         }
1011     }
1012
1013     if [info exists et_cstdint] {
1014         verbose "check_v3_target_cstdint: using cached result" 2
1015     } else {
1016         set et_cstdint 0
1017
1018         # Set up and compile a C++0x test program that depends
1019         # on the C99 stdint facilities to be available.
1020         set src cstdint[pid].cc
1021         set exe cstdint[pid].exe
1022
1023         set f [open $src "w"]
1024         puts $f "#include <tr1/cstdint>"
1025         puts $f "int main()"
1026         puts $f "#ifdef _GLIBCXX_USE_C99_STDINT_TR1"
1027         puts $f "{ return 0; }"
1028         puts $f "#endif"
1029         close $f
1030
1031         set cxxflags_saved $cxxflags
1032         set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror"
1033
1034         set lines [v3_target_compile $src $exe executable ""]
1035         set cxxflags $cxxflags_saved
1036         file delete $src
1037
1038         if [string match "" $lines] {
1039             # No error message, compilation succeeded.
1040             set et_cstdint 1
1041         } else {
1042             verbose "check_v3_target_cstdint: compilation failed" 2
1043         }
1044     }
1045     verbose "check_v3_target_cstdint: $et_cstdint" 2
1046     return $et_cstdint
1047 }
1048
1049 proc check_v3_target_atomic_builtins { } {
1050     global cxxflags
1051     global DEFAULT_CXXFLAGS
1052     global et_cstdint
1053
1054     global tool 
1055
1056     if { ![info exists et_atomic_builtins_target_name] } {
1057         set et_atomic_builtins_target_name ""
1058     }
1059
1060     # If the target has changed since we set the cached value, clear it.
1061     set current_target [current_target_name]
1062     if { $current_target != $et_atomic_builtins_target_name } {
1063         verbose "check_v3_target_atomic_builtins: `$et_atomic_builtins_target_name'" 2
1064         set et_atomic_builtins_target_name $current_target
1065         if [info exists et_atomic_builtins] {
1066             verbose "check_v3_target_atomic_builtins: removing cached result" 2
1067             unset et_atomic_builtins
1068         }
1069     }
1070
1071     if [info exists et_atomic_builtins] {
1072         verbose "check_v3_target_atomic_builtins: using cached result" 2
1073     } else {
1074         set et_atomic_builtins 0
1075
1076         # Set up and compile a C++0x test program that depends
1077         # on the atomic builtin facilities to be available.
1078         set src atomic_builtins[pid].cc
1079         set exe atomic_builtins[pid].exe
1080
1081         set f [open $src "w"]
1082         puts $f "#include <bits/c++config.h>"
1083         puts $f "int main()"
1084         puts $f "#ifdef _GLIBCXX_ATOMIC_BUILTINS_4"
1085         puts $f "{ return 0; }"
1086         puts $f "#endif"
1087         close $f
1088
1089         set cxxflags_saved $cxxflags
1090         set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror"
1091
1092         set lines [v3_target_compile $src $exe executable ""]
1093         set cxxflags $cxxflags_saved
1094         file delete $src
1095
1096         if [string match "" $lines] {
1097             # No error message, compilation succeeded.
1098             set et_atomic_builtins 1
1099         } else {
1100             verbose "check_v3_target_atomic_builtins: compilation failed" 2
1101         }
1102     }
1103     verbose "check_v3_target_atomic_builtins: $et_atomic_builtins" 2
1104     return $et_atomic_builtins
1105 }
1106
1107 proc check_v3_target_gthreads { } {
1108     global cxxflags
1109     global DEFAULT_CXXFLAGS
1110     global et_gthreads
1111
1112     global tool
1113
1114     if { ![info exists et_gthreads_target_name] } {
1115         set et_gthreads_target_name ""
1116     }
1117
1118     # If the target has changed since we set the cached value, clear it.
1119     set current_target [current_target_name]
1120     if { $current_target != $et_gthreads_target_name } {
1121         verbose "check_v3_target_gthreads: `$et_gthreads_target_name'" 2
1122         set et_gthreads_target_name $current_target
1123         if [info exists et_gthreads] {
1124             verbose "check_v3_target_gthreads: removing cached result" 2
1125             unset et_gthreads
1126         }
1127     }
1128
1129     if [info exists et_gthreads] {
1130         verbose "check_v3_target_gthreads: using cached result" 2
1131     } else {
1132         set et_gthreads 0
1133
1134         # Set up and compile a C++0x test program that depends
1135         # on the gthreads facilities to be available.
1136         set src gthreads[pid].cc
1137         set exe gthreads[pid].exe
1138
1139         set f [open $src "w"]
1140         puts $f "#include <bits/c++config.h>"
1141         puts $f "int main()"
1142         puts $f "#ifdef _GLIBCXX_HAS_GTHREADS"
1143         puts $f "{ return 0; }"
1144         puts $f "#endif"
1145         close $f
1146
1147         set cxxflags_saved $cxxflags
1148         set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror"
1149
1150         set lines [v3_target_compile $src $exe executable ""]
1151         set cxxflags $cxxflags_saved
1152         file delete $src
1153
1154         if [string match "" $lines] {
1155             # No error message, compilation succeeded.
1156             set et_gthreads 1
1157         } else {
1158             verbose "check_v3_target_gthreads: compilation failed" 2
1159         }
1160     }
1161     verbose "check_v3_target_gthreads: $et_gthreads" 2
1162     return $et_gthreads
1163 }
1164
1165 proc check_v3_target_nanosleep { } {
1166     global cxxflags
1167     global DEFAULT_CXXFLAGS
1168     global et_nanosleep
1169
1170     global tool
1171
1172     if { ![info exists et_nanosleep_target_name] } {
1173         set et_nanosleep_target_name ""
1174     }
1175
1176     # If the target has changed since we set the cached value, clear it.
1177     set current_target [current_target_name]
1178     if { $current_target != $et_nanosleep_target_name } {
1179         verbose "check_v3_target_nanosleep: `$et_nanosleep_target_name'" 2
1180         set et_nanosleep_target_name $current_target
1181         if [info exists et_nanosleep] {
1182             verbose "check_v3_target_nanosleep: removing cached result" 2
1183             unset et_nanosleep
1184         }
1185     }
1186
1187     if [info exists et_nanosleep] {
1188         verbose "check_v3_target_nanosleep: using cached result" 2
1189     } else {
1190         set et_nanosleep 0
1191         
1192         # Set up and compile a C++0x test program that depends
1193         # on the nanosleep facilities to be available.
1194         set src nanosleep[pid].cc
1195         set exe nanosleep[pid].exe
1196
1197         set f [open $src "w"]
1198         puts $f "#include <bits/c++config.h>"
1199         puts $f "int main()"
1200         puts $f "#ifdef _GLIBCXX_USE_NANOSLEEP"
1201         puts $f "{ return 0; }"
1202         puts $f "#endif"
1203         close $f
1204
1205         set cxxflags_saved $cxxflags
1206         set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror"
1207
1208         set lines [v3_target_compile $src $exe executable ""]
1209         set cxxflags $cxxflags_saved
1210         file delete $src
1211
1212         if [string match "" $lines] {
1213             # No error message, compilation succeeded.
1214             set et_nanosleep 1
1215         } else {
1216             verbose "check_v3_target_nanosleep: compilation failed" 2
1217         }
1218     }
1219     verbose "check_v3_target_nanosleep: $et_nanosleep" 2
1220     return $et_nanosleep
1221 }
1222
1223 proc check_v3_target_sched_yield { } {
1224     global cxxflags
1225     global DEFAULT_CXXFLAGS
1226     global et_sched_yield
1227
1228     global tool
1229
1230     if { ![info exists et_sched_yield_target_name] } {
1231         set et_sched_yield_target_name ""
1232     }
1233
1234     # If the target has changed since we set the cached value, clear it.
1235     set current_target [current_target_name]
1236     if { $current_target != $et_sched_yield_target_name } {
1237         verbose "check_v3_target_sched_yield: `$et_sched_yield_target_name'" 2
1238         set et_sched_yield_target_name $current_target
1239         if [info exists et_sched_yield] {
1240             verbose "check_v3_target_sched_yield: removing cached result" 2
1241             unset et_sched_yield
1242         }
1243     }
1244
1245     if [info exists et_sched_yield] {
1246         verbose "check_v3_target_sched_yield: using cached result" 2
1247     } else {
1248         set et_sched_yield 0
1249
1250         # Set up and compile a C++0x test program that depends
1251         # on the sched_yield facility to be available.
1252         set src sched_yield[pid].cc
1253         set exe sched_yield[pid].exe
1254
1255         set f [open $src "w"]
1256         puts $f "#include <bits/c++config.h>"
1257         puts $f "int main()"
1258         puts $f "#ifdef _GLIBCXX_USE_SCHED_YIELD"
1259         puts $f "{ return 0; }"
1260         puts $f "#endif"
1261         close $f
1262
1263         set cxxflags_saved $cxxflags
1264         set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror"
1265
1266         set lines [v3_target_compile $src $exe executable ""]
1267         set cxxflags $cxxflags_saved
1268         file delete $src
1269
1270         if [string match "" $lines] {
1271             # No error message, compilation succeeded.
1272             set et_sched_yield 1
1273         } else {
1274             verbose "check_v3_target_sched_yield: compilation failed" 2
1275         }
1276     }
1277     verbose "check_v3_target_sched_yield: $et_sched_yield" 2
1278     return $et_sched_yield
1279 }
1280
1281 proc check_v3_target_string_conversions { } {
1282     global cxxflags
1283     global DEFAULT_CXXFLAGS
1284     global et_string_conversions
1285
1286     global tool
1287
1288     if { ![info exists et_string_conversions_target_name] } {
1289         set et_string_conversions_target_name ""
1290     }
1291
1292     # If the target has changed since we set the cached value, clear it.
1293     set current_target [current_target_name]
1294     if { $current_target != $et_string_conversions_target_name } {
1295         verbose "check_v3_target_string_conversions: `$et_string_conversions_target_name'" 2
1296         set et_string_conversions_target_name $current_target
1297         if [info exists et_string_conversions] {
1298             verbose "check_v3_target_string_conversions: removing cached result" 2
1299             unset et_string_conversions
1300         }
1301     }
1302
1303     if [info exists et_string_conversions] {
1304         verbose "check_v3_target_string_conversions: using cached result" 2
1305     } else {
1306         set et_string_conversions 0
1307         
1308         # Set up and compile a C++0x test program that depends
1309         # on the string_conversions facilities to be available.
1310         set src string_conversions[pid].cc
1311         set exe string_conversions[pid].exe
1312
1313         set f [open $src "w"]
1314         puts $f "#include <bits/c++config.h>"
1315         puts $f "int main()"
1316         puts $f "#if defined(_GLIBCXX_USE_C99) && !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF)"
1317         puts $f "{ return 0; }"
1318         puts $f "#endif"
1319         close $f
1320
1321         set cxxflags_saved $cxxflags
1322         set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror"
1323
1324         set lines [v3_target_compile $src $exe executable ""]
1325         set cxxflags $cxxflags_saved
1326         file delete $src
1327
1328         if [string match "" $lines] {
1329             # No error message, compilation succeeded.
1330             set et_string_conversions 1
1331         } else {
1332             verbose "check_v3_target_string_conversions: compilation failed" 2
1333         }
1334     }
1335     verbose "check_v3_target_string_conversions: $et_string_conversions" 2
1336     return $et_string_conversions
1337 }
1338
1339 proc check_v3_target_swprintf { } {
1340     global cxxflags
1341     global DEFAULT_CXXFLAGS
1342     global et_swprintf
1343
1344     global tool
1345
1346     if { ![info exists et_swprintf_target_name] } {
1347         set et_swprintf_target_name ""
1348     }
1349
1350     # If the target has changed since we set the cached value, clear it.
1351     set current_target [current_target_name]
1352     if { $current_target != $et_swprintf_target_name } {
1353         verbose "check_v3_target_swprintf: `$et_swprintf_target_name'" 2
1354         set et_swprintf_target_name $current_target
1355         if [info exists et_swprintf] {
1356             verbose "check_v3_target_swprintf: removing cached result" 2
1357             unset et_swprintf
1358         }
1359     }
1360
1361     if [info exists et_swprintf] {
1362         verbose "check_v3_target_swprintf: using cached result" 2
1363     } else {
1364         set et_swprintf 0
1365         
1366         # Set up and compile a C++0x test program that depends
1367         # on a standard swprintf function to be available.
1368         set src swprintf[pid].cc
1369         set exe swprintf[pid].exe
1370
1371         set f [open $src "w"]
1372         puts $f "#include <bits/c++config.h>"
1373         puts $f "int main()"
1374         puts $f "#if !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF)"
1375         puts $f "{ return 0; }"
1376         puts $f "#endif"
1377         close $f
1378
1379         set cxxflags_saved $cxxflags
1380         set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror"
1381
1382         set lines [v3_target_compile $src $exe executable ""]
1383         set cxxflags $cxxflags_saved
1384         file delete $src
1385
1386         if [string match "" $lines] {
1387             # No error message, compilation succeeded.
1388             set et_swprintf 1
1389         } else {
1390             verbose "check_v3_target_swprintf: compilation failed" 2
1391         }
1392     }
1393     verbose "check_v3_target_swprintf: $et_swprintf" 2
1394     return $et_swprintf
1395 }
1396
1397 proc check_v3_target_binary_io { } {
1398     global cxxflags
1399     global DEFAULT_CXXFLAGS
1400     global et_binary_io
1401
1402     global tool
1403
1404     if { ![info exists et_binary_io_target_name] } {
1405         set et_binary_io_target_name ""
1406     }
1407
1408     # If the target has changed since we set the cached value, clear it.
1409     set current_target [current_target_name]
1410     if { $current_target != $et_binary_io_target_name } {
1411         verbose "check_v3_target_binary_io: `$et_binary_io_target_name'" 2
1412         set et_binary_io_target_name $current_target
1413         if [info exists et_binary_io] {
1414             verbose "check_v3_target_binary_io: removing cached result" 2
1415             unset et_binary_io
1416         }
1417     }
1418
1419     if [info exists et_binary_io] {
1420         verbose "check_v3_target_binary_io: using cached result" 2
1421     } else {
1422         set et_binary_io 0
1423         
1424         # Set up and compile a C++0x test program that depends
1425         # on text and binary I/O being the same.
1426         set src binary_io[pid].cc
1427         set exe binary_io[pid].exe
1428
1429         set f [open $src "w"]
1430         puts $f "#include <bits/c++config.h>"
1431         puts $f "int main()"
1432         puts $f "#if !defined(_GLIBCXX_HAVE_DOS_BASED_FILESYSTEM)"
1433         puts $f "{ return 0; }"
1434         puts $f "#endif"
1435         close $f
1436
1437         set cxxflags_saved $cxxflags
1438         set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror"
1439
1440         set lines [v3_target_compile $src $exe executable ""]
1441         set cxxflags $cxxflags_saved
1442         file delete $src
1443
1444         if [string match "" $lines] {
1445             # No error message, compilation succeeded.
1446             set et_binary_io 1
1447         } else {
1448             verbose "check_v3_target_binary_io: compilation failed" 2
1449         }
1450     }
1451     verbose "check_v3_target_binary_io: $et_binary_io" 2
1452     return $et_binary_io
1453 }