blob: ef78c875a0e363fa365b3b61d743188dcce6fe0f [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"
19fi
20
Nicolas Palix74425ee2010-06-06 17:15:01 +020021if [ ! -x "$SPATCH" ]; then
22 echo 'spatch is part of the Coccinelle project and is available at http://coccinelle.lip6.fr/'
23 exit 1
24fi
25
26if [ "$MODE" = "" ] ; then
Nicolas Palix1e9dea22010-06-13 09:26:34 +020027 if [ "$ONLINE" = "0" ] ; then
Nicolas Palix3c908412010-10-08 21:27:38 +020028 echo 'You have not explicitly specified the mode to use. Fallback to "report".'
Nicolas Palix1e9dea22010-06-13 09:26:34 +020029 echo 'You can specify the mode with "make coccicheck MODE=<mode>"'
30 echo 'Available modes are: report, patch, context, org'
31 fi
Nicolas Palix74425ee2010-06-06 17:15:01 +020032 MODE="report"
33fi
34
Nicolas Palix1e9dea22010-06-13 09:26:34 +020035if [ "$ONLINE" = "0" ] ; then
36 echo ''
37 echo 'Please check for false positives in the output before submitting a patch.'
38 echo 'When using "patch" mode, carefully review the patch before submitting it.'
39 echo ''
40fi
Nicolas Palix74425ee2010-06-06 17:15:01 +020041
Nicolas Palix1e9dea22010-06-13 09:26:34 +020042coccinelle () {
Nicolas Palix74425ee2010-06-06 17:15:01 +020043 COCCI="$1"
Nicolas Palix74425ee2010-06-06 17:15:01 +020044
45 OPT=`grep "Option" $COCCI | cut -d':' -f2`
Nicolas Palix74425ee2010-06-06 17:15:01 +020046
47# The option '-parse_cocci' can be used to syntaxically check the SmPL files.
48#
Nicolas Palix1e9dea22010-06-13 09:26:34 +020049# $SPATCH -D $MODE $FLAGS -parse_cocci $COCCI $OPT > /dev/null
Nicolas Palix74425ee2010-06-06 17:15:01 +020050
Nicolas Palix1e9dea22010-06-13 09:26:34 +020051 if [ "$ONLINE" = "0" ] ; then
52
53 FILE=`echo $COCCI | sed "s|$srctree/||"`
54
Nicolas Palix3c908412010-10-08 21:27:38 +020055 echo "Processing `basename $COCCI`"
56 echo "with option(s) \"$OPT\""
57 echo ''
Nicolas Palix1e9dea22010-06-13 09:26:34 +020058 echo 'Message example to submit a patch:'
59
Nicolas Palix3c908412010-10-08 21:27:38 +020060 sed -ne 's|^///||p' $COCCI
Nicolas Palix1e9dea22010-06-13 09:26:34 +020061
62 echo ' The semantic patch that makes this change is available'
63 echo " in $FILE."
64 echo ''
65 echo ' More information about semantic patching is available at'
66 echo ' http://coccinelle.lip6.fr/'
67 echo ''
68
Nicolas Palix3c908412010-10-08 21:27:38 +020069 if [ "`sed -ne 's|^//#||p' $COCCI`" ] ; then
70 echo 'Semantic patch information:'
71 sed -ne 's|^//#||p' $COCCI
72 echo ''
73 fi
74
Nicolas Palix1e9dea22010-06-13 09:26:34 +020075 $SPATCH -D $MODE $FLAGS -sp_file $COCCI $OPT -dir $srctree || exit 1
76 else
77 $SPATCH -D $MODE $FLAGS -sp_file $COCCI $OPT $OPTIONS || exit 1
78 fi
79
Nicolas Palix74425ee2010-06-06 17:15:01 +020080}
81
82if [ "$COCCI" = "" ] ; then
83 for f in `find $srctree/scripts/coccinelle/ -name '*.cocci' -type f | sort`; do
Nicolas Palix1e9dea22010-06-13 09:26:34 +020084 coccinelle $f
Nicolas Palix74425ee2010-06-06 17:15:01 +020085 done
86else
Nicolas Palix1e9dea22010-06-13 09:26:34 +020087 coccinelle $COCCI
Nicolas Palix74425ee2010-06-06 17:15:01 +020088fi