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 name [file rootname [file tail $file]]
25 set soname lib${name}.${so_extension}
27 lappend options "additional_flags=${so_flag} -fPIC"
28 # Find the generated header.
29 lappend options "additional_flags=-I. -I.."
31 lappend options "additional_flags=-I$srcdir/../include"
33 set x [libjava_prune_warnings \
34 [target_compile $file $soname executable $options]]
36 verbose "target_compile failed: $x" 2
37 fail "$name.c compilation"
41 pass "$name.c compilation"
45 # Build a header file from a .class file. Return 0 on failure.
46 proc gcj_jni_build_header {file} {
48 set file [file rootname $file]
49 set x [string trim [libjava_prune_warnings \
50 [lindex [local_exec "$gcjh -jni $file" "" "" 300] 1]]]
52 verbose "local_exec failed: $x" 2
53 fail "$file header generation"
57 pass "$file header generation"
61 # Do all the work for a single JNI test. Return 0 on failure.
62 proc gcj_jni_test_one {file} {
66 # apple uses a different extension for shared/dynamic libraries
67 # so we check against powerpc-apple-darwin and set them to
68 # dylib, else we assume it's .so
70 if { [ regexp
{powerpc
-apple
-darwin
} $host_triplet
] } {
71 set so_extension
"dylib"
76 # The base
name. We use it
for several purposes.
77 set main
[file rootname
[file tail $file
]]
78 if {! [runtest_file_p $runtests $main
]} {
83 if {! [bytecompile_file $file
[pwd
]]} {
84 fail
"bytecompile $file"
85 # FIXME
- should use `untested
' on all remaining tests.
89 pass "bytecompile $file"
91 set bytefile [file rootname [file tail $file]].class
92 if {! [gcj_jni_build_header $bytefile]} {
97 set cfile [file rootname $file].c
100 # If there is no `.c' file
, assume there is a `.cc
' file.
101 if {! [file exists $cfile]} {
102 set cfile [file rootname $file].cc
105 foreach arg [split [libjava_find_lib libstdc++-v3/src stdc++] " "] {
106 switch -glob -- $arg {
108 set arg [string range $arg 2 end]
109 lappend cxxldlibflags $arg
110 # Strip the `.libs' directory
; we link with libtool which
112 set arg "-L[file dirname $arg]"
115 lappend cxxflaglist $arg
118 lappend cxxflaglist "-lstdc++"
119 set cxxflags [join $cxxflaglist]
122 if {! [gcj_jni_compile_c_to_so $cfile]} {
127 # We use -l$main because the .so is named the same as the main
129 set args [list "additional_flags=-fjni -L. -l$main $cxxflags"]
130 if {! [gcj_link $main $main $file $args]} {
135 if {! [gcj_invoke $main [file rootname $file].out $cxxldlibflags]} {
140 # When we succeed we remove all our clutter.
141 eval gcj_cleanup [glob -nocomplain -- ${main}.*] [list $main lib${main}.${so_extension}]
147 proc gcj_jni_run {} {
149 global build_triplet host_triplet
151 # For now we only test JNI on native builds.
152 if {$build_triplet == $host_triplet} {
153 catch { lsort [glob -nocomplain ${srcdir}/${subdir}/*.java] } srcfiles
155 foreach x $srcfiles {
159 verbose "JNI tests not run in cross-compilation environment"