1 # Copyright (C) 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 proc load_gcc_lib { filename } {
19 load_file $srcdir/../../gcc/testsuite/lib/$filename
24 load_gcc_lib wrapper.exp
27 # Define libffi callbacks for dg.exp.
29 proc libffi-dg-test-1 { target_compile prog do_what extra_tool_flags } {
30 # Set up the compiler flags, based on what we're going to do.
35 set compile_type "assembly"
36 set output_file "[file rootname [file tail $prog]].s"
39 set compile_type "executable"
40 set output_file "[file rootname [file tail $prog]].exe"
41 # The following line is needed for targets like the i960 where
42 # the default output file is b.out. Sigh.
45 set compile_type "executable"
46 # FIXME: "./" is to cope with "." not being in $PATH.
47 # Should this be handled elsewhere?
49 set output_file "./[file rootname [file tail $prog]].exe"
50 # This is the only place where we care if an executable was
51 # created or not. If it was, dg.exp will try to run it.
52 remote_file build delete $output_file;
55 perror "$do_what: not a valid dg-do keyword"
60 if { $extra_tool_flags != "" } {
61 lappend options "additional_flags=$extra_tool_flags"
64 set comp_output [libffi_target_compile "$prog" "$output_file" "$compile_type" $options];
67 return [list $comp_output $output_file]
71 proc libffi-dg-test { prog do_what extra_tool_flags } {
72 return [libffi-dg-test-1 target_compile $prog $do_what $extra_tool_flags]
75 proc libffi-init { args } {
76 global gluefile wrap_flags;
84 global libffi_link_flags
87 set blddirffi [lookfor_file [get_multilibs] libffi]
88 verbose "libffi $blddirffi"
89 set blddircxx [lookfor_file [get_multilibs] libstdc++-v3]
90 verbose "libstdc++ $blddircxx"
92 set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a]
94 set gccdir [file dirname $gccdir]
96 verbose "gccdir $gccdir"
98 set ld_library_path "."
99 append ld_library_path ":${gccdir}"
101 set compiler "${gccdir}/xgcc"
102 if { [is_remote host] == 0 && [which $compiler] != 0 } {
103 foreach i "[exec $compiler --print-multi-lib]" {
105 regexp -- "\[a-z0-9=/\.-\]*;" $i mldir
106 set mldir [string trimright $mldir "\;@"]
107 if { "$mldir" == "." } {
110 if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] >= 1 } {
111 append ld_library_path ":${gccdir}/${mldir}"
115 # add the library path for libffi.
116 append ld_library_path ":${blddirffi}/.libs"
117 # add the library path for libstdc++ as well.
118 append ld_library_path ":${blddircxx}/src/.libs"
120 verbose "ld_library_path: $ld_library_path"
122 # Point to the Libffi headers in libffi.
123 set libffi_include "${blddirffi}/include"
124 verbose "libffi_include $libffi_include"
126 set libffi_dir "${blddirffi}/.libs"
127 verbose "libffi_dir $libffi_dir"
128 if { $libffi_dir != "" } {
129 set libffi_dir [file dirname ${libffi_dir}]
130 set libffi_link_flags "-L${libffi_dir}/.libs"
131 lappend libffi_link_flags "-L${blddircxx}/src/.libs"
134 # On IRIX 6, we have to set variables akin to LD_LIBRARY_PATH, but
135 # called LD_LIBRARYN32_PATH (for the N32 ABI) and LD_LIBRARY64_PATH
136 # (for the 64-bit ABI). The right way to do this would be to modify
137 # unix.exp -- but that's not an option since it's part of DejaGNU
138 # proper, so we do it here.
139 # The same applies to darwin (DYLD_LIBRARY_PATH), solaris 32 bit
140 # (LD_LIBRARY_PATH_32), solaris 64 bit (LD_LIBRARY_PATH_64), and HP-UX
142 if {![is_remote target]} {
143 set ld_path "LD_LIBRARY_PATH SHLIB_PATH LD_LIBRARYN32_PATH LD_LIBRARY64_PATH LD_LIBRARY_PATH_32 LD_LIBRARY_PATH_64 DYLD_LIBRARY_PATH"
144 foreach path $ld_path {
145 if [info exists env($path)] {
146 # If we've already added these directories once, keep
148 if {$ld_library_path != $env($path)
149 && [string first $ld_library_path: $env($path)] != 0} {
150 setenv $path "$ld_library_path:$env($path)"
153 setenv $path "$ld_library_path"
157 libffi_maybe_build_wrapper "${objdir}/testglue.o"
160 proc libffi_exit { } {
163 if [info exists gluefile] {
164 file_on_build delete $gluefile;
169 proc libffi_target_compile { source dest type options } {
170 global gluefile wrap_flags;
174 global libffi_link_flags
175 global libffi_include
176 global target_triplet
179 if { [target_info needs_status_wrapper]!="" && [info exists gluefile] } {
180 lappend options "libs=${gluefile}"
181 lappend options "ldflags=$wrap_flags"
184 # TOOL_OPTIONS must come first, so that it doesn't override testcase
186 if [info exists TOOL_OPTIONS] {
187 lappend options [concat "additional_flags=$TOOL_OPTIONS" $options];
190 # search for ffi_mips.h in srcdir, too
191 lappend options "additional_flags=-I${libffi_include} -I${srcdir}/../include -I${libffi_include}/.."
192 lappend options "additional_flags=${libffi_link_flags}"
194 if { [string match "powerpc-*-darwin*" $target_triplet] } {
195 lappend options "libs= -lgcc_s"
198 lappend options "libs= -lffi"
200 verbose "options: $options"
201 return [target_compile $source $dest $type $options]
207 # search_for -- looks for a string match in a file
209 proc search_for { file pattern } {
210 set fd [open $file r]
211 while { [gets $fd cur_line]>=0 } {
212 if [string match "*$pattern*" $cur_line] then {
221 # Modified dg-runtest that can cycle through a list of optimization options
223 proc libffi-dg-runtest { testcases default-extra-flags } {
226 foreach test $testcases {
227 # If we're only testing specific files and this isn't one of
229 if ![runtest_file_p $runtests $test] {
233 # Look for a loop within the source code - if we don't find one,
234 # don't pass -funroll[-all]-loops.
235 global torture_with_loops torture_without_loops
236 if [expr [search_for $test "for*("]+[search_for $test "while*("]] {
237 set option_list $torture_with_loops
239 set option_list $torture_without_loops
242 set nshort [file tail [file dirname $test]]/[file tail $test]
244 foreach flags $option_list {
245 verbose "Testing $nshort, $flags" 1
246 dg-test $test $flags ${default-extra-flags}
252 # Like check_conditional_xfail, but callable from a dg test.
254 proc dg-xfail-if { args } {
255 set args [lreplace $args 0 0]
256 set selector "target [join [lindex $args 1]]"
257 if { [dg-process-target $selector] == "S" } {
258 global compiler_conditional_xfail_data
259 set compiler_conditional_xfail_data $args
264 # We need to make sure that additional_files and additional_sources
265 # are both cleared out after every test. It is not enough to clear
266 # them out *before* the next test run because gcc-target-compile gets
267 # run directly from some .exp files (outside of any test). (Those
268 # uses should eventually be eliminated.)
270 # Because the DG framework doesn't provide a hook that is run at the
271 # end of a test, we must replace dg-test with a wrapper.
273 if { [info procs saved-dg-test] == [list] } {
274 rename dg-test saved-dg-test
276 proc dg-test { args } {
277 global additional_files
278 global additional_sources
281 if { [ catch { eval saved-dg-test $args } errmsg ] } {
282 set saved_info $errorInfo
283 set additional_files ""
284 set additional_sources ""
285 error $errmsg $saved_info
287 set additional_files ""
288 set additional_sources ""