libstdc++-v3-dg.exp (libstdc++-v3-list-sourcefiles): New function.
[official-gcc.git] / libstdc++-v3 / testsuite / lib / libstdc++-v3-dg.exp
blob8d1e71397d9f7625e9d998e22f2f08342dde0ba9
1 # Copyright (C) 2001, 2002 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 # Define libstdc++-v3 callbacks for dg.exp.
19 load_lib dg.exp
20 load_lib libgloss.exp
21 load_lib prune.exp
23 proc libstdc++-v3-copy-files {srcfiles dstdir} {
24 foreach f $srcfiles {
25 if { [catch { set symlink [file readlink $f] } x] } then {
26 file copy -force $f $dstdir
27 } else {
28 if { [regexp "^/" "$symlink"] } then {
29 file copy -force $symlink $dstdir
30 } else {
31 set dirname [file dirname $f]
32 file copy -force $dirname/$symlink $dstdir
38 proc libstdc++-v3-init { args } {
39 global srcdir
40 global outdir
41 global blddir
42 global cxx
43 global includes
44 global cxxflags
45 global objdir
46 global gluefile wrap_flags
47 global ld_library_path
48 global tool_root_dir
50 set blddir [lookfor_file [get_multilibs] libstdc++-v3]
52 # By default, we assume we want to run program images.
53 global dg-do-what-default
54 set dg-do-what-default run
56 # Copy any required data files.
57 libstdc++-v3-copy-files [glob -nocomplain "$srcdir/*/*.tst"] $outdir
58 libstdc++-v3-copy-files [glob -nocomplain "$srcdir/*/*.txt"] $outdir
60 # set LD_LIBRARY_PATH so that libgcc_s, libstdc++ binaries can be found.
61 # locate libgcc.a so we don't need to account for different values of
62 # SHLIB_EXT on different platforms
63 set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a]
64 if {$gccdir != ""} {
65 set gccdir [file dirname $gccdir]
68 set ld_library_path "."
69 append ld_library_path ":${gccdir}"
70 append ld_library_path ":${blddir}/src/.libs"
72 # Do a bunch of handstands and backflips for cross compiling and
73 # finding simulators...
74 if [is_remote host] {
75 set header [remote_download host ${blddir}/testsuite/testsuite_hooks.h]
76 if { $header == "" } {
77 verbose -log "Unable to download ${blddir}/testsuite/testsuite_hooks.h to host."
78 return "untested"
80 set cxx [transform "g++"]
81 set cxxflags "-ggdb3 -DDEBUG_ASSERT"
82 set includes "-I./"
83 } else {
84 # If we find a testsuite_flags file, we're testing in the build dir.
85 set flags_file "${blddir}/testsuite_flags"
86 if { [file exists $flags_file] } {
87 set cxx [exec sh $flags_file --build-cxx]
88 set cxxflags [exec sh $flags_file --cxxflags]
89 set includes [exec sh $flags_file --build-includes]
90 } else {
91 set cxx [transform "g++"]
92 set cxxflags "-ggdb3 -DDEBUG_ASSERT"
93 set includes "-I${srcdir}"
97 if { [target_info needs_status_wrapper]!="" && ![info exists gluefile] } {
98 set gluefile ${objdir}/testglue.o;
99 set result [build_wrapper $gluefile];
100 if { $result != "" } {
101 set gluefile [lindex $result 0];
102 set wrap_flags [lindex $result 1];
103 } else {
104 unset gluefile
109 proc libstdc++-v3-dg-test { prog do_what extra_tool_flags } {
110 # Set up the compiler flags, based on what we're going to do.
112 switch $do_what {
113 "preprocess" {
114 set compile_type "preprocess"
115 set output_file "[file rootname [file tail $prog]].i"
117 "compile" {
118 set compile_type "assembly"
119 set output_file "[file rootname [file tail $prog]].s"
121 "assemble" {
122 set compile_type "object"
123 set output_file "[file rootname [file tail $prog]].o"
125 "link" {
126 set compile_type "executable"
127 set output_file "./[file rootname [file tail $prog]].exe"
129 "run" {
130 set compile_type "executable"
131 # FIXME: "./" is to cope with "." not being in $PATH.
132 # Should this be handled elsewhere?
133 # YES.
134 set output_file "./[file rootname [file tail $prog]].exe"
135 # This is the only place where we care if an executable was
136 # created or not. If it was, dg.exp will try to run it.
137 remote_file build delete $output_file;
139 default {
140 perror "$do_what: not a valid dg-do keyword"
141 return ""
144 set options ""
145 if { $extra_tool_flags != "" } {
146 lappend options "additional_flags=$extra_tool_flags"
149 set comp_output [libstdc++-v3_target_compile "$prog" "$output_file" "$compile_type" $options];
150 set comp_output [ prune_g++_output $comp_output ];
152 return [list $comp_output $output_file]
156 proc libstdc++-v3_target_compile { source dest type options } {
157 global gluefile
158 global wrap_flags
159 global cxx
160 global cxxflags
161 global includes
163 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
164 lappend options "libs=${gluefile}"
165 lappend options "ldflags=${wrap_flags}"
168 set cxx_final $cxx
169 set cxxlibglossflags [libgloss_link_flags]
170 set cxx_final [concat $cxx_final $cxxlibglossflags]
171 set cxx_final [concat $cxx_final $cxxflags]
172 set cxx_final [concat $cxx_final $includes]
174 lappend options "compiler=$cxx_final";
176 return [target_compile $source $dest $type $options]
180 # A bit sloppy... Returns a list of source files (full pathnames) to
181 # compile. We mimic the mkcheck script in that the first time this is run,
182 # all existing files are listed in "testsuite_files" in the output
183 # directory. Subsequent runs pull the list from that file, allowing users
184 # to trim the list down to problematic tests.
185 ### This is supposed to be done via RUNTESTFLAGS, but that doesn't work.
186 proc libstdc++-v3-list-sourcefiles { } {
187 global srcdir
188 global outdir
190 set files_file "${outdir}/testsuite_files"
191 set sfiles ""
192 if { [file exists $files_file] } {
193 set f [open $files_file]
194 while { ! [eof $f] } {
195 set t [gets $f]
196 if { [string length "$t"] != 0 } {
197 lappend sfiles ${srcdir}/${t}
200 } else {
201 set f [open $files_file "w"]
202 set where_we_were [pwd]
203 cd $srcdir
204 foreach s [lsort [glob -nocomplain */*.cc]] {
205 lappend sfiles ${srcdir}/${s}
206 puts $f $s
208 cd $where_we_were
210 close $f
211 return $sfiles