Merged gcj-eclipse branch to trunk.
[official-gcc.git] / libjava / classpath / scripts / check_jni_methods.sh
blobb46e378214e0f3e05bea79aae61d04cdd4e967f9
1 #!/bin/sh
3 # Fail if any command fails
4 set -e
6 TMPFILE=/tmp/check-jni-methods.$$.1
7 TMPFILE2=/tmp/check-jni-methods.$$.2
8 TMPFILE3=/tmp/check-jni-methods.$$.3
10 # Find all methods defined in the header files generated
11 # from the java source files.
12 grep -h '^JNIEXPORT .* Java_' include/*.h | \
13 LC_ALL=C sed -e 's,.*JNICALL \(Java_[a-z_A-Z0-9]*\).*$,\1,' | \
14 sort > $TMPFILE
16 # Find all methods in the JNI C source files.
17 find 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 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 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
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
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 -b -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"
50 # Compare the found method lists.
51 diff -b -U 0 $TMPFILE $TMPFILE2 | grep '^[+-]Java' | fgrep -v -f $TMPFILE3
54 # Cleanup.
55 rm -f $TMPFILE $TMPFILE2 $TMPFILE3
57 if test "$PROBLEM" = "1" ; then
58 exit 1
61 exit 0