OSDN Git Service

libjava/
[pf3gnuchains/gcc-fork.git] / libjava / classpath / scripts / check_jni_methods.sh.in
1 #!/bin/sh
2
3 # Fail if any command fails
4 set -e
5
6 TMPFILE=/tmp/check-jni-methods.$$.1
7 TMPFILE2=/tmp/check-jni-methods.$$.2
8 TMPFILE3=/tmp/check-jni-methods.$$.3
9
10 # Find all methods defined in the header files generated
11 # from the java source files.
12 grep -h '^JNIEXPORT .* Java_' @abs_top_builddir@/include/*.h @abs_top_srcdir@/include/*.h | \
13         LC_ALL=C sed -e 's,.*JNICALL \(Java_[a-z_A-Z0-9]*\).*$,\1,' | \
14         sort -u > $TMPFILE
15
16 # Find all methods in the JNI C source files.
17 find @abs_top_srcdir@/native/jni -name \*.c | \
18         xargs grep -h '^Java_' | \
19         LC_ALL=C sed -e 's,^\(Java_[a-z_A-Z0-9]*\).*$,\1,' > $TMPFILE2
20 # Or in the the C++ files. (Note that cpp doesn't follow gnu conventions atm)
21 # So we try to match both GNU style and some other style.
22 find @abs_top_srcdir@/native/jni -name \*.cpp | \
23         xargs grep -h '^Java_' | \
24         LC_ALL=C sed -e 's,^\(Java_[a-z_A-Z0-9]*\).*$,\1,' >> $TMPFILE2
25 find @abs_top_srcdir@/native/jni -name \*.cpp | \
26         xargs egrep -h '^(JNIEXPORT .* JNICALL )?Java_' | \
27         cut -f4 -d\  | \
28         LC_ALL=C sed -e 's,^\JNIEXPORT .* JNICALL \(Java_[a-z_A-Z0-9]*\).*$,\1,' >> $TMPFILE2
29 mv $TMPFILE2 $TMPFILE3
30 sort $TMPFILE3 | uniq > $TMPFILE2
31 rm $TMPFILE3
32
33 # Write temporary ignore file.
34 cat > $TMPFILE3 << EOF
35 -Java_gnu_java_awt_peer_gtk_GtkMenuComponentPeer_dispose
36 -Java_java_lang_VMSystem_arraycopy
37 -Java_java_lang_VMSystem_identityHashCode
38 EOF
39
40 # Compare again silently.
41 # Use fgrep and direct the output to /dev/null for compatibility with older
42 # grep instead of using the non portable -q.
43 if diff -U 0 $TMPFILE $TMPFILE2 | grep '^[+-]Java' | \
44     fgrep -v -f $TMPFILE3 > /dev/null;
45 then
46   PROBLEM=1
47   echo "Found a problem with the JNI methods declared and implemented."
48   echo "(-) missing in implementation, (+) missing in header files"
49
50   # Compare the found method lists.
51   diff -U 0 $TMPFILE $TMPFILE2  | grep '^[+-]Java' | fgrep -v -f $TMPFILE3
52 fi
53
54 # Cleanup.
55 rm -f $TMPFILE $TMPFILE2 $TMPFILE3
56
57 if test "$PROBLEM" = "1" ; then
58   exit 1
59 fi
60
61 exit 0