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.
20 # Define libffi callbacks for dg.exp.
22 proc libffi-dg-test-1 { target_compile prog do_what extra_tool_flags } {
23 # Set up the compiler flags, based on what we're going to do.
28 set compile_type "assembly"
29 set output_file "[file rootname [file tail $prog]].s"
32 set compile_type "executable"
33 set output_file "[file rootname [file tail $prog]].exe"
34 # The following line is needed for targets like the i960 where
35 # the default output file is b.out. Sigh.
38 set compile_type "executable"
39 # FIXME: "./" is to cope with "." not being in $PATH.
40 # Should this be handled elsewhere?
42 set output_file "./[file rootname [file tail $prog]].exe"
43 # This is the only place where we care if an executable was
44 # created or not. If it was, dg.exp will try to run it.
45 remote_file build delete $output_file;
48 perror "$do_what: not a valid dg-do keyword"
53 if { $extra_tool_flags != "" } {
54 lappend options "additional_flags=$extra_tool_flags"
57 set comp_output [libffi_target_compile "$prog" "$output_file" "$compile_type" $options];
60 return [list $comp_output $output_file]
64 proc libffi-dg-test { prog do_what extra_tool_flags } {
65 return [libffi-dg-test-1 target_compile $prog $do_what $extra_tool_flags]
68 proc libffi-init { args } {
69 global gluefile wrap_flags;
74 global ld_library_path
76 global libffi_link_flags
79 set blddirffi [lookfor_file [get_multilibs] libffi]
80 verbose "libffi $blddirffi"
81 set blddircxx [lookfor_file [get_multilibs] libstdc++-v3]
82 verbose "libstdc++ $blddircxx"
84 set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a]
86 set gccdir [file dirname $gccdir]
88 verbose "gccdir $gccdir"
90 set ld_library_path "."
91 append ld_library_path ":${gccdir}"
93 set compiler "${gccdir}/xgcc"
94 if { [is_remote host] == 0 && [which $compiler] != 0 } {
95 foreach i "[exec $compiler --print-multi-lib]" {
97 regexp -- "\[a-z0-9=/\.-\]*;" $i mldir
98 set mldir [string trimright $mldir "\;@"]
99 if { "$mldir" == "." } {
102 if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] == 1 } {
103 append ld_library_path ":${gccdir}/${mldir}"
107 # add the library path for libffi.
108 append ld_library_path ":${blddirffi}/.libs"
109 # add the library path for libstdc++ as well.
110 append ld_library_path ":${blddircxx}/src/.libs"
112 verbose "ld_library_path: $ld_library_path"
114 # Point to the Libffi headers in libffi.
115 set libffi_include "${blddirffi}/include"
116 verbose "libffi_include $libffi_include"
118 set libffi_dir "${blddirffi}/.libs"
119 verbose "libffi_dir $libffi_dir"
120 if { $libffi_dir != "" } {
121 set libffi_dir [file dirname ${libffi_dir}]
122 set libffi_link_flags "-L${libffi_dir}/.libs"
123 lappend libffi_link_flags "-L${blddircxx}/src/.libs"
126 # On IRIX 6, we have to set variables akin to LD_LIBRARY_PATH, but
127 # called LD_LIBRARYN32_PATH (for the N32 ABI) and LD_LIBRARY64_PATH
128 # (for the 64-bit ABI). The right way to do this would be to modify
129 # unix.exp -- but that's not an option since it's part of DejaGNU
130 # proper, so we do it here. We really only need to do
131 # this on IRIX, but it shouldn't hurt to do it anywhere else.
132 setenv LD_LIBRARY_PATH $ld_library_path
133 setenv SHLIB_PATH $ld_library_path
134 setenv LD_LIBRARYN32_PATH $ld_library_path
135 setenv LD_LIBRARY64_PATH $ld_library_path
136 setenv LD_LIBRARY_PATH_64 $ld_library_path
139 proc libffi_target_compile { source dest type options } {
140 global gluefile wrap_flags;
144 global ld_library_path
145 global libffi_link_flags
146 global libffi_include
149 if { [target_info needs_status_wrapper]!="" && [info exists gluefile] } {
150 lappend options "libs=${gluefile}"
151 lappend options "ldflags=$wrap_flags"
154 # TOOL_OPTIONS must come first, so that it doesn't override testcase
156 if [info exists TOOL_OPTIONS] {
157 lappend options [concat "additional_flags=$TOOL_OPTIONS" $options];
160 # search for ffi_mips.h in srcdir, too
161 lappend options "additional_flags=-I${libffi_include} -I${srcdir}/../include"
162 lappend options "additional_flags=${libffi_link_flags}"
163 lappend options "libs= -lffi"
164 verbose "options: $options"
165 return [target_compile $source $dest $type $options]
171 # search_for -- looks for a string match in a file
173 proc search_for { file pattern } {
174 set fd [open $file r]
175 while { [gets $fd cur_line]>=0 } {
176 if [string match "*$pattern*" $cur_line] then {
185 # Modified dg-runtest that can cycle through a list of optimization options
187 proc libffi-dg-runtest { testcases default-extra-flags } {
190 foreach test $testcases {
191 # If we're only testing specific files and this isn't one of
193 if ![runtest_file_p $runtests $test] {
197 # Look for a loop within the source code - if we don't find one,
198 # don't pass -funroll[-all]-loops.
199 global torture_with_loops torture_without_loops
200 if [expr [search_for $test "for*("]+[search_for $test "while*("]] {
201 set option_list $torture_with_loops
203 set option_list $torture_without_loops
206 set nshort [file tail [file dirname $test]]/[file tail $test]
208 foreach flags $option_list {
209 verbose "Testing $nshort, $flags" 1
210 dg-test $test $flags ${default-extra-flags}
216 # Like check_conditional_xfail, but callable from a dg test.
218 proc dg-xfail-if { args } {
219 set args [lreplace $args 0 0]
220 set selector "target [join [lindex $args 1]]"
221 if { [dg-process-target $selector] == "S" } {
222 global compiler_conditional_xfail_data
223 set compiler_conditional_xfail_data $args
228 # We need to make sure that additional_files and additional_sources
229 # are both cleared out after every test. It is not enough to clear
230 # them out *before* the next test run because gcc-target-compile gets
231 # run directly from some .exp files (outside of any test). (Those
232 # uses should eventually be eliminated.)
234 # Because the DG framework doesn't provide a hook that is run at the
235 # end of a test, we must replace dg-test with a wrapper.
237 if { [info procs saved-dg-test] == [list] } {
238 rename dg-test saved-dg-test
240 proc dg-test { args } {
241 global additional_files
242 global additional_sources
245 if { [ catch { eval saved-dg-test $args } errmsg ] } {
246 set saved_info $errorInfo
247 set additional_files ""
248 set additional_sources ""
249 error $errmsg $saved_info
251 set additional_files ""
252 set additional_sources ""