]>
Commit | Line | Data |
---|---|---|
8a6b509e AT |
1 | # Copyright (C) 2003 Free Software Foundation, Inc. |
2 | ||
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. | |
7a54c850 | 7 | # |
8a6b509e AT |
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. | |
7a54c850 | 12 | # |
8a6b509e AT |
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 | |
7a54c850 | 15 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
8a6b509e AT |
16 | |
17 | load_lib dg.exp | |
18 | load_lib libgloss.exp | |
19 | ||
70d8f2a1 AT |
20 | |
21 | ||
8a6b509e AT |
22 | # Define libffi callbacks for dg.exp. |
23 | ||
24 | proc libffi-dg-test-1 { target_compile prog do_what extra_tool_flags } { | |
25 | # Set up the compiler flags, based on what we're going to do. | |
26 | ||
27 | set options [list] | |
28 | switch $do_what { | |
29 | "compile" { | |
30 | set compile_type "assembly" | |
31 | set output_file "[file rootname [file tail $prog]].s" | |
32 | } | |
33 | "link" { | |
34 | set compile_type "executable" | |
35 | set output_file "[file rootname [file tail $prog]].exe" | |
36 | # The following line is needed for targets like the i960 where | |
37 | # the default output file is b.out. Sigh. | |
38 | } | |
39 | "run" { | |
40 | set compile_type "executable" | |
41 | # FIXME: "./" is to cope with "." not being in $PATH. | |
42 | # Should this be handled elsewhere? | |
43 | # YES. | |
44 | set output_file "./[file rootname [file tail $prog]].exe" | |
45 | # This is the only place where we care if an executable was | |
46 | # created or not. If it was, dg.exp will try to run it. | |
47 | remote_file build delete $output_file; | |
48 | } | |
49 | default { | |
50 | perror "$do_what: not a valid dg-do keyword" | |
51 | return "" | |
52 | } | |
53 | } | |
54 | ||
55 | if { $extra_tool_flags != "" } { | |
56 | lappend options "additional_flags=$extra_tool_flags" | |
57 | } | |
58 | ||
59 | set comp_output [libffi_target_compile "$prog" "$output_file" "$compile_type" $options]; | |
60 | ||
61 | ||
62 | return [list $comp_output $output_file] | |
63 | } | |
64 | ||
65 | ||
66 | proc libffi-dg-test { prog do_what extra_tool_flags } { | |
67 | return [libffi-dg-test-1 target_compile $prog $do_what $extra_tool_flags] | |
68 | } | |
69 | ||
70 | proc libffi-init { args } { | |
71 | global gluefile wrap_flags; | |
72 | global srcdir | |
73 | global blddirffi | |
74 | global blddircxx | |
75 | global TOOL_OPTIONS | |
76 | global ld_library_path | |
77 | global libffi_include | |
7a54c850 | 78 | global libffi_link_flags |
8a6b509e AT |
79 | global tool_root_dir |
80 | ||
81 | set blddirffi [lookfor_file [get_multilibs] libffi] | |
82 | verbose "libffi $blddirffi" | |
83 | set blddircxx [lookfor_file [get_multilibs] libstdc++-v3] | |
84 | verbose "libstdc++ $blddircxx" | |
85 | ||
86 | set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a] | |
87 | if {$gccdir != ""} { | |
7a54c850 | 88 | set gccdir [file dirname $gccdir] |
8a6b509e AT |
89 | } |
90 | verbose "gccdir $gccdir" | |
91 | ||
92 | set ld_library_path "." | |
93 | append ld_library_path ":${gccdir}" | |
94 | ||
95 | set compiler "${gccdir}/xgcc" | |
96 | if { [is_remote host] == 0 && [which $compiler] != 0 } { | |
97 | foreach i "[exec $compiler --print-multi-lib]" { | |
98 | set mldir "" | |
99 | regexp -- "\[a-z0-9=/\.-\]*;" $i mldir | |
100 | set mldir [string trimright $mldir "\;@"] | |
101 | if { "$mldir" == "." } { | |
102 | continue | |
103 | } | |
104 | if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] == 1 } { | |
105 | append ld_library_path ":${gccdir}/${mldir}" | |
106 | } | |
107 | } | |
108 | } | |
109 | # add the library path for libffi. | |
110 | append ld_library_path ":${blddirffi}/.libs" | |
7a54c850 | 111 | # add the library path for libstdc++ as well. |
8a6b509e AT |
112 | append ld_library_path ":${blddircxx}/src/.libs" |
113 | ||
114 | verbose "ld_library_path: $ld_library_path" | |
115 | ||
116 | # Point to the Libffi headers in libffi. | |
117 | set libffi_include "${blddirffi}/include" | |
118 | verbose "libffi_include $libffi_include" | |
7a54c850 | 119 | |
8a6b509e AT |
120 | set libffi_dir "${blddirffi}/.libs" |
121 | verbose "libffi_dir $libffi_dir" | |
122 | if { $libffi_dir != "" } { | |
123 | set libffi_dir [file dirname ${libffi_dir}] | |
124 | set libffi_link_flags "-L${libffi_dir}/.libs" | |
125 | lappend libffi_link_flags "-L${blddircxx}/src/.libs" | |
126 | } | |
7a54c850 | 127 | |
8a6b509e AT |
128 | # On IRIX 6, we have to set variables akin to LD_LIBRARY_PATH, but |
129 | # called LD_LIBRARYN32_PATH (for the N32 ABI) and LD_LIBRARY64_PATH | |
130 | # (for the 64-bit ABI). The right way to do this would be to modify | |
131 | # unix.exp -- but that's not an option since it's part of DejaGNU | |
7a54c850 | 132 | # proper, so we do it here. We really only need to do |
8a6b509e AT |
133 | # this on IRIX, but it shouldn't hurt to do it anywhere else. |
134 | setenv LD_LIBRARY_PATH $ld_library_path | |
135 | setenv SHLIB_PATH $ld_library_path | |
136 | setenv LD_LIBRARYN32_PATH $ld_library_path | |
137 | setenv LD_LIBRARY64_PATH $ld_library_path | |
7a54c850 | 138 | setenv LD_LIBRARY_PATH_64 $ld_library_path |
70d8f2a1 | 139 | setenv DYLD_LIBRARY_PATH $ld_library_path |
8a6b509e AT |
140 | } |
141 | ||
142 | proc libffi_target_compile { source dest type options } { | |
143 | global gluefile wrap_flags; | |
144 | global srcdir | |
145 | global blddirffi | |
146 | global TOOL_OPTIONS | |
147 | global ld_library_path | |
148 | global libffi_link_flags | |
149 | global libffi_include | |
70d8f2a1 | 150 | global target_triplet |
7a54c850 | 151 | |
8a6b509e AT |
152 | |
153 | if { [target_info needs_status_wrapper]!="" && [info exists gluefile] } { | |
154 | lappend options "libs=${gluefile}" | |
155 | lappend options "ldflags=$wrap_flags" | |
156 | } | |
157 | ||
158 | # TOOL_OPTIONS must come first, so that it doesn't override testcase | |
159 | # specific options. | |
160 | if [info exists TOOL_OPTIONS] { | |
161 | lappend options [concat "additional_flags=$TOOL_OPTIONS" $options]; | |
162 | } | |
163 | ||
eb26c76c | 164 | # search for ffi_mips.h in srcdir, too |
5196736e | 165 | lappend options "additional_flags=-I${libffi_include} -I${srcdir}/../include -I${libffi_include}/.." |
8a6b509e | 166 | lappend options "additional_flags=${libffi_link_flags}" |
9e6c3ecb AT |
167 | |
168 | if { [string match "powerpc-*-darwin*" $target_triplet] } { | |
169 | lappend options "libs= -lgcc_s" | |
170 | } | |
171 | ||
172 | lappend options "libs= -lffi" | |
70d8f2a1 | 173 | |
8a6b509e AT |
174 | verbose "options: $options" |
175 | return [target_compile $source $dest $type $options] | |
176 | } | |
177 | ||
178 | # Utility routines. | |
179 | ||
180 | # | |
181 | # search_for -- looks for a string match in a file | |
182 | # | |
183 | proc search_for { file pattern } { | |
184 | set fd [open $file r] | |
185 | while { [gets $fd cur_line]>=0 } { | |
186 | if [string match "*$pattern*" $cur_line] then { | |
187 | close $fd | |
188 | return 1 | |
189 | } | |
190 | } | |
191 | close $fd | |
192 | return 0 | |
193 | } | |
194 | ||
195 | # Modified dg-runtest that can cycle through a list of optimization options | |
196 | # as c-torture does. | |
197 | proc libffi-dg-runtest { testcases default-extra-flags } { | |
198 | global runtests | |
199 | ||
200 | foreach test $testcases { | |
7a54c850 | 201 | # If we're only testing specific files and this isn't one of |
8a6b509e AT |
202 | # them, skip it. |
203 | if ![runtest_file_p $runtests $test] { | |
204 | continue | |
7a54c850 | 205 | } |
8a6b509e AT |
206 | |
207 | # Look for a loop within the source code - if we don't find one, | |
208 | # don't pass -funroll[-all]-loops. | |
209 | global torture_with_loops torture_without_loops | |
210 | if [expr [search_for $test "for*("]+[search_for $test "while*("]] { | |
211 | set option_list $torture_with_loops | |
212 | } else { | |
213 | set option_list $torture_without_loops | |
214 | } | |
215 | ||
216 | set nshort [file tail [file dirname $test]]/[file tail $test] | |
217 | ||
218 | foreach flags $option_list { | |
219 | verbose "Testing $nshort, $flags" 1 | |
220 | dg-test $test $flags ${default-extra-flags} | |
221 | } | |
222 | } | |
223 | } | |
224 | ||
225 | ||
226 | # Like check_conditional_xfail, but callable from a dg test. | |
227 | ||
228 | proc dg-xfail-if { args } { | |
229 | set args [lreplace $args 0 0] | |
230 | set selector "target [join [lindex $args 1]]" | |
231 | if { [dg-process-target $selector] == "S" } { | |
232 | global compiler_conditional_xfail_data | |
233 | set compiler_conditional_xfail_data $args | |
234 | } | |
235 | } | |
236 | ||
237 | ||
238 | # We need to make sure that additional_files and additional_sources | |
239 | # are both cleared out after every test. It is not enough to clear | |
240 | # them out *before* the next test run because gcc-target-compile gets | |
241 | # run directly from some .exp files (outside of any test). (Those | |
7a54c850 | 242 | # uses should eventually be eliminated.) |
8a6b509e AT |
243 | |
244 | # Because the DG framework doesn't provide a hook that is run at the | |
245 | # end of a test, we must replace dg-test with a wrapper. | |
246 | ||
247 | if { [info procs saved-dg-test] == [list] } { | |
248 | rename dg-test saved-dg-test | |
249 | ||
250 | proc dg-test { args } { | |
251 | global additional_files | |
252 | global additional_sources | |
253 | global errorInfo | |
254 | ||
255 | if { [ catch { eval saved-dg-test $args } errmsg ] } { | |
256 | set saved_info $errorInfo | |
257 | set additional_files "" | |
258 | set additional_sources "" | |
259 | error $errmsg $saved_info | |
260 | } | |
261 | set additional_files "" | |
262 | set additional_sources "" | |
263 | } | |
264 | } | |
265 | ||
266 | # Local Variables: | |
267 | # tcl-indent-level:4 | |
70d8f2a1 | 268 | # End: |