1 # Copyright (C) 2001, 2002, 2003 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.
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 callbacks for dg.exp. This file is loaded early.
23 # Called by v3-init below. "Static" to this file.
24 proc v3-copy-files {srcfiles dstdir} {
26 if { [catch { set symlink [file readlink $f] } x] } then {
27 file copy -force $f $dstdir
29 if { [regexp "^/" "$symlink"] } then {
30 file copy -force $symlink $dstdir
32 set dirname [file dirname $f]
33 file copy -force $dirname/$symlink $dstdir
39 # Called once, from libstdc++/dg.exp.
40 proc v3-init { args } {
48 global gluefile wrap_flags
50 global ld_library_path
51 global original_ld_library_path
54 set blddir [lookfor_file [get_multilibs] libstdc++-v3]
56 # By default, we assume we want to run program images.
57 global dg-do-what-default
58 set dg-do-what-default run
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
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)
69 } elseif [info exists env(SHLIB_PATH)] {
70 set original_ld_library_path $env(SHLIB_PATH)
72 } elseif [info exists env(DYLD_LIBRARY_PATH)] {
73 set original_ld_library_path $env(DYLD_LIBRARY_PATH)
75 } elseif [info exists env(LD_LIBRARY_PATH_32)] {
76 set original_ld_library_path $env(LD_LIBRARY_PATH_32)
78 } elseif [info exists env(LD_LIBRARY_PATH_64)] {
79 set original_ld_library_path $env(LD_LIBRARY_PATH_64)
81 set original_ld_library_path ""
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]
88 set gccdir [file dirname $gccdir]
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]" {
98 regexp -- "\[a-z0-9=/\.-\]*;" $i mldir
99 set mldir [string trimright $mldir "\;@"]
100 if { "$mldir" == "." } {
103 if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] == 1 } {
104 append ld_library_path ":${gccdir}/${mldir}"
108 append ld_library_path ":${blddir}/src/.libs"
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
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)"
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."
136 set cxx [transform "g++"]
137 set cxxflags "-ggdb3 -D_GLIBCXX_ASSERT"
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]
147 set cxx [transform "g++"]
148 set cxxflags "-ggdb3 -D_GLIBCXX_ASSERT"
149 set includes "-I${srcdir}"
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];
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.
172 set compile_type "preprocess"
173 set output_file "[file rootname [file tail $prog]].i"
176 set compile_type "assembly"
177 set output_file "[file rootname [file tail $prog]].s"
180 set compile_type "object"
181 set output_file "[file rootname [file tail $prog]].o"
184 set compile_type "executable"
185 set output_file "./[file rootname [file tail $prog]].exe"
188 set compile_type "executable"
189 # FIXME: "./" is to cope with "." not being in $PATH.
190 # Should this be handled elsewhere?
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;
198 perror "$do_what: not a valid dg-do keyword"
203 if { $extra_tool_flags != "" } {
204 lappend options "additional_flags=$extra_tool_flags"
207 set comp_output [v3_target_compile "$prog" "$output_file" "$compile_type" $options];
208 set comp_output [ prune_g++_output $comp_output ];
210 return [list $comp_output $output_file]
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 } {
223 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
224 lappend options "libs=${gluefile}"
225 lappend options "ldflags=${wrap_flags}"
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]
234 lappend options "compiler=$cxx_final"
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"
241 return [target_compile $source $dest $type $options]
245 # Called once, from libstdc++*/dg.exp.
246 proc v3-list-tests { filename } {
250 set tests_file "${outdir}/${filename}"
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] } {
258 if { [string length "$t"] != 0 } {
259 lappend sfiles ${srcdir}/${t}
264 verbose "cannot open $tests_file"