OSDN Git Service

2008-07-31 Paolo Carlini <paolo.carlini@oracle.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
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 v3-libgomp
85     global srcdir blddir objdir tool_root_dir
86     global cc cxx cxxflags cxxpchflags 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 v3-libgomp 0
139     set libgompdir [lookfor_file $blddir/../libgomp .libs/libgomp.so]
140     if {$libgompdir != ""} {
141         set v3-libgomp 1
142         set libgompdir [file dirname $libgompdir]
143         append ld_library_path_tmp ":${libgompdir}"
144         verbose -log "libgomp support detected"
145     }
146     v3track libgompdir 3
147
148     # Locate libstdc++ shared library. (ie libstdc++.so.)
149     set v3-sharedlib 0
150     set sharedlibdir [lookfor_file $blddir src/.libs/libstdc++.so]
151     if {$sharedlibdir != ""} {
152         if { [string match "*-*-linux*" $target_triplet] && [isnative] } {
153             set v3-sharedlib 1
154             verbose -log "shared library support detected"
155         } 
156     }
157     v3track v3-sharedlib 3
158
159     # Compute what needs to be added to the existing LD_LIBRARY_PATH.
160     if {$gccdir != ""} {
161         set compiler ${gccdir}/g++
162         set ld_library_path ${ld_library_path_tmp}
163         append ld_library_path ":${blddir}/src/.libs"
164
165         if { [is_remote host] == 0 && [which $compiler] != 0 } {
166           foreach i "[exec $compiler --print-multi-lib]" {
167             set mldir ""
168             regexp -- "\[a-z0-9=_/\.-\]*;" $i mldir
169             set mldir [string trimright $mldir "\;@"]
170             if { "$mldir" == "." } {
171               continue
172             }
173             if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] >= 1 } {
174               append ld_library_path ":${gccdir}/${mldir}"
175             }
176           }
177         }
178
179         set_ld_library_path_env_vars
180         if [info exists env(LD_LIBRARY_PATH)] {
181           verbose -log "LD_LIBRARY_PATH = $env(LD_LIBRARY_PATH)"
182         }
183     } else {
184         set compiler [transform "g++"]
185     }
186
187     # Default settings.
188     set cxx [transform "g++"]
189     set cxxflags "-g -O2 -D_GLIBCXX_ASSERT -fmessage-length=0"
190     set cxxpchflags ""
191     set cxxldflags ""
192     set cc [transform "gcc"]
193     # Locate testsuite_hooks.h and other testsuite headers.
194     set includes "-I${srcdir}/util"
195     # Adapt the defaults for special circumstances.
196     if [is_remote host] {
197         # A remote host does not, in general, have access to the
198         # $srcdir so we copy the testsuite headers into the current
199         # directory, and then add that to the search path.
200         foreach src [glob "${srcdir}/util/*.h" \
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                           "${srcdir}/util/*/*/*/*.cc" \
208                           "${srcdir}/util/*/*/*/*.hpp" \
209                           "${srcdir}/util/*/*/*/*/*.cc" \
210                           "${srcdir}/util/*/*/*/*/*.hpp" ] {
211             # Remove everything up to "util/..."
212             set dst [string range $src [string length "${srcdir}/"] end]
213             # Create the directory containing the file.
214             set dir [file dirname $dst]
215             remote_exec host "mkdir" [list "-p" "$dir"]
216             # Download the file.
217             set result [remote_download host $src $dst]
218             if { $result == "" } {
219                 verbose -log "Unable to download ${srcdir}/${src} to host."
220                 return "untested"
221             }
222         }
223         set includes "-Iutil"
224     } elseif { [file exists $flags_file] } {
225         # If we find a testsuite_flags file, we're testing in the build dir.
226         set cxx [exec sh $flags_file --build-cxx]
227         set cxxflags [exec sh $flags_file --cxxflags]
228         set cxxpchflags [exec sh $flags_file --cxxpchflags]
229         set cxxldflags [exec sh $flags_file --cxxldflags]
230         set cc [exec sh $flags_file --build-cc]
231         set includes [exec sh $flags_file --build-includes]
232     }
233     append cxxflags " "
234     append cxxflags [getenv CXXFLAGS]
235     v3track cxxflags 2
236
237     # Always use MO files built by this test harness.
238     set cxxflags "$cxxflags -DLOCALEDIR=\".\""
239     set ccflags "$cxxflags -DLOCALEDIR=\".\""
240
241     # If a PCH file is available, use it.  We must delay performing
242     # this check until $cxx and such have been initialized because we
243     # perform a test compilation.  (Ideally, gcc --print-file-name would
244     # list PCH files, but it does not.)
245     if { $cxxpchflags != "" } {
246         set src "config[pid].cc"
247         set f [open $src "w"]
248         puts $f "int main () {}"
249         close $f
250
251         # Fixme: "additional_flags=$cxxpchflags" fails, but would be
252         # useful as then the requested variant of the pre-build PCH
253         # files could be tested to see if it works.
254         set lines [v3_target_compile $src "config[pid].o" object \
255                    "additional_flags=-include additional_flags=bits/stdc++.h"]
256         if { $lines != "" } {
257             verbose -log "Requested PCH file: $cxxpchflags"
258             verbose -log "is not working, and will not be used."
259             set cxxpchflags ""
260         } 
261         file delete $src
262      } 
263     v3track cxxpchflags 2
264
265     global PCH_CXXFLAGS
266     if ![info exists PCH_CXXFLAGS] then {
267         set PCH_CXXFLAGS $cxxpchflags
268         v3track PCH_CXXFLAGS 2
269     }
270
271     libstdc++_maybe_build_wrapper "${objdir}/testglue.o" "-fexceptions"
272 }
273
274 # Callback for cleanup routines.
275 proc libstdc++_exit { } {
276     global gluefile;
277
278     if [info exists gluefile] {
279         file_on_build delete $gluefile;
280         unset gluefile;
281     }
282 }
283
284 # Callback from system dg-test.
285 proc libstdc++-dg-test { prog do_what extra_tool_flags } {
286     # Set up the compiler flags, based on what we're going to do.
287     switch $do_what {
288         "preprocess" {
289             set compile_type "preprocess"
290             set output_file "[file rootname [file tail $prog]].i"
291         }
292         "compile" {
293             set compile_type "assembly"
294             set output_file "[file rootname [file tail $prog]].s"
295         }
296         "assemble" {
297             set compile_type "object"
298             set output_file "[file rootname [file tail $prog]].o"
299         }
300         "link" {
301             set compile_type "executable"
302             set output_file "./[file rootname [file tail $prog]].exe"
303         }
304         "run" {
305             set compile_type "executable"
306             # FIXME: "./" is to cope with "." not being in $PATH.
307             # Should this be handled elsewhere?
308             # YES.
309             set output_file "./[file rootname [file tail $prog]].exe"
310             # This is the only place where we care if an executable was
311             # created or not.  If it was, dg.exp will try to run it.
312             catch { remote_file build delete $output_file }
313         }
314         default {
315             perror "$do_what: not a valid dg-do keyword"
316             return ""
317         }
318     }
319
320     # Short-circut a bunch of complicated goo here for the special
321     # case of compiling a test file as a "C" file, not as C++. Why? So
322     # -nostdc++ doesn't trip us up. So all the extra object files
323     # don't trip us up. So automatically linking in libstdc++ doesn't
324     # happen. So CXXFLAGS don't error.
325     set select_compile "v3_target_compile"
326     set options ""
327     if { $extra_tool_flags != "" } {
328         verbose -log "extra_tool_flags are:"
329         verbose -log $extra_tool_flags
330         if { [string first "-x c" $extra_tool_flags ] != -1 } {
331             verbose -log "compiling and executing as C, not C++"
332             set edit_tool_flags $extra_tool_flags
333             regsub -all ".x c" $edit_tool_flags "" edit_tool_flags
334             lappend options "additional_flags=$edit_tool_flags"
335             set select_compile "v3_target_compile_as_c"
336         } else {
337             lappend options "additional_flags=$extra_tool_flags"
338         }
339     }
340
341     # There is a libstdc++_compile made for us by default (via the tool-
342     # and-target file), but the defaults are lacking in goodness.
343     set comp_output [$select_compile "$prog" "$output_file" "$compile_type" $options];
344     set comp_output [ prune_g++_output $comp_output ];
345
346     return [list $comp_output $output_file]
347 }
348
349 # True if the library supports wchar_t.
350 set v3-wchar_t 0
351
352 # True if the library supports threads.
353 set v3-threads 0
354
355 # True if the library supports symbol versioning.
356 set v3-symver 0
357
358 # Called from libstdc++-dg-test above.  Calls back into system's
359 # target_compile to actually do the work.
360 proc v3_target_compile { source dest type options } {
361     global gluefile 
362     global wrap_flags
363     global cxx
364     global cxxflags
365     global cxxldflags
366     global includes
367
368     if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
369         lappend options "libs=${gluefile}"
370         lappend options "ldflags=${wrap_flags}"
371     }
372
373     set cxx_final $cxx
374     set cxxlibglossflags  [libgloss_link_flags]
375     set cxx_final [concat $cxx_final $cxxlibglossflags]
376     set cxx_final [concat $cxx_final $cxxflags]
377     set cxx_final [concat $cxx_final $includes]
378
379     # Flag setting based on type argument.
380     if { $type == "executable" } {
381         # Link the support objects into executables.
382         set cxx_final [concat $cxx_final $cxxldflags]
383         lappend options "additional_flags=./libtestc++.a"
384     } else {
385         if { $type == "sharedlib" } {
386             # Don't link in anything.
387             set type "executable"
388         }
389     }
390
391     lappend options "compiler=$cxx_final"
392     lappend options "timeout=600"
393
394     return [target_compile $source $dest $type $options]
395 }
396
397
398 # Called from libstdc++-dg-test above, but only for "C" compilation.
399 # Calls back into system's target_compile to actually do the work.
400 proc v3_target_compile_as_c { source dest type options } {
401     global gluefile 
402     global wrap_flags
403     global includes
404     global flags_file
405     global blddir
406     global cc
407     global cxxflags
408
409     if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
410         lappend options "libs=${gluefile}"
411         lappend options "ldflags=${wrap_flags}"
412     }
413
414     set tname [target_info name]
415     set cc_final $cc
416     set cxxlibglossflags [libgloss_link_flags]
417     set cc_final [concat $cc_final $cxxlibglossflags]
418     set cc_final [concat $cc_final $cxxflags]
419     set cc_final [concat $cc_final $includes]
420     regsub -all {\s[-]nostdinc[+][+]} $cc_final "" cc_final
421
422     # This is needed for "C" tests, as this type of test may need the
423     # C++ includes. And if we're not testing in the build directory,
424     # the includes variable is not likely to include the necessary
425     # info.
426     if { ![file exists $flags_file] } {
427         # ??? We need a --print-include-dirs option to GCC, so that
428         # we can avoid these hacks.  The heuristics here will not
429         # work with non-standard --with-includedir= options.
430         set version [remote_exec host ${cc} -dumpversion]
431         # Remove the trailing newline from the output.
432         set version [string trimright [lindex $version 1]]
433         set machine [remote_exec host ${cc} -dumpmachine]
434         set machine [string trimright [lindex $machine 1]]
435         set comp_base_dir [remote_exec host ${cc} --print-prog-name=cc1]
436         set comp_base_dir [lindex $comp_base_dir 1]
437         set comp_base_dir [file dirname [file dirname [file dirname [file dirname [file dirname $comp_base_dir]]]]]
438         # For a cross compiler, the header files will be located in a
439         # machine-specific subdirectory.
440         set crossbase "${comp_base_dir}/${machine}/include/c++/${version}"
441         set crosstarget "${crossbase}/${machine}"
442         set cc_final [concat $cc_final "-I$crossbase -I$crosstarget"]
443         # For a native compiler, the header files will be located at 
444         # the top level.
445         set includesbase "${comp_base_dir}/include/c++/${version}"
446         set includestarget "${includesbase}/${machine}"
447         set cc_final [concat $cc_final "-I$includesbase -I$includestarget"]
448
449         set libdir "-L${comp_base_dir}/lib"
450     } else {
451         set libdir "-L${blddir}/libsupc++/.libs"
452         set libdir [concat $libdir "-L${blddir}/src/.libs"]
453     }
454
455     set cc_final [concat $cc_final "$libdir"]
456
457     lappend options "compiler=$cc_final"
458     lappend options "timeout=600"
459
460     return [target_compile $source $dest $type $options]
461 }
462
463 # Build the support objects linked in with the libstdc++ tests.  In
464 # addition, set v3-wchar_t, v3-threads, and v3-symver appropriately.
465 proc v3-build_support { } {
466     global env
467     global srcdir
468     global v3-wchar_t
469     global v3-threads
470     global v3-symver
471     global v3-sharedlib
472
473     # Figure out whether or not the library supports certain features.
474     set v3-wchar_t 0
475     set v3-threads 0
476     set v3-symver 0
477     set libtest_objs ""
478
479     set config_src "config.cc"
480     set config_out "config.ii"
481     set f [open $config_src "w"]
482     puts $f "#include <bits/c++config.h>"
483     puts $f "#include <bits/gthr.h>"
484     close $f
485     v3_target_compile $config_src $config_out preprocess "additional_flags=-dN"
486     set file [open $config_out r]
487     set preprocessed [read $file]
488     close $file
489     if { [string first "_GLIBCXX_USE_WCHAR_T" $preprocessed] != -1 } {
490         verbose -log "wchar_t support detected"
491         set v3-wchar_t 1
492     }
493     if { [string first "_GLIBCXX_SYMVER" $preprocessed] != -1 } {
494         verbose -log "symbol versioning support detected"
495         set v3-symver 1
496     }
497     if { [string first "__GTHREADS" $preprocessed] != -1 } {
498         verbose -log "thread support detected"
499         set v3-threads 1
500     }
501
502     # Try to build the MO files that are used by some of the locale
503     # tests.  If we can't build them, that's OK; it just means that
504     # those tests will fail.
505     foreach lang [list "fr" "de"] {
506         catch {
507             file mkdir "$lang/LC_MESSAGES"
508             remote_exec "build" "msgfmt" "-o $lang/LC_MESSAGES/libstdc++.mo $srcdir/../po/$lang.po"
509             if [is_remote host] {
510                 remote_exec "host" "mkdir" "-p $lang/LC_MESSAGES"
511                 remote_download "host" "$lang/LC_MESSAGES/libstdc++.mo" "$lang/LC_MESSAGES/libstdc++.mo"
512             }
513         }
514     }
515
516     # Build the support objects.
517     set source_files [list testsuite_abi.cc testsuite_allocator.cc \
518                           testsuite_character.cc testsuite_hooks.cc \
519                           io/verified_cmd_line_input.cc \
520                           io/prog_bar.cc performance/time/elapsed_timer.cc ]
521     foreach f $source_files {
522         set obj [file rootname $f].o
523         set object_file [file tail $obj]
524         # Compile with "-w" so that warnings issued by the compiler
525         # do not prevent compilation.
526         if { [v3_target_compile $srcdir/util/$f $object_file "object" \
527                   [list "incdir=$srcdir" "additional_flags=-w"]]
528              != "" } {
529             error "could not compile $f"
530         }
531         append libtest_objs "$object_file "
532     }
533
534     # Collect into libtestc++.a
535     if  [info exists env(AR)] {
536         set ar $env(AR)
537     } else {
538         set ar [transform "ar"]
539     }
540     set arargs "-rc ./libtestc++.a ${libtest_objs}"
541     verbose -log "$ar $arargs"
542     set result [lindex [remote_exec host "$ar" "$arargs"] 0]
543     verbose "link result is $result"
544     if { $result == 0 } {
545         if  [info exists env(RANLIB)] {
546             set ranlib $env(RANLIB)
547         } else {
548             set ranlib [transform "ranlib"]
549         }
550         set ranlibargs "./libtestc++.a"
551         verbose -log "$ranlib $ranlibargs"
552         set result [lindex [remote_exec host "$ranlib" "$ranlibargs"] 0]
553         if { $result != 0 } {
554             error "could not link libtestc++.a"
555         }
556     }
557
558     # Build any shared objects needed for regression testing.
559     if { ${v3-sharedlib} == 1 } {
560         set source_files [list testsuite_shared.cc]
561         foreach f $source_files {
562             set object_file [file rootname $f].so
563             # Compile with "-w" so that warnings issued by the compiler
564             # do not prevent compilation.
565             if { [v3_target_compile $srcdir/util/$f $object_file "sharedlib" \
566              [list "incdir=$srcdir" "additional_flags=-w -shared -fPIC -DPIC"]]
567                  != "" } {
568                 error "could not compile $f"
569             }
570         }
571     }
572 }
573
574 proc check_v3_target_fileio { } {
575     global et_fileio_saved
576     global et_fileio_target_name
577     global tool 
578
579     if { ![info exists et_fileio_target_name] } {
580         set et_fileio_target_name ""
581     }
582
583     # If the target has changed since we set the cached value, clear it.
584     set current_target [current_target_name]
585     if { $current_target != $et_fileio_target_name } {
586         verbose "check_v3_target_fileio: `$et_fileio_target_name'" 2
587         set et_fileio_target_name $current_target
588         if [info exists et_fileio_saved] {
589             verbose "check_v3_target_fileio: removing cached result" 2
590             unset et_fileio_saved
591         }
592     }
593
594     if [info exists et_fileio_saved] {
595         verbose "check_v3_target_fileio: using cached result" 2
596     } else {
597         set et_fileio_saved 0
598
599         # Set up, compile, and execute a C++ test program that tries to use
600         # the file functions
601         set src fileio[pid].cc
602         set exe fileio[pid].x
603
604         set f [open $src "w"]
605         puts $f "#include <sys/types.h>"
606         puts $f "#include <sys/stat.h>"
607         puts $f "#include <fcntl.h>"
608         puts $f "#include <unistd.h>"
609         puts $f "#include <errno.h>"
610         puts $f "using namespace std;"  
611         puts $f "int main ()"
612         puts $f "{"
613         puts $f "  int fd  = open (\".\", O_RDONLY);"
614         puts $f "  int ret = 0;"
615         puts $f "  if (fd == -1)"
616         puts $f "  {"
617         puts $f "    int err = errno;"
618         puts $f "    if (err == EIO || err == ENOSYS)"
619         puts $f "      ret = 1;"
620         puts $f "  }"
621         puts $f "  else"
622         puts $f "  {"
623         puts $f "    if (lseek (fd, 0, SEEK_CUR) == -1)"
624         puts $f "      ret = 1;"
625         puts $f "    close (fd);"
626         puts $f "  }"
627         puts $f "  return ret;"
628         puts $f "}" 
629         close $f
630
631         set lines [v3_target_compile $src $exe executable ""]
632         file delete $src
633
634         if [string match "" $lines] {
635             # No error message, compilation succeeded.
636             set result [${tool}_load "./$exe" "" ""]
637             set status [lindex $result 0]
638             remote_file build delete $exe
639
640             verbose "check_v3_target_fileio: status is <$status>" 2
641
642             if { $status == "pass" } {
643                 set et_fileio_saved 1
644             }
645         } else {
646             verbose "check_v3_target_fileio: compilation failed" 2
647         }
648     }
649     return $et_fileio_saved
650 }
651
652 # Eventually we want C90/C99 determining and switching from this.
653 proc check_v3_target_c_std { } {
654     global et_c_std_saved
655     global et_c_std_target_name
656     global tool 
657
658     if { ![info exists et_c_std_target_name] } {
659         set et_c_std_target_name ""
660     }
661
662     # If the target has changed since we set the cached value, clear it.
663     set current_target [current_target_name]
664     if { $current_target != $et_c_std_target_name } {
665         verbose "check_v3_target_c_std: `$et_c_std_target_name'" 2
666         set et_c_std_target_name $current_target
667         if [info exists et_c_std_saved] {
668             verbose "check_v3_target_c_std: removing cached result" 2
669             unset et_c_std_saved
670         }
671     }
672
673     if [info exists et_c_std_saved] {
674         verbose "check_v3_target_c_std: using cached result" 2
675     } else {
676         set et_c_std_saved 0
677
678         # Set up, compile, and execute a C++ test program that tries to use
679         # C99 functionality.
680         # For math bits, could use check_effective_target_c99_math.
681         set src fileio[pid].cc
682         set exe fileio[pid].x
683
684         set f [open $src "w"]
685         puts $f "#include <tr1/cmath>"
686         puts $f "#include <cstdlib>"
687         puts $f "int main ()"
688         puts $f "{"
689         puts $f "  float f = 45.55;"
690         puts $f "  int i = std::tr1::isnan(f);"
691         puts $f "  "
692         puts $f "  using std::wctomb;"
693         puts $f "  return i;"
694         puts $f "}" 
695         close $f
696
697         set lines [v3_target_compile $src $exe executable ""]
698         file delete $src
699
700         if [string match "" $lines] {
701             # No error message, compilation succeeded.
702             set result [${tool}_load "./$exe" "" ""]
703             set status [lindex $result 0]
704             remote_file build delete $exe
705
706             verbose "check_v3_target_c_std: status is <$status>" 2
707
708             if { $status == "pass" } {
709                 set et_c_std_saved 1
710             }
711         } else {
712             verbose "check_v3_target_c_std: compilation failed" 2
713         }
714     }
715     return $et_c_std_saved
716 }
717
718 proc check_v3_target_sharedlib { } {
719     global v3-sharedlib
720     return ${v3-sharedlib}
721 }
722
723 proc check_v3_target_time { } {
724     global et_time_saved
725     global et_time_target_name
726     global tool 
727
728     if { ![info exists et_time_target_name] } {
729         set et_time_target_name ""
730     }
731
732     # If the target has changed since we set the cached value, clear it.
733     set current_target [current_target_name]
734     if { $current_target != $et_time_target_name } {
735         verbose "check_v3_target_time: `$et_time_target_name'" 2
736         set et_time_target_name $current_target
737         if [info exists et_time_saved] {
738             verbose "check_v3_target_time: removing cached result" 2
739             unset et_time_saved
740         }
741     }
742
743     if [info exists et_time_saved] {
744         verbose "check_v3_target_time: using cached result" 2
745     } else {
746         set et_time_saved 0
747
748         # Set up and compile a C++ test program that tries to use
749         # the time function
750         set src time[pid].cc
751         set exe time[pid].x
752
753         set f [open $src "w"]
754         puts $f "#include <time.h>"
755         puts $f "using namespace std;"  
756         puts $f "int main ()"
757         puts $f "{"
758         puts $f "  time (0);"   
759         puts $f "}" 
760         close $f
761
762         set lines [v3_target_compile $src $exe executable ""]
763         file delete $src
764
765         if [string match "" $lines] {
766             # No error message, compilation succeeded.
767             verbose "check_v3_target_time: compilation succeeded" 2
768             remote_file build delete $exe
769             set et_time_saved 1
770         } else {
771             verbose "check_v3_target_time: compilation failed" 2
772         }
773     }
774     return $et_time_saved
775 }
776
777 proc check_v3_target_rvalref { } {
778     global et_rvalref_saved
779     global et_rvalref_target_name
780     global tool 
781
782     if { ![info exists et_rvalref_target_name] } {
783         set et_rvalref_target_name ""
784     }
785
786     # If the target has changed since we set the cached value, clear it.
787     set current_target [current_target_name]
788     if { $current_target != $et_rvalref_target_name } {
789         verbose "check_v3_target_rvalref: `$et_rvalref_target_name'" 2
790         set et_rvalref_target_name $current_target
791         if [info exists et_rvalref_saved] {
792             verbose "check_v3_target_rvalref: removing cached result" 2
793             unset et_rvalref_saved
794         }
795     }
796
797     if [info exists et_rvalref_saved] {
798         verbose "check_v3_target_rvalref: using cached result" 2
799     } else {
800         set et_rvalref_saved 0
801
802         # Set up and compile a C++ test program that tries to use
803         # the library components of rval references
804         set src rvalref[pid].cc
805         set exe rvalref[pid].x
806
807         set f [open $src "w"]
808         puts $f "#include <iterator>"
809         puts $f "#include <utility>"
810         puts $f "using std::move;"
811         puts $f "using std::identity;"
812         puts $f "using std::forward;"
813         puts $f "using std::move_iterator;"
814         puts $f "using std::make_move_iterator;"
815         close $f
816
817         set lines [v3_target_compile $src $exe executable ""]
818         file delete $src
819
820         if [string match "" $lines] {
821             # No error message, compilation succeeded.
822             verbose "check_v3_target_rvalref: compilation succeeded" 2
823             remote_file build delete $exe
824             set et_rvalref_saved 1
825         } else {
826             verbose "check_v3_target_rvalref: compilation failed" 2
827         }
828     }
829     return $et_rvalref_saved
830 }
831
832 proc check_v3_target_namedlocale { } {
833     global et_namedlocale_saved
834     global et_namedlocale_target_name
835     global tool 
836
837     if { ![info exists et_namedlocale_target_name] } {
838         set et_namedlocale_target_name ""
839     }
840
841     # If the target has changed since we set the cached value, clear it.
842     set current_target [current_target_name]
843     if { $current_target != $et_namedlocale_target_name } {
844         verbose "check_v3_target_namedlocale: `$et_namedlocale_target_name'" 2
845         set et_namedlocale_target_name $current_target
846         if [info exists et_namedlocale_saved] {
847             verbose "check_v3_target_namedlocale: removing cached result" 2
848             unset et_namedlocale_saved
849         }
850     }
851
852     if [info exists et_namedlocale_saved] {
853         verbose "check_v3_target_namedlocale: using cached result" 2
854     } else {
855         set et_namedlocale_saved 0
856
857         # Set up, compile, and execute a C++ test program that tries to use
858         # all the required named locales.
859         set src nlocale[pid].cc
860         set exe nlocale[pid].x
861
862         set f [open $src "w"]
863         puts $f "#include <locale>"
864         puts $f "using namespace std;"  
865         puts $f "int main ()"
866         puts $f "{"
867         puts $f "  try" 
868         puts $f "  {" 
869         puts $f "     locale(\"\");"
870         puts $f "     locale(\"de_DE\");"
871         puts $f "     locale(\"de_DE.ISO-8859-15@euro\");"
872         puts $f "     locale(\"de_DE@euro\");"
873         puts $f "     locale(\"en_HK\");"
874         puts $f "     locale(\"en_PH\");"
875         puts $f "     locale(\"en_US\");"
876         puts $f "     locale(\"en_US.ISO-8859-1\");"
877         puts $f "     locale(\"en_US.ISO-8859-15\");"
878         puts $f "     locale(\"en_US.UTF-8\");"
879         puts $f "     locale(\"es_ES\");"
880         puts $f "     locale(\"es_MX\");"
881         puts $f "     locale(\"fr_FR\");"
882         puts $f "     locale(\"fr_FR@euro\");"
883         puts $f "     locale(\"is_IS\");"
884         puts $f "     locale(\"is_IS.UTF-8\");"
885         puts $f "     locale(\"it_IT\");"
886         puts $f "     locale(\"ja_JP.eucjp\");"
887         puts $f "     locale(\"se_NO.UTF-8\");"
888         puts $f "     locale(\"ta_IN\");"
889         puts $f "     locale(\"zh_TW\");"
890         puts $f "     return 0;"
891         puts $f "  }"
892         puts $f "  catch(...)"
893         puts $f "  {"
894         puts $f "     return 1;"
895         puts $f "  }"   
896         puts $f "}"
897         close $f
898
899         set lines [v3_target_compile $src $exe executable ""]
900         file delete $src
901
902         if [string match "" $lines] {
903             # No error message, compilation succeeded.
904             set result [${tool}_load "./$exe" "" ""]
905             set status [lindex $result 0]
906             remote_file build delete $exe
907
908             verbose "check_v3_target_namedlocale: status is <$status>" 2
909
910             if { $status == "pass" } {
911                 set et_namedlocale_saved 1
912             }
913         } else {
914             verbose "check_v3_target_namedlocale: compilation failed" 2
915         }
916     }
917     return $et_namedlocale_saved
918 }
919
920 proc check_v3_target_debug_mode { } {
921     global cxxflags
922     global et_debug_mode
923     global tool 
924
925     if { ![info exists et_debug_mode_target_name] } {
926         set et_debug_mode_target_name ""
927     }
928
929     # If the target has changed since we set the cached value, clear it.
930     set current_target [current_target_name]
931     if { $current_target != $et_debug_mode_target_name } {
932         verbose "check_v3_target_debug_mode: `$et_debug_mode_target_name'" 2
933         set et_debug_mode_target_name $current_target
934         if [info exists et_debug_mode] {
935             verbose "check_v3_target_debug_mode: removing cached result" 2
936             unset et_debug_mode
937         }
938     }
939
940     if [info exists et_debug_mode] {
941         verbose "check_v3_target_debug_mode: using cached result" 2
942     } else {
943         set et_debug_mode 0
944
945         # Set up and compile a C++ test program that depends
946         # on debug mode working.
947         set src debug_mode[pid].cc
948         set exe debug_mode[pid].exe
949
950         set f [open $src "w"]
951         puts $f "#include <string>"
952         puts $f "using namespace std;"  
953         puts $f "int main()"
954         puts $f "{ return 0; }"
955         close $f
956
957         set cxxflags_saved $cxxflags
958         set cxxflags "$cxxflags -Werror -O0 -D_GLIBCXX_DEBUG"
959         set lines [v3_target_compile $src $exe executable ""]
960         set cxxflags $cxxflags_saved
961         file delete $src
962
963         if [string match "" $lines] {
964             # No error message, compilation succeeded.
965             set et_debug_mode 1
966         }
967     }
968     verbose "check_v3_target_debug_mode: $et_debug_mode" 2
969     return $et_debug_mode
970 }
971
972 proc check_v3_target_parallel_mode { } {
973     global cxxflags
974     global v3-libgomp
975     global et_parallel_mode
976
977     global tool 
978
979     if { ![info exists et_parallel_mode_target_name] } {
980         set et_parallel_mode_target_name ""
981     }
982
983     # If the target has changed since we set the cached value, clear it.
984     set current_target [current_target_name]
985     if { $current_target != $et_parallel_mode_target_name } {
986         verbose "check_v3_target_parallel_mode: `$et_parallel_mode_target_name'" 2
987         set et_parallel_mode_target_name $current_target
988         if [info exists et_parallel_mode] {
989             verbose "check_v3_target_parallel_mode: removing cached result" 2
990             unset et_parallel_mode
991         }
992     }
993
994     if [info exists et_parallel_mode] {
995         verbose "check_v3_target_parallel_mode: using cached result" 2
996     } else {
997         set et_parallel_mode 0
998
999         # If 'make check-parallel' is running the test succeeds.
1000         if { ${v3-libgomp} == 1 && [regexp "libgomp" $cxxflags] } {
1001             set et_parallel_mode 1
1002         }
1003     }
1004     verbose "check_v3_target_parallel_mode: $et_parallel_mode" 2
1005     return $et_parallel_mode
1006 }
1007
1008 proc check_v3_target_cstdint { } {
1009     global cxxflags
1010     global DEFAULT_CXXFLAGS
1011     global et_cstdint
1012
1013     global tool 
1014
1015     if { ![info exists et_cstdint_target_name] } {
1016         set et_cstdint_target_name ""
1017     }
1018
1019     # If the target has changed since we set the cached value, clear it.
1020     set current_target [current_target_name]
1021     if { $current_target != $et_cstdint_target_name } {
1022         verbose "check_v3_target_cstdint: `$et_cstdint_target_name'" 2
1023         set et_cstdint_target_name $current_target
1024         if [info exists et_cstdint] {
1025             verbose "check_v3_target_cstdint: removing cached result" 2
1026             unset et_cstdint
1027         }
1028     }
1029
1030     if [info exists et_cstdint] {
1031         verbose "check_v3_target_cstdint: using cached result" 2
1032     } else {
1033         set et_cstdint 0
1034
1035         # Set up and compile a C++0x test program that depends
1036         # on the C99 stdint facilities to be available.
1037         set src cstdint[pid].cc
1038         set exe cstdint[pid].exe
1039
1040         set f [open $src "w"]
1041         puts $f "#include <tr1/cstdint>"
1042         puts $f "int main()"
1043         puts $f "#ifdef _GLIBCXX_USE_C99_STDINT_TR1"
1044         puts $f "{ return 0; }"
1045         puts $f "#endif"
1046         close $f
1047
1048         set cxxflags_saved $cxxflags
1049         set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror"
1050
1051         set lines [v3_target_compile $src $exe executable ""]
1052         set cxxflags $cxxflags_saved
1053         file delete $src
1054
1055         if [string match "" $lines] {
1056             # No error message, compilation succeeded.
1057             set et_cstdint 1
1058         } else {
1059             verbose "check_v3_target_cstdint: compilation failed" 2
1060         }
1061     }
1062     verbose "check_v3_target_cstdint: $et_cstdint" 2
1063     return $et_cstdint
1064 }