3 #
Compile a single C file and produce a .so file. OPTIONS is a list
4 # of options to pass to the compiler. Returns
0 on failure
, 1 on
6 proc gcj_jni_compile_c_to_so
{file
{options
{}}} {
9 verbose
"options: $options"
10 set options_cxx $options
13 # Apple uses a different extension
for shared
/dynamic libraries
14 # so we check against powerpc
-apple
-darwin and
set them to
16 # HP
-UX uses sl
, so we check this too
, otherwise we take so.
18 if { [istarget
"*-*-darwin*"] } {
19 set so_extension
"dylib"
20 set so_flag
"-dynamiclib"
21 } elseif
{ [istarget
"hppa*-hp-hpux*"] } {
28 set filename
[file tail $file
]
29 set name [file rootname $filename
]
30 set soname lib$
{name}.$
{so_extension
}
32 lappend options
"additional_flags=${so_flag} -fPIC"
33 # Find the generated header.
34 lappend options
"additional_flags=-I. -I.."
36 # Ensure that the generated header has correct prototypes.
37 set cfile
[file rootname $file
].c
38 if { [file
exists $cfile
]} {
39 # This option is only valid
for C sources.
40 lappend options
"additional_flags=-Wmissing-prototypes"
43 # Find jni.h and jni_md.h.
44 lappend options
"additional_flags=-I$srcdir/../include -I$srcdir/../classpath/include"
47 lappend options
"additional_flags=$options_cxx"
49 set x
[libjava_prune_warnings \
50 [target_compile $file $soname executable $options
]]
52 verbose
"target_compile failed: $x" 2
53 fail
"$filename compilation"
57 pass
"$filename compilation"
61 # Build a header file from a .class file.
Return 0 on failure.
62 proc gcj_jni_build_header
{file
} {
64 set file
[file rootname $file
]
65 set x
[string trim
[libjava_prune_warnings \
66 [lindex
[local_exec
"$gcjh -jni $file" "" "" 300] 1]]]
68 verbose
"local_exec failed: $x" 2
69 fail
"$file header generation"
73 pass
"$file header generation"
77 #
Do all the work
for a single JNI test.
Return 0 on failure.
78 proc gcj_jni_test_one
{file
} {
83 # Apple uses a different extension
for shared
/dynamic libraries
84 # so we check against powerpc
-apple
-darwin and
set them to
86 # HP
-UX uses sl
, so we check this too
, otherwise we take so.
88 if { [istarget
"*-*-darwin*"] } {
89 set so_extension
"dylib"
90 } elseif
{ [istarget
"hppa*-hp-hpux*"] } {
96 # The base
name. We use it
for several purposes.
97 set main
[file rootname
[file tail $file
]]
98 if {! [runtest_file_p $runtests $main
]} {
103 if {! [bytecompile_file $file
[pwd
]]} {
104 fail
"bytecompile $file"
105 # FIXME
- should use `untested
' on all remaining tests.
109 pass "bytecompile $file"
111 set bytefile [file rootname [file tail $file]].class
112 if {! [gcj_jni_build_header $bytefile]} {
117 set cfile [file rootname $file].c
120 # If there is no `.c' file
, assume there is a `.cc
' file.
121 if {! [file exists $cfile]} {
122 set cfile [file rootname $file].cc
125 foreach arg [split [libjava_find_lib libstdc++-v3/src stdc++] " "] {
126 switch -glob -- $arg {
128 set arg [string range $arg 2 end]
129 lappend cxxldlibflags $arg
130 # Strip the `.libs' directory
; we link with libtool which
132 set arg "-L[file dirname $arg]"
135 lappend cxxflaglist $arg
136 # In case the libstdc++ is not installed yet, we pass the build
137 # directory of it to the cxxflaglist.
138 lappend cxxflaglist "-L$cxxldlibflags"
141 # If you're building the compiler with
--prefix
set to a place
142 # where it
's not yet installed, then the linker won't be able to
143 # find the libgcc used by libffi.dylib. We could pass the
144 #
-dylib_file option
, but that
's complicated, and it's much easier
145 # to just make the linker find libgcc using
-L options.
146 if { [istarget
"*-*-darwin*"] } {
147 lappend cxxflaglist
"-shared-libgcc -lstdc++"
149 lappend cxxflaglist
"-lstdc++"
152 set cxxflags
[join $cxxflaglist
]
155 if {! [gcj_jni_compile_c_to_so $cfile $cxxflags
]} {
160 set args [list
"additional_flags=-fjni"]
161 if {! [gcj_link $main $main $file $
args]} {
166 set resultfile
[file rootname $file
].out
168 if {! [gcj_invoke $main $resultfile $cxxldlibflags
]} {
173 # We purposely ignore errors here
; we still want to run the other
175 set errname
[file rootname
[file tail $file
]]
176 set gij
[libjava_find_gij
]
177 # libjava_find_gij will
return "" if it couldn't find the
178 #
program; in this case we want to skip the test.
179 #
If the libraries are not installed yet
, we have to pass them via
180 # cxxldlibflags to libjava_invoke.
181 if {$INTERPRETER
== "yes" && $gij != ""} {
182 libjava_invoke $errname
"gij test" opts $gij \
183 "" $resultfile $cxxldlibflags $main
186 # When we succeed we remove all our clutter.
187 eval gcj_cleanup
[glob
-nocomplain
-- $
{main
}.
*] \
188 [list $main lib$
{main
}.$
{so_extension
}]
193 #
Compile a single C file and produce a binary. OPTIONS is a list of
194 # options to pass to the compiler. Returns
0 on failure
, 1 on
196 proc gcj_jni_invocation_compile_c_to_binary
{file
{options
{}}} {
199 verbose
"options: $options"
200 set options_cxx $options
203 set filename
[file tail $file
]
204 set name [file rootname $filename
]
206 #
Set some darwin specific options
207 if { [istarget
"*-*-darwin*"] } {
208 lappend options
"additional_flags= -bind_at_load -multiply_defined suppress"
210 # Find the generated header.
211 lappend options
"additional_flags=-I. -I.."
213 # Find jni.h and jni_md.h.
214 lappend options
"additional_flags=-I$srcdir/../include -I$srcdir/../classpath/include"
217 lappend options
"additional_flags=$options_cxx"
219 set x
[libjava_prune_warnings \
220 [target_compile $file $
name executable $options
]]
222 verbose
"target_compile failed: $x" 2
223 fail
"$filename compilation"
227 pass
"$filename compilation"
231 #
Do all the work
for a single invocation API test.
Return 0 on
233 proc gcj_jni_invocation_test_one
{file
} {
238 # The base
name. We use it
for several purposes.
239 set main
[file rootname
[file tail $file
]]
240 if {! [runtest_file_p $runtests $main
]} {
245 if {! [bytecompile_file $file
[pwd
]]} {
246 fail
"bytecompile $file"
247 # FIXME
- should use `untested
' on all remaining tests.
251 pass "bytecompile $file"
253 set cfile [file rootname $file].c
254 # Darwin needs -liconv linked, otherwise we get some unresolved.
255 # If you're building the compiler with
--prefix
set to a place
256 # where it
's not yet installed, then the linker won't be able to
257 # find the libgcc used by libffi.dylib. We could pass the
258 #
-dylib_file option
, but that
's complicated, and it's much easier
259 # to just make the linker find libgcc using
-L options.
260 if { [istarget
"*-*-darwin*"] } {
261 set cxxflags
"-L../.libs -shared-libgcc -lgcj -liconv"
264 if [info exists LIBJAVA
] {
265 set libjava $LIBJAVA
;
267 set libjava
[libjava_find_lib libjava gcj
]
269 set cxxflags
"$libjava -lgcj"
272 if { [istarget
"*-*-solaris*"] } {
273 lappend cxxflags
"-lsocket"
276 if {! [gcj_jni_invocation_compile_c_to_binary $cfile $cxxflags
]} {
281 set resultfile
[file rootname $file
].out
283 if {! [gcj_invoke $main $resultfile
""]} {
288 # We purposely ignore errors here
; we still want to run the other
290 set errname
[file rootname
[file tail $file
]]
292 # When we succeed we remove all our clutter.
293 eval gcj_cleanup
[glob
-nocomplain
-- $
{main
}.
*] \
300 proc gcj_jni_run
{} {
302 global build_triplet host_triplet
304 #
For now we only test JNI
on native builds.
305 if {$build_triplet
== $host_triplet
} {
306 catch
{ lsort
[glob
-nocomplain $
{srcdir
}/$
{subdir
}/*.java
] } srcfiles
308 foreach x $srcfiles
{
312 # Run JNI invocation API tests
313 catch
{ lsort
[glob
-nocomplain $
{srcdir
}/$
{subdir
}/invocation
/*.java
] } srcfiles
315 foreach x $srcfiles
{
316 gcj_jni_invocation_test_one $x
319 verbose
"JNI tests not run in cross-compilation environment"