OSDN Git Service

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