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
15 # dylib
, else we assume it
's .so
17 if { [ regexp {powerpc-apple-darwin} $host_triplet] } {
18 set so_extension "dylib"
19 set so_flag "-dynamiclib"
24 set filename [file tail $file]
25 set name [file rootname $filename]
26 set soname lib${name}.${so_extension}
28 lappend options "additional_flags=${so_flag} -fPIC"
29 # Find the generated header.
30 lappend options "additional_flags=-I. -I.."
32 # Ensure that the generated header has correct prototypes.
33 set cfile [file rootname $file].c
34 if { [file exists $cfile]} {
35 # This option is only valid for C sources.
36 lappend options "additional_flags=-Wmissing-prototypes"
40 lappend options "additional_flags=-I$srcdir/../include"
43 lappend options "additional_flags=$options_cxx"
45 set x [libjava_prune_warnings \
46 [target_compile $file $soname executable $options]]
48 verbose "target_compile failed: $x" 2
49 fail "$filename compilation"
53 pass "$filename compilation"
57 # Build a header file from a .class file. Return 0 on failure.
58 proc gcj_jni_build_header {file} {
60 set file [file rootname $file]
61 set x [string trim [libjava_prune_warnings \
62 [lindex [local_exec "$gcjh -jni $file" "" "" 300] 1]]]
64 verbose "local_exec failed: $x" 2
65 fail "$file header generation"
69 pass "$file header generation"
73 # Do all the work for a single JNI test. Return 0 on failure.
74 proc gcj_jni_test_one {file} {
79 # apple uses a different extension for shared/dynamic libraries
80 # so we check against powerpc-apple-darwin and set them to
81 # dylib, else we assume it's .so
83 if { [ regexp
{powerpc
-apple
-darwin
} $host_triplet
] } {
84 set so_extension
"dylib"
89 # The base
name. We use it
for several purposes.
90 set main
[file rootname
[file tail $file
]]
91 if {! [runtest_file_p $runtests $main
]} {
96 if {! [bytecompile_file $file
[pwd
]]} {
97 fail
"bytecompile $file"
98 # FIXME
- should use `untested
' on all remaining tests.
102 pass "bytecompile $file"
104 set bytefile [file rootname [file tail $file]].class
105 if {! [gcj_jni_build_header $bytefile]} {
110 set cfile [file rootname $file].c
113 # If there is no `.c' file
, assume there is a `.cc
' file.
114 if {! [file exists $cfile]} {
115 set cfile [file rootname $file].cc
118 foreach arg [split [libjava_find_lib libstdc++-v3/src stdc++] " "] {
119 switch -glob -- $arg {
121 set arg [string range $arg 2 end]
122 lappend cxxldlibflags $arg
123 # Strip the `.libs' directory
; we link with libtool which
125 set arg "-L[file dirname $arg]"
128 lappend cxxflaglist $arg
129 # In case the libstdc++ is not installed yet, we pass the build
130 # directory of it to the cxxflaglist.
131 lappend cxxflaglist "-L$cxxldlibflags"
134 # Darwin does not yet have a libgcc_s.dylib library.
135 # So we add it here. If the libgcc_s is installed, the libstdc++
137 if { [ regexp {powerpc-apple-darwin} $host_triplet] } {
138 lappend cxxflaglist "-lgcc_s -lstdc++"
140 lappend cxxflaglist "-lstdc++"
143 set cxxflags [join $cxxflaglist]
146 if {! [gcj_jni_compile_c_to_so $cfile $cxxflags]} {
151 set args [list "additional_flags=-fjni"]
152 if {! [gcj_link $main $main $file $args]} {
157 set resultfile [file rootname $file].out
159 if {! [gcj_invoke $main $resultfile $cxxldlibflags]} {
164 # We purposely ignore errors here; we still want to run the other
166 set errname [file rootname [file tail $file]]
167 set gij [libjava_find_gij]
168 # libjava_find_gij will return "" if it couldn't find the
169 #
program; in this case we want to skip the test.
170 #
If the libraries are not installed yet
, we have to pass them via
171 # cxxldlibflags to libjava_invoke.
172 if {$INTERPRETER
== "yes" && $gij != ""} {
173 libjava_invoke $errname
"gij test" opts $gij \
174 "" $resultfile $cxxldlibflags $main
177 # When we succeed we remove all our clutter.
178 eval gcj_cleanup
[glob
-nocomplain
-- $
{main
}.
*] \
179 [list $main lib$
{main
}.$
{so_extension
}]
184 #
Compile a single C file and produce a binary. OPTIONS is a list of
185 # options to pass to the compiler. Returns
0 on failure
, 1 on
187 proc gcj_jni_invocation_compile_c_to_binary
{file
{options
{}}} {
190 verbose
"options: $options"
191 set options_cxx $options
194 set filename
[file tail $file
]
195 set name [file rootname $filename
]
198 lappend options
"additional_flags=-I$srcdir/../include"
201 lappend options
"additional_flags=$options_cxx"
203 set x
[libjava_prune_warnings \
204 [target_compile $file $
name executable $options
]]
206 verbose
"target_compile failed: $x" 2
207 fail
"$filename compilation"
211 pass
"$filename compilation"
215 #
Do all the work
for a single invocation API test.
Return 0 on
217 proc gcj_jni_invocation_test_one
{file
} {
222 # The base
name. We use it
for several purposes.
223 set main
[file rootname
[file tail $file
]]
224 if {! [runtest_file_p $runtests $main
]} {
229 if {! [bytecompile_file $file
[pwd
]]} {
230 fail
"bytecompile $file"
231 # FIXME
- should use `untested
' on all remaining tests.
235 pass "bytecompile $file"
237 set cfile [file rootname $file].c
240 if {! [gcj_jni_invocation_compile_c_to_binary $cfile $cxxflags]} {
245 set resultfile [file rootname $file].out
247 if {! [gcj_invoke $main $resultfile ""]} {
252 # We purposely ignore errors here; we still want to run the other
254 set errname [file rootname [file tail $file]]
256 # When we succeed we remove all our clutter.
257 eval gcj_cleanup [glob -nocomplain -- ${main}.*] \
264 proc gcj_jni_run {} {
266 global build_triplet host_triplet
268 # For now we only test JNI on native builds.
269 if {$build_triplet == $host_triplet} {
270 catch { lsort [glob -nocomplain ${srcdir}/${subdir}/*.java] } srcfiles
272 foreach x $srcfiles {
276 # Run JNI invocation API tests
277 catch { lsort [glob -nocomplain ${srcdir}/${subdir}/invocation/*.java] } srcfiles
279 foreach x $srcfiles {
280 gcj_jni_invocation_test_one $x
283 verbose "JNI tests not run in cross-compilation environment"