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