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.
, 51 Franklin Street
, Fifth Floor
, Boston
, MA
02110-1301, USA.
17 #
Define libmudflap callbacks
for dg.exp.
18 # This file is a copy of libstdc
++-v3
's dejagnu driver, with minor changes.
20 # Useful hook: if ${hostname}_init exists, it will be called, almost
21 # the last thing before testing begins. This can be defined in, e.g.,
22 # ~/.dejagnurc or $DEJAGNU.
24 proc load_gcc_lib { filename } {
26 load_file $srcdir/../../gcc/testsuite/lib/$filename
31 load_gcc_lib target-libpath.exp
33 proc libmudflap-init { language } {
35 global srcdir outdir blddir objdir tool_root_dir
39 global gluefile wrap_flags
40 global ld_library_path
43 "c" { set cxx [find_gcc] }
44 "c++" { set cxx [find_g++] }
45 default { error "bad language code $language"; return }
48 verbose -log "libmudflap-init $cxx"
50 set blddir [lookfor_file [get_multilibs] libmudflap]
51 set cxxblddir [lookfor_file [get_multilibs] libstdc++-v3]
52 set cxxflags_file "${cxxblddir}/scripts/testsuite_flags"
54 # By default, we assume we want to run program images.
55 global dg-do-what-default
56 set dg-do-what-default run
58 # set LD_LIBRARY_PATH so that libgcc_s, libstdc++ binaries can be found.
59 # locate libgcc.a so we don't need to account
for different
values of
60 # SHLIB_EXT
on different platforms
61 set gccdir
[lookfor_file $tool_root_dir gcc
/libgcc.a
]
63 set gccdir
[file dirname $gccdir
]
66 set ld_library_path
"."
67 append ld_library_path
":${gccdir}"
68 append ld_library_path
":${cxxblddir}/src/.libs"
69 if {[is_remote host
] == 0} {
70 foreach i
"[exec ${gccdir}/xgcc --print-multi-lib]" {
72 regexp
-- "\[a-z0-9=/\.-\]*;" $i mldir
73 set mldir
[string trimright $mldir
"\;@"]
74 if { "$mldir" == "." } {
77 if { [llength
[glob
-nocomplain $
{gccdir
}/$
{mldir
}/libgcc_s
*.so.
*]] >= 1 } {
78 append ld_library_path
":${gccdir}/${mldir}"
82 append ld_library_path
":${blddir}/.libs"
84 set libs
"-L${blddir}/.libs"
85 set cxxflags
"-ggdb3 -DDEBUG_ASSERT"
86 set includes
"-I${srcdir} -I${srcdir}/.. -I.."
88 if {$language
== "c++"} {
89 if {[file
exists $cxxflags_file
]} then {
90 set includes
"${includes} [exec sh $cxxflags_file --build-includes]"
91 set cxxflags
"${cxxflags} [exec sh $cxxflags_file --cxxflags]"
92 # c
++ libs are included by
--build
-cxx below
93 set cxx
"[exec sh $cxxflags_file --build-cxx]"
95 lappend libs
"-L${cxxblddir}src/.libs"
96 lappend includes
"-I../../libstdc++-v3/include"
102 append add_flags
" $mfconfig_libs"
104 set_ld_library_path_env_vars
105 if [info exists env
(LD_LIBRARY_PATH
)] {
106 verbose
-log "LD_LIBRARY_PATH = $env(LD_LIBRARY_PATH)"
109 if { [target_info needs_status_wrapper
]!=""} {
110 file
delete $
{objdir
}/testglue.o
;
111 set gluefile $
{objdir
}/testglue.o
;
112 set result
[build_wrapper $gluefile
];
113 if { $result
!= "" } {
114 set gluefile
[lindex $result
0];
115 set wrap_flags
[lindex $result
1];
121 #
If there is no static library
then don
't run tests with -static.
123 set opts "additional_flags=-static"
124 lappend opts "additional_flags=-fmudflap"
125 lappend opts "additional_flags=-lmudflap"
129 set f [open $src "w"]
130 puts $f "int main () { }"
132 set lines [${tool}_target_compile $src $exe executable "$opts"]
134 remote_file build delete $exe
136 if { ![string match "" $lines] } {
137 # Compilation failed; assume static library is not available.
139 set i [lsearch $MUDFLAP_FLAGS "*static*"]
140 set MUDFLAP_FLAGS [lreplace $MUDFLAP_FLAGS $i $i]
144 proc libmudflap-dg-test { prog do_what extra_tool_flags } {
145 # Set up the compiler flags, based on what we're going to
do.
149 set compile_type
"preprocess"
150 set output_file
"[file rootname [file tail $prog]].i"
153 set compile_type
"assembly"
154 set output_file
"[file rootname [file tail $prog]].s"
157 set compile_type
"object"
158 set output_file
"[file rootname [file tail $prog]].o"
161 set compile_type
"executable"
162 set output_file
"./[file rootname [file tail $prog]].exe"
165 set compile_type
"executable"
166 # FIXME
: "./" is to cope with "." not being in $PATH.
167 # Should this be handled elsewhere?
169 set output_file
"./[file rootname [file tail $prog]].exe"
170 # This is the only place where we care
if an executable was
171 # created or not.
If it was
, dg.exp will try to run it.
172 remote_file build
delete $output_file
;
175 perror
"$do_what: not a valid dg-do keyword"
180 if { $extra_tool_flags
!= "" } {
181 lappend options
"additional_flags=$extra_tool_flags"
185 lappend options
"libs=$mfconfig_libs"
187 set comp_output
[libmudflap_target_compile
"$prog" "$output_file" "$compile_type" $options];
188 set comp_output
[prune_gcc_output $comp_output
];
190 return [list $comp_output $output_file
]
194 proc libmudflap_target_compile
{ source dest type options
} {
203 if { [target_info needs_status_wrapper
] != "" && [info exists gluefile] } {
204 lappend options
"libs=${gluefile}"
205 lappend options
"ldflags=${wrap_flags}"
209 set cxxlibglossflags
[libgloss_link_flags
]
210 set cxx_final
[concat $cxx_final $cxxlibglossflags
]
211 set cxx_final
[concat $cxx_final $cxxflags
]
212 set cxx_final
[concat $cxx_final $includes
]
213 set cxx_final
[concat $cxx_final $libs
]
215 lappend options
"compiler=$cxx_final"
217 # Picks up the freshly
-built testsuite library corresponding to the
218 # multilib under test.
219 lappend options
"ldflags=-L${blddir}/testsuite"
221 return [target_compile $source $dest $type $options
]
225 # A bit sloppy... Returns a list of source files
(full pathnames
) to
226 #
compile. We mimic the mkcheck script in that the first time this is run
,
227 # all existing files are listed in
"testsuite_files" in the output
228 # directory. Subsequent runs pull the list from that file
, allowing users
229 # to trim the list down to problematic tests.
230 ### This is supposed to be done via RUNTESTFLAGS
, but that doesn
't work.
231 proc libmudflap-list-sourcefiles { } {
235 set files_file "${outdir}/testsuite_files"
237 if { [file exists $files_file] } {
238 set f [open $files_file]
239 while { ! [eof $f] } {
241 if { [string length "$t"] != 0 } {
242 lappend sfiles ${srcdir}/${t}
246 set f [open $files_file "w"]
247 set where_we_were [pwd]
249 foreach s [lsort [glob -nocomplain "*/*.cc" "*/*/*.cc" "{,*/}*/*/*/*.cc" ]] {
250 lappend sfiles ${srcdir}/${s}
257 # Disable wchar_t tests if library not configured to support
259 set wchar_file "${outdir}/testsuite_wchar_t"
260 if { [file exists $wchar_file] } {
263 # Remove wchar_t tests files from list.
266 if [regexp "wchar_t" $w] {
267 verbose -log "element out list is $w"
269 verbose -log "element in list is $w"
278 proc prune_gcc_output { text } {
279 regsub -all {(^|\n)[^\n]*ld: warning: libgcc_s[^\n]*not found[^\n]*try using[^\n]*} $text "" text
280 regsub -all {(^|\n)[^\n]*In function.*pthread_create[^\n]*} $text "" text
281 regsub -all {(^|\n)[^\n]*the use of .pthread.*is deprecated[^\n]*} $text "" text
282 regsub -all {(^|\n)[^\n]*Dwarf Error:.*FORM value: 14[^\n]*} $text "" text
283 regsub -all {(^|\n)[^\n]*In function[^\n]*} $text "" text
284 regsub -all {(^|\n)[^\n]*Using.*in statically linked applications requires[^\n]*} $text "" text