3 SPATCH="`which ${SPATCH:=spatch}`"
5 # The verbosity may be set by the environmental parameter V=
6 # as for example with 'make V=1 coccicheck'
8 if [ -n "$V" -a "$V" != "0" ]; then
14 if [ "$C" = "1" -o "$C" = "2" ]; then
17 # This requires Coccinelle >= 0.2.3
18 # FLAGS="-ignore_unknown_options -very_quiet"
21 # Workaround for Coccinelle < 0.2.3
22 FLAGS="-I $srctree/include -very_quiet"
28 if [ "$KBUILD_EXTMOD" = "" ] ; then
29 OPTIONS="-dir $srctree"
31 OPTIONS="-dir $KBUILD_EXTMOD -patch $srctree -I $srctree/include -I $KBUILD_EXTMOD/include"
35 if [ ! -x "$SPATCH" ]; then
36 echo 'spatch is part of the Coccinelle project and is available at http://coccinelle.lip6.fr/'
40 if [ "$MODE" = "" ] ; then
41 if [ "$ONLINE" = "0" ] ; then
42 echo 'You have not explicitly specified the mode to use. Using default "chain" mode.'
43 echo 'All available modes will be tried (in that order): patch, report, context, org'
44 echo 'You can specify the mode with "make coccicheck MODE=<mode>"'
47 elif [ "$MODE" = "report" -o "$MODE" = "org" ] ; then
48 FLAGS="$FLAGS -no_show_diff"
51 if [ "$ONLINE" = "0" ] ; then
53 echo 'Please check for false positives in the output before submitting a patch.'
54 echo 'When using "patch" mode, carefully review the patch before submitting it.'
61 OPT=`grep "Option" $COCCI | cut -d':' -f2`
63 # The option '-parse_cocci' can be used to syntactically check the SmPL files.
65 # $SPATCH -D $MODE $FLAGS -parse_cocci $COCCI $OPT > /dev/null
67 if [ $VERBOSE -ne 0 ] ; then
69 FILE=`echo $COCCI | sed "s|$srctree/||"`
71 echo "Processing `basename $COCCI`"
72 echo "with option(s) \"$OPT\""
74 echo 'Message example to submit a patch:'
76 sed -ne 's|^///||p' $COCCI
78 if [ "$MODE" = "patch" ] ; then
79 echo ' The semantic patch that makes this change is available'
80 elif [ "$MODE" = "report" ] ; then
81 echo ' The semantic patch that makes this report is available'
82 elif [ "$MODE" = "context" ] ; then
83 echo ' The semantic patch that spots this code is available'
84 elif [ "$MODE" = "org" ] ; then
85 echo ' The semantic patch that makes this Org report is available'
87 echo ' The semantic patch that makes this output is available'
91 echo ' More information about semantic patching is available at'
92 echo ' http://coccinelle.lip6.fr/'
95 if [ "`sed -ne 's|^//#||p' $COCCI`" ] ; then
96 echo 'Semantic patch information:'
97 sed -ne 's|^//#||p' $COCCI
102 if [ "$MODE" = "chain" ] ; then
103 $SPATCH -D patch $FLAGS -sp_file $COCCI $OPT $OPTIONS || \
104 $SPATCH -D report $FLAGS -sp_file $COCCI $OPT $OPTIONS -no_show_diff || \
105 $SPATCH -D context $FLAGS -sp_file $COCCI $OPT $OPTIONS || \
106 $SPATCH -D org $FLAGS -sp_file $COCCI $OPT $OPTIONS -no_show_diff || exit 1
107 elif [ "$MODE" = "rep+ctxt" ] ; then
108 $SPATCH -D report $FLAGS -sp_file $COCCI $OPT $OPTIONS -no_show_diff && \
109 $SPATCH -D context $FLAGS -sp_file $COCCI $OPT $OPTIONS || exit 1
111 $SPATCH -D $MODE $FLAGS -sp_file $COCCI $OPT $OPTIONS || exit 1
116 if [ "$COCCI" = "" ] ; then
117 for f in `find $srctree/scripts/coccinelle/ -name '*.cocci' -type f | sort`; do