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 [prune_warnings [target_compile $file $soname executable $options]]
20 verbose "target_compile failed: $x" 2
21 fail "$name.c compilation"
25 pass "$name.c compilation"
29 # Build a header file from a .class file. Return 0 on failure.
30 proc gcj_jni_build_header {file} {
32 set file [file rootname $file]
33 set options [list "compiler=$gcjh" \
34 "additional_flags=-jni"]
35 set x [prune_warnings [target_compile $file "" none $options]]
37 verbose "target_compile failed: $x" 2
38 fail "$file header generation"
42 pass "$file header generation"
46 # Invoke the program and see what happens. Return 0 on failure.
47 proc gcj_invoke {program expectFile} {
49 set lib_path $env(LD_LIBRARY_PATH)
50 setenv LD_LIBRARY_PATH .:$lib_path
51 setenv SHLIB_PATH .:$lib_path
53 verbose "LD_LIBRARY_PATH=$env(LD_LIBRARY_PATH)"
55 set result [libjava_load ./$program]
56 set status [lindex $result 0]
57 set output [lindex $result 1]
60 setenv LD_LIBRARY_PATH $lib_path
61 setenv SHLIB_PATH $lib_path
63 if {$status != "pass"} {
66 untested "$program output"
70 set id [open $expectFile r]
71 set expected [read $id]
74 if {! [string compare $output $expected]} {
75 pass "$program output"
78 fail "$program output"
83 # Do all the work for a single JNI test. Return 0 on failure.
84 proc gcj_jni_test_one {file} {
87 # The base name. We use it for several purposes.
88 set main [file rootname [file tail $file]]
89 if {! [runtest_file_p $runtests $main]} {
94 if {! [bytecompile_file $file [pwd]]} {
95 fail "bytecompile $file"
96 # FIXME - should use `untested' on all remaining tests.
100 pass "bytecompile $file"
102 set bytefile [file rootname [file tail $file]].class
103 if {! [gcj_jni_build_header $bytefile]} {
108 set cfile [file rootname $file].c
110 # If there is no `.c' file, assume there is a `.cc' file.
111 if {! [file exists $cfile]} {
112 set cfile [file rootname $file].cc
113 set cxxflags "-lstdc++"
116 if {! [gcj_jni_compile_c_to_so $cfile]} {
121 # We use -l$main because the .so is named the same as the main
123 set args [list "additional_flags=-fjni -L. -l$main $cxxflags"]
124 if {! [gcj_link $main $main $file $args]} {
129 if {! [gcj_invoke $main [file rootname $file].out]} {
134 # When we succeed we remove all our clutter.
135 eval gcj_cleanup [glob -nocomplain -- ${main}.*] [list $main lib${main}.so]
141 proc gcj_jni_run {} {
143 global target_triplet host_triplet
145 # For now we only test JNI on native builds.
146 if {$target_triplet == $host_triplet} {
147 catch "glob -nocomplain ${srcdir}/${subdir}/*.java" srcfiles
149 foreach x $srcfiles {
153 verbose "JNI tests not run in cross-compilation environment"