OSDN Git Service

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