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 libmudflap callbacks for dg.exp.
18 # This file is a copy of libstdc++-v3's dejagnu driver, with minor changes.
24 proc libmudflap-init { compiler } {
33 global gluefile wrap_flags
34 global ld_library_path
37 verbose "libmudflap-init $compiler"
39 set blddir [lookfor_file [get_multilibs] libmudflap]
41 # By default, we assume we want to run program images.
42 global dg-do-what-default
43 set dg-do-what-default run
45 # set LD_LIBRARY_PATH so that libgcc_s, libstdc++ binaries can be found.
46 # locate libgcc.a so we don't need to account for different values of
47 # SHLIB_EXT on different platforms
48 set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a]
50 set gccdir [file dirname $gccdir]
53 set ld_library_path "."
54 append ld_library_path ":${gccdir}"
55 append ld_library_path ":../../libstdc++-v3/src/.libs"
56 if {[is_remote host] == 0} {
57 foreach i "[exec ${gccdir}/xgcc --print-multi-lib]" {
59 regexp -- "\[a-z0-9=/\.-\]*;" $i mldir
60 set mldir [string trimright $mldir "\;@"]
61 if { "$mldir" == "." } {
64 if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] == 1 } {
65 append ld_library_path ":${gccdir}/${mldir}"
66 append ld_library_path ":../../libstdc++-v3/${mldir}/src/.libs"
70 append ld_library_path ":${blddir}/.libs"
72 set libs "-L../.libs -L../../libstdc++-v3/src/.libs -L../../../gcc"
73 set cxxflags "-ggdb3 -DDEBUG_ASSERT"
74 set includes "-I${srcdir} -I.."
76 verbose "ld_library_path=$ld_library_path"
77 setenv LD_LIBRARY_PATH $ld_library_path
78 setenv SHLIB_PATH $ld_library_path
79 setenv LD_LIBRARYN32_PATH $ld_library_path
80 setenv LD_LIBRARY64_PATH $ld_library_path
82 if { [target_info needs_status_wrapper]!=""} {
83 file delete ${objdir}/testglue.o;
84 set gluefile ${objdir}/testglue.o;
85 set result [build_wrapper $gluefile];
86 if { $result != "" } {
87 set gluefile [lindex $result 0];
88 set wrap_flags [lindex $result 1];
95 proc libmudflap-dg-test { prog do_what extra_tool_flags } {
96 # Set up the compiler flags, based on what we're going to do.
100 set compile_type "preprocess"
101 set output_file "[file rootname [file tail $prog]].i"
104 set compile_type "assembly"
105 set output_file "[file rootname [file tail $prog]].s"
108 set compile_type "object"
109 set output_file "[file rootname [file tail $prog]].o"
112 set compile_type "executable"
113 set output_file "./[file rootname [file tail $prog]].exe"
116 set compile_type "executable"
117 # FIXME: "./" is to cope with "." not being in $PATH.
118 # Should this be handled elsewhere?
120 set output_file "./[file rootname [file tail $prog]].exe"
121 # This is the only place where we care if an executable was
122 # created or not. If it was, dg.exp will try to run it.
123 remote_file build delete $output_file;
126 perror "$do_what: not a valid dg-do keyword"
131 if { $extra_tool_flags != "" } {
132 lappend options "additional_flags=$extra_tool_flags"
135 set comp_output [libmudflap_target_compile "$prog" "$output_file" "$compile_type" $options];
136 set comp_output [prune_gcc_output $comp_output ];
138 return [list $comp_output $output_file]
142 proc libmudflap_target_compile { source dest type options } {
151 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
152 lappend options "libs=${gluefile}"
153 lappend options "ldflags=${wrap_flags}"
157 set cxxlibglossflags [libgloss_link_flags]
158 set cxx_final [concat $cxx_final $cxxlibglossflags]
159 set cxx_final [concat $cxx_final $cxxflags]
160 set cxx_final [concat $cxx_final $includes]
161 set cxx_final [concat $cxx_final $libs]
163 lappend options "compiler=$cxx_final"
165 # Picks up the freshly-built testsuite library corresponding to the
166 # multilib under test.
167 lappend options "ldflags=-L${blddir}/testsuite"
169 return [target_compile $source $dest $type $options]
173 # A bit sloppy... Returns a list of source files (full pathnames) to
174 # compile. We mimic the mkcheck script in that the first time this is run,
175 # all existing files are listed in "testsuite_files" in the output
176 # directory. Subsequent runs pull the list from that file, allowing users
177 # to trim the list down to problematic tests.
178 ### This is supposed to be done via RUNTESTFLAGS, but that doesn't work.
179 proc libmudflap-list-sourcefiles { } {
183 set files_file "${outdir}/testsuite_files"
185 if { [file exists $files_file] } {
186 set f [open $files_file]
187 while { ! [eof $f] } {
189 if { [string length "$t"] != 0 } {
190 lappend sfiles ${srcdir}/${t}
194 set f [open $files_file "w"]
195 set where_we_were [pwd]
197 foreach s [lsort [glob -nocomplain "*/*.cc" "*/*/*.cc" "{,*/}*/*/*/*.cc" ]] {
198 lappend sfiles ${srcdir}/${s}
205 # Disable wchar_t tests if library not configured to support
207 set wchar_file "${outdir}/testsuite_wchar_t"
208 if { [file exists $wchar_file] } {
211 # Remove wchar_t tests files from list.
214 if [regexp "wchar_t" $w] {
215 verbose "element out list is $w"
217 verbose "element in list is $w"
226 proc prune_gcc_output { text } {
228 regsub -all {(^|\n)[^\n]*ld: warning: libgcc_s[^\n]*not found[^\n]*try using[^\n]*} $text "" text
230 regsub -all {(^|\n)[^\n]*In function.*pthread_create[^\n]*} $text "" text
232 regsub -all {(^|\n)[^\n]*the use of .pthread.*is deprecated[^\n]*} $text "" text
234 regsub -all {(^|\n)[^\n]*Dwarf Error:.*FORM value: 14[^\n]*} $text "" text