OSDN Git Service

2004-01-10 Andreas Tobler <a.tobler@schweiz.ch>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / testsuite / lib / libstdc++.exp
1 # Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
2
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.
12
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.  
16
17 # Define callbacks for dg.exp.  This file is loaded early.
18
19 load_lib dg.exp
20 load_lib libgloss.exp
21 load_lib prune.exp
22
23 # Called by v3-init below.  "Static" to this file.
24 proc v3-copy-files {srcfiles dstdir} {
25     foreach f $srcfiles {
26         if { [catch { set symlink [file readlink $f] } x] } then {
27             file copy -force $f $dstdir
28         } else {
29             if { [regexp "^/" "$symlink"] } then {
30                 file copy -force $symlink $dstdir
31             } else {
32                 set dirname [file dirname $f]
33                 file copy -force $dirname/$symlink $dstdir
34             }
35         }
36     }
37 }
38
39 # Called once, from libstdc++/dg.exp.
40 proc v3-init { args } {
41     global srcdir
42     global outdir
43     global blddir
44     global cxx
45     global includes
46     global cxxflags
47     global objdir
48     global gluefile wrap_flags
49     global env
50     global ld_library_path
51     global original_ld_library_path
52     global tool_root_dir
53
54     set blddir [lookfor_file [get_multilibs] libstdc++-v3]
55
56     # By default, we assume we want to run program images.
57     global dg-do-what-default
58     set dg-do-what-default run
59
60     # Copy any required data files.
61     v3-copy-files [glob -nocomplain "$srcdir/data/*.tst"] $outdir
62     v3-copy-files [glob -nocomplain "$srcdir/data/*.txt"] $outdir
63
64     # Setup LD_LIBRARY_PATH so that libgcc_s, libstdc++ binaries can be found.
65     # Find the existing LD_LIBRARY_PATH.
66     if [info exists env(LD_LIBRARY_PATH)] {
67         set original_ld_library_path $env(LD_LIBRARY_PATH)
68         # For HP-UX
69     } elseif [info exists env(SHLIB_PATH)] {
70         set original_ld_library_path $env(SHLIB_PATH)
71         # For Darwin:
72     } elseif [info exists env(DYLD_LIBRARY_PATH)] {
73         set original_ld_library_path $env(DYLD_LIBRARY_PATH)
74         # For Solaris 32 bit:
75     } elseif [info exists env(LD_LIBRARY_PATH_32)] {
76         set original_ld_library_path $env(LD_LIBRARY_PATH_32)
77         # For Solaris 64 bit:
78     } elseif [info exists env(LD_LIBRARY_PATH_64)] {
79         set original_ld_library_path $env(LD_LIBRARY_PATH_64)
80     } else {
81         set original_ld_library_path ""
82     }
83
84     # Locate libgcc.a so we don't need to account for different values of
85     # SHLIB_EXT on different platforms
86     set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a]
87     if {$gccdir != ""} {
88         set gccdir [file dirname $gccdir]
89     }
90
91     # Compute what needs to be added to the existing LD_LIBRARY_PATH.
92     set ld_library_path ""
93     append ld_library_path ":${gccdir}"
94     set compiler ${gccdir}/g++
95     if { [is_remote host] == 0 && [which $compiler] != 0 } {
96       foreach i "[exec $compiler --print-multi-lib]" {
97         set mldir ""
98         regexp -- "\[a-z0-9=/\.-\]*;" $i mldir
99         set mldir [string trimright $mldir "\;@"]
100         if { "$mldir" == "." } {
101           continue
102         }
103         if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] == 1 } {
104           append ld_library_path ":${gccdir}/${mldir}"
105         }
106       }
107     }
108     append ld_library_path ":${blddir}/src/.libs"
109
110     # On IRIX 6, we have to set variables akin to LD_LIBRARY_PATH, but
111     # called LD_LIBRARYN32_PATH (for the N32 ABI) and LD_LIBRARY64_PATH
112     # (for the 64-bit ABI).  The right way to do this would be to modify
113     # unix.exp -- but that's not an option since it's part of DejaGNU
114     # proper, so we do it here.
115     # The same applies to darwin (DYLD_LIBRARY_PATH), solaris 32 bit
116     # (LD_LIBRARY_PATH_32), solaris 64 bit (LD_LIBRARY_PATH_64), and HP-UX
117     # (SHLIB_PATH).
118     setenv  LD_LIBRARY_PATH     "$ld_library_path:$original_ld_library_path"
119     setenv  SHLIB_PATH          "$ld_library_path:$original_ld_library_path"
120     setenv  LD_LIBRARYN32_PATH  "$ld_library_path:$original_ld_library_path"
121     setenv  LD_LIBRARY64_PATH   "$ld_library_path:$original_ld_library_path"
122     setenv  LD_RUN_PATH         "$ld_library_path:$original_ld_library_path"
123     setenv  LD_LIBRARY_PATH_32  "$ld_library_path:$original_ld_library_path"
124     setenv  LD_LIBRARY_PATH_64  "$ld_library_path:$original_ld_library_path"
125     setenv  DYLD_LIBRARY_PATH   "$ld_library_path:$original_ld_library_path"
126     verbose -log "LD_LIBRARY_PATH = $env(LD_LIBRARY_PATH)"
127
128     # Do a bunch of handstands and backflips for cross compiling and
129     # finding simulators...
130     if [is_remote host] {
131         set header [remote_download host ${blddir}/testsuite/testsuite_hooks.h]
132         if { $header == "" } {
133             verbose -log "Unable to download ${blddir}/testsuite/testsuite_hooks.h to host."
134             return "untested"
135         }
136       set cxx [transform "g++"]
137       set cxxflags "-ggdb3 -D_GLIBCXX_ASSERT"
138       set includes "-I./"
139     } else {
140         # If we find a testsuite_flags file, we're testing in the build dir.
141         set flags_file "${blddir}/scripts/testsuite_flags"
142         if { [file exists $flags_file] } {
143             set cxx [exec sh $flags_file --build-cxx]
144             set cxxflags [exec sh $flags_file --cxxflags]
145             set includes [exec sh $flags_file --build-includes]
146         } else {
147             set cxx [transform "g++"]
148             set cxxflags "-ggdb3 -D_GLIBCXX_ASSERT"
149             set includes "-I${srcdir}"
150         }
151     }
152
153     if { [target_info needs_status_wrapper]!=""} {
154       file delete ${objdir}/testglue.o;
155       set gluefile ${objdir}/testglue.o;
156       set result [build_wrapper $gluefile];
157       if { $result != "" } {
158           set gluefile [lindex $result 0];
159           set wrap_flags [lindex $result 1];
160       } else {
161           unset gluefile
162       }
163     }
164 }
165
166 # Callback from system dg-test.
167 proc libstdc++-dg-test { prog do_what extra_tool_flags } {
168     # Set up the compiler flags, based on what we're going to do.
169
170     switch $do_what {
171         "preprocess" {
172             set compile_type "preprocess"
173             set output_file "[file rootname [file tail $prog]].i"
174         }
175         "compile" {
176             set compile_type "assembly"
177             set output_file "[file rootname [file tail $prog]].s"
178         }
179         "assemble" {
180             set compile_type "object"
181             set output_file "[file rootname [file tail $prog]].o"
182         }
183         "link" {
184             set compile_type "executable"
185             set output_file "./[file rootname [file tail $prog]].exe"
186         }
187         "run" {
188             set compile_type "executable"
189             # FIXME: "./" is to cope with "." not being in $PATH.
190             # Should this be handled elsewhere?
191             # YES.
192             set output_file "./[file rootname [file tail $prog]].exe"
193             # This is the only place where we care if an executable was
194             # created or not.  If it was, dg.exp will try to run it.
195             remote_file build delete $output_file;
196         }
197         default {
198             perror "$do_what: not a valid dg-do keyword"
199             return ""
200         }
201     }
202     set options ""
203     if { $extra_tool_flags != "" } {
204         lappend options "additional_flags=$extra_tool_flags"
205     }
206
207     set comp_output [v3_target_compile "$prog" "$output_file" "$compile_type" $options];
208     set comp_output [ prune_g++_output $comp_output ];
209
210     return [list $comp_output $output_file]
211 }
212
213 # Called from libstdc++-dg-test above.  Calls back into system's
214 # target_compile to actually do the work.
215 proc v3_target_compile { source dest type options } {
216     global gluefile 
217     global wrap_flags
218     global cxx
219     global cxxflags
220     global includes
221     global blddir
222
223     if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
224         lappend options "libs=${gluefile}"
225         lappend options "ldflags=${wrap_flags}"
226     }
227
228     set cxx_final $cxx
229     set cxxlibglossflags  [libgloss_link_flags]
230     set cxx_final [concat $cxx_final $cxxlibglossflags]
231     set cxx_final [concat $cxx_final $cxxflags]
232     set cxx_final [concat $cxx_final $includes]
233
234     lappend options "compiler=$cxx_final"
235
236     # Picks up the freshly-built testsuite library corresponding to the
237     # multilib under test.
238     lappend options "ldflags=-L${blddir}/testsuite"
239     lappend options "libs=-lv3test"
240
241     return [target_compile $source $dest $type $options]
242 }
243
244
245 # Called once, from libstdc++*/dg.exp.
246 proc v3-list-tests { filename } {
247     global srcdir
248     global outdir
249     
250     set tests_file "${outdir}/${filename}"
251     set sfiles ""
252
253     # If there is a testsuite_file, use it. 
254     if { [file exists $tests_file] } {
255         set f [open $tests_file]
256         while { ! [eof $f] } {
257             set t [gets $f]
258             if { [string length "$t"] != 0 } {
259                 lappend sfiles  ${srcdir}/${t}
260             }
261         } 
262         close $f
263     } else {
264         verbose "cannot open $tests_file"
265     }
266     return $sfiles
267 }