blob: c7beb63de2e86dae06ff131f92a1cc95a9b8673b [file] [log] [blame]
Nicolas Palix74425ee2010-06-06 17:15:01 +02001#!/bin/sh
2
3SPATCH="`which ${SPATCH:=spatch}`"
4
Nicolas Palix1e9dea22010-06-13 09:26:34 +02005if [ "$C" = "1" -o "$C" = "2" ]; then
6 ONLINE=1
7
8# This requires Coccinelle >= 0.2.3
9# FLAGS="-ignore_unknown_options -very_quiet"
10# OPTIONS=$*
11
12# Workaround for Coccinelle < 0.2.3
13 FLAGS="-I $srctree/include -very_quiet"
14 shift $(( $# - 1 ))
15 OPTIONS=$1
16else
17 ONLINE=0
18 FLAGS="-very_quiet"
Nicolas Palix2c1160c82010-10-08 21:27:40 +020019 OPTIONS="-dir $srctree"
Nicolas Palix1e9dea22010-06-13 09:26:34 +020020fi
21
Nicolas Palix74425ee2010-06-06 17:15:01 +020022if [ ! -x "$SPATCH" ]; then
23 echo 'spatch is part of the Coccinelle project and is available at http://coccinelle.lip6.fr/'
24 exit 1
25fi
26
27if [ "$MODE" = "" ] ; then
Nicolas Palix1e9dea22010-06-13 09:26:34 +020028 if [ "$ONLINE" = "0" ] ; then
Nicolas Palix2c1160c82010-10-08 21:27:40 +020029 echo 'You have not explicitly specified the mode to use. Using default "chain" mode.'
30 echo 'All available modes will be tried (in that order): patch, report, context, org'
Nicolas Palix1e9dea22010-06-13 09:26:34 +020031 echo 'You can specify the mode with "make coccicheck MODE=<mode>"'
Nicolas Palix1e9dea22010-06-13 09:26:34 +020032 fi
Nicolas Palix2c1160c82010-10-08 21:27:40 +020033 MODE="chain"
Nicolas Palix74425ee2010-06-06 17:15:01 +020034fi
35
Nicolas Palix1e9dea22010-06-13 09:26:34 +020036if [ "$ONLINE" = "0" ] ; then
37 echo ''
38 echo 'Please check for false positives in the output before submitting a patch.'
39 echo 'When using "patch" mode, carefully review the patch before submitting it.'
40 echo ''
41fi
Nicolas Palix74425ee2010-06-06 17:15:01 +020042
Nicolas Palix1e9dea22010-06-13 09:26:34 +020043coccinelle () {
Nicolas Palix74425ee2010-06-06 17:15:01 +020044 COCCI="$1"
Nicolas Palix74425ee2010-06-06 17:15:01 +020045
46 OPT=`grep "Option" $COCCI | cut -d':' -f2`
Nicolas Palix74425ee2010-06-06 17:15:01 +020047
48# The option '-parse_cocci' can be used to syntaxically check the SmPL files.
49#
Nicolas Palix1e9dea22010-06-13 09:26:34 +020050# $SPATCH -D $MODE $FLAGS -parse_cocci $COCCI $OPT > /dev/null
Nicolas Palix74425ee2010-06-06 17:15:01 +020051
Nicolas Palix1e9dea22010-06-13 09:26:34 +020052 if [ "$ONLINE" = "0" ] ; then
53
54 FILE=`echo $COCCI | sed "s|$srctree/||"`
55
Nicolas Palix3c908412010-10-08 21:27:38 +020056 echo "Processing `basename $COCCI`"
57 echo "with option(s) \"$OPT\""
58 echo ''
Nicolas Palix1e9dea22010-06-13 09:26:34 +020059 echo 'Message example to submit a patch:'
60
Nicolas Palix3c908412010-10-08 21:27:38 +020061 sed -ne 's|^///||p' $COCCI
Nicolas Palix1e9dea22010-06-13 09:26:34 +020062
63 echo ' The semantic patch that makes this change is available'
64 echo " in $FILE."
65 echo ''
66 echo ' More information about semantic patching is available at'
67 echo ' http://coccinelle.lip6.fr/'
68 echo ''
69
Nicolas Palix3c908412010-10-08 21:27:38 +020070 if [ "`sed -ne 's|^//#||p' $COCCI`" ] ; then
71 echo 'Semantic patch information:'
72 sed -ne 's|^//#||p' $COCCI
73 echo ''
74 fi
Nicolas Palix2c1160c82010-10-08 21:27:40 +020075 fi
Nicolas Palix3c908412010-10-08 21:27:38 +020076
Nicolas Palix2c1160c82010-10-08 21:27:40 +020077 if [ "$MODE" = "chain" ] ; then
78 $SPATCH -D patch $FLAGS -sp_file $COCCI $OPT $OPTIONS || \
79 $SPATCH -D report $FLAGS -sp_file $COCCI $OPT $OPTIONS || \
80 $SPATCH -D context $FLAGS -sp_file $COCCI $OPT $OPTIONS || \
81 $SPATCH -D org $FLAGS -sp_file $COCCI $OPT $OPTIONS || exit 1
Nicolas Palix1e9dea22010-06-13 09:26:34 +020082 else
Nicolas Palix2c1160c82010-10-08 21:27:40 +020083 $SPATCH -D $MODE $FLAGS -sp_file $COCCI $OPT $OPTIONS || exit 1
Nicolas Palix1e9dea22010-06-13 09:26:34 +020084 fi
85
Nicolas Palix74425ee2010-06-06 17:15:01 +020086}
87
88if [ "$COCCI" = "" ] ; then
89 for f in `find $srctree/scripts/coccinelle/ -name '*.cocci' -type f | sort`; do
Nicolas Palix1e9dea22010-06-13 09:26:34 +020090 coccinelle $f
Nicolas Palix74425ee2010-06-06 17:15:01 +020091 done
92else
Nicolas Palix1e9dea22010-06-13 09:26:34 +020093 coccinelle $COCCI
Nicolas Palix74425ee2010-06-06 17:15:01 +020094fi