1 # Copyright (C) 2001, 2002, 2003, 2004 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 { language } {
33 global gluefile wrap_flags
34 global ld_library_path
38 "c" { set cxx [find_gcc] }
39 "c++" { set cxx [find_g++] }
40 default { error "bad language code $language"; return }
43 verbose -log "libmudflap-init $cxx"
45 set blddir [lookfor_file [get_multilibs] libmudflap]
46 set cxxblddir [lookfor_file [get_multilibs] libstdc++-v3]
47 set cxxflags_file "${cxxblddir}/scripts/testsuite_flags"
49 # By default, we assume we want to run program images.
50 global dg-do-what-default
51 set dg-do-what-default run
53 # set LD_LIBRARY_PATH so that libgcc_s, libstdc++ binaries can be found.
54 # locate libgcc.a so we don't need to account for different values of
55 # SHLIB_EXT on different platforms
56 set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a]
58 set gccdir [file dirname $gccdir]
61 set ld_library_path "."
62 append ld_library_path ":${gccdir}"
63 append ld_library_path ":${cxxblddir}/src/.libs"
64 if {[is_remote host] == 0} {
65 foreach i "[exec ${gccdir}/xgcc --print-multi-lib]" {
67 regexp -- "\[a-z0-9=/\.-\]*;" $i mldir
68 set mldir [string trimright $mldir "\;@"]
69 if { "$mldir" == "." } {
72 if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] >= 1 } {
73 append ld_library_path ":${gccdir}/${mldir}"
77 append ld_library_path ":${blddir}/.libs"
79 set libs "-L${blddir}/.libs"
80 set cxxflags "-ggdb3 -DDEBUG_ASSERT"
81 set includes "-I${srcdir} -I.."
83 if {$language == "c++"} {
84 if {[file exists $cxxflags_file]} then {
85 set includes "${includes} [exec sh $cxxflags_file --build-includes]"
86 set cxxflags "${cxxflags} [exec sh $cxxflags_file --cxxflags]"
87 # c++ libs are included by --build-cxx below
88 set cxx "[exec sh $cxxflags_file --build-cxx]"
90 lappend libs "-L${cxxblddir}src/.libs"
91 lappend includes "-I../../libstdc++-v3/include"
97 append add_flags " $mfconfig_libs"
99 verbose -log "ld_library_path=$ld_library_path"
100 setenv LD_LIBRARY_PATH $ld_library_path
101 setenv SHLIB_PATH $ld_library_path
102 setenv LD_RUN_PATH $ld_library_path
103 setenv LD_LIBRARYN32_PATH $ld_library_path
104 setenv LD_LIBRARY64_PATH $ld_library_path
106 if { [target_info needs_status_wrapper]!=""} {
107 file delete ${objdir}/testglue.o;
108 set gluefile ${objdir}/testglue.o;
109 set result [build_wrapper $gluefile];
110 if { $result != "" } {
111 set gluefile [lindex $result 0];
112 set wrap_flags [lindex $result 1];
119 proc libmudflap-dg-test { prog do_what extra_tool_flags } {
120 # Set up the compiler flags, based on what we're going to do.
124 set compile_type "preprocess"
125 set output_file "[file rootname [file tail $prog]].i"
128 set compile_type "assembly"
129 set output_file "[file rootname [file tail $prog]].s"
132 set compile_type "object"
133 set output_file "[file rootname [file tail $prog]].o"
136 set compile_type "executable"
137 set output_file "./[file rootname [file tail $prog]].exe"
140 set compile_type "executable"
141 # FIXME: "./" is to cope with "." not being in $PATH.
142 # Should this be handled elsewhere?
144 set output_file "./[file rootname [file tail $prog]].exe"
145 # This is the only place where we care if an executable was
146 # created or not. If it was, dg.exp will try to run it.
147 remote_file build delete $output_file;
150 perror "$do_what: not a valid dg-do keyword"
155 if { $extra_tool_flags != "" } {
156 lappend options "additional_flags=$extra_tool_flags"
160 lappend options "libs=$mfconfig_libs"
162 set comp_output [libmudflap_target_compile "$prog" "$output_file" "$compile_type" $options];
163 set comp_output [prune_gcc_output $comp_output ];
165 return [list $comp_output $output_file]
169 proc libmudflap_target_compile { source dest type options } {
178 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
179 lappend options "libs=${gluefile}"
180 lappend options "ldflags=${wrap_flags}"
184 set cxxlibglossflags [libgloss_link_flags]
185 set cxx_final [concat $cxx_final $cxxlibglossflags]
186 set cxx_final [concat $cxx_final $cxxflags]
187 set cxx_final [concat $cxx_final $includes]
188 set cxx_final [concat $cxx_final $libs]
190 lappend options "compiler=$cxx_final"
192 # Picks up the freshly-built testsuite library corresponding to the
193 # multilib under test.
194 lappend options "ldflags=-L${blddir}/testsuite"
196 return [target_compile $source $dest $type $options]
200 # A bit sloppy... Returns a list of source files (full pathnames) to
201 # compile. We mimic the mkcheck script in that the first time this is run,
202 # all existing files are listed in "testsuite_files" in the output
203 # directory. Subsequent runs pull the list from that file, allowing users
204 # to trim the list down to problematic tests.
205 ### This is supposed to be done via RUNTESTFLAGS, but that doesn't work.
206 proc libmudflap-list-sourcefiles { } {
210 set files_file "${outdir}/testsuite_files"
212 if { [file exists $files_file] } {
213 set f [open $files_file]
214 while { ! [eof $f] } {
216 if { [string length "$t"] != 0 } {
217 lappend sfiles ${srcdir}/${t}
221 set f [open $files_file "w"]
222 set where_we_were [pwd]
224 foreach s [lsort [glob -nocomplain "*/*.cc" "*/*/*.cc" "{,*/}*/*/*/*.cc" ]] {
225 lappend sfiles ${srcdir}/${s}
232 # Disable wchar_t tests if library not configured to support
234 set wchar_file "${outdir}/testsuite_wchar_t"
235 if { [file exists $wchar_file] } {
238 # Remove wchar_t tests files from list.
241 if [regexp "wchar_t" $w] {
242 verbose -log "element out list is $w"
244 verbose -log "element in list is $w"
253 proc prune_gcc_output { text } {
254 regsub -all {(^|\n)[^\n]*ld: warning: libgcc_s[^\n]*not found[^\n]*try using[^\n]*} $text "" text
255 regsub -all {(^|\n)[^\n]*In function.*pthread_create[^\n]*} $text "" text
256 regsub -all {(^|\n)[^\n]*the use of .pthread.*is deprecated[^\n]*} $text "" text
257 regsub -all {(^|\n)[^\n]*Dwarf Error:.*FORM value: 14[^\n]*} $text "" text
258 regsub -all {(^|\n)[^\n]*In function[^\n]*} $text "" text
259 regsub -all {(^|\n)[^\n]*Using.*in statically linked applications requires[^\n]*} $text "" text