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 set name [file rootname [file tail $file]]
10 set soname lib${name}.so
12 lappend options "additional_flags=-shared -fPIC"
13 # Find the generated header.
14 lappend options "additional_flags=-I. -I.."
16 lappend options "additional_flags=-I$srcdir/../include"
18 set x [libjava_prune_warnings \
19 [target_compile $file $soname executable $options]]
21 verbose "target_compile failed: $x" 2
22 fail "$name.c compilation"
26 pass "$name.c compilation"
30 # Build a header file from a .class file. Return 0 on failure.
31 proc gcj_jni_build_header {file} {
33 set file [file rootname $file]
34 set x [string trim [libjava_prune_warnings \
35 [lindex [local_exec "$gcjh -jni $file" "" "" 300] 1]]]
37 verbose "local_exec failed: $x" 2
38 fail "$file header generation"
42 pass "$file header generation"
46 # Do all the work for a single JNI test. Return 0 on failure.
47 proc gcj_jni_test_one {file} {
50 # The base name. We use it for several purposes.
51 set main [file rootname [file tail $file]]
52 if {! [runtest_file_p $runtests $main]} {
57 if {! [bytecompile_file $file [pwd]]} {
58 fail "bytecompile $file"
59 # FIXME - should use `untested' on all remaining tests.
63 pass "bytecompile $file"
65 set bytefile [file rootname [file tail $file]].class
66 if {! [gcj_jni_build_header $bytefile]} {
71 set cfile [file rootname $file].c
74 # If there is no `.c' file, assume there is a `.cc' file.
75 if {! [file exists $cfile]} {
76 set cfile [file rootname $file].cc
79 foreach arg [split [libjava_find_lib libstdc++-v3/src stdc++] " "] {
80 switch -glob -- $arg {
82 set arg [string range $arg 2 end]
83 lappend cxxldlibflags $arg
84 # Strip the `.libs' directory; we link with libtool which
86 set arg "-L[file dirname $arg]"
89 lappend cxxflaglist $arg
92 lappend cxxflaglist "-lstdc++"
93 set cxxflags [join $cxxflaglist]
96 if {! [gcj_jni_compile_c_to_so $cfile]} {
101 # We use -l$main because the .so is named the same as the main
103 set args [list "additional_flags=-fjni -L. -l$main $cxxflags"]
104 if {! [gcj_link $main $main $file $args]} {
109 if {! [gcj_invoke $main [file rootname $file].out $cxxldlibflags]} {
114 # When we succeed we remove all our clutter.
115 eval gcj_cleanup [glob -nocomplain -- ${main}.*] [list $main lib${main}.so]
121 proc gcj_jni_run {} {
123 global build_triplet host_triplet
125 # For now we only test JNI on native builds.
126 if {$build_triplet == $host_triplet} {
127 catch { lsort [glob -nocomplain ${srcdir}/${subdir}/*.java] } srcfiles
129 foreach x $srcfiles {
133 verbose "JNI tests not run in cross-compilation environment"