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 FLAGS
="$SPFLAGS -very_quiet"
16 # spatch only allows include directories with the syntax "-I include"
17 # while gcc also allows "-Iinclude" and "-include include"
18 COCCIINCLUDE
=${LINUXINCLUDE//-I/-I }
19 COCCIINCLUDE
=${COCCIINCLUDE//-include/-I}
21 if [ "$C" = "1" -o "$C" = "2" ]; then
24 # Take only the last argument, which is the C file to test
26 OPTIONS
="$COCCIINCLUDE $1"
29 if [ "$KBUILD_EXTMOD" = "" ] ; then
30 OPTIONS
="-dir $srctree $COCCIINCLUDE"
32 OPTIONS
="-dir $KBUILD_EXTMOD $COCCIINCLUDE"
36 if [ "$KBUILD_EXTMOD" != "" ] ; then
37 OPTIONS
="-patch $srctree $OPTIONS"
40 if [ ! -x "$SPATCH" ]; then
41 echo 'spatch is part of the Coccinelle project and is available at http://coccinelle.lip6.fr/'
45 if [ "$MODE" = "" ] ; then
46 if [ "$ONLINE" = "0" ] ; then
47 echo 'You have not explicitly specified the mode to use. Using default "chain" mode.'
48 echo 'All available modes will be tried (in that order): patch, report, context, org'
49 echo 'You can specify the mode with "make coccicheck MODE=<mode>"'
52 elif [ "$MODE" = "report" -o "$MODE" = "org" ] ; then
53 FLAGS
="$FLAGS -no_show_diff"
56 if [ "$ONLINE" = "0" ] ; then
58 echo 'Please check for false positives in the output before submitting a patch.'
59 echo 'When using "patch" mode, carefully review the patch before submitting it.'
64 if [ $VERBOSE -ne 0 ] ; then
74 OPT
=`grep "Option" $COCCI | cut -d':' -f2`
76 # The option '-parse_cocci' can be used to syntactically check the SmPL files.
78 # $SPATCH -D $MODE $FLAGS -parse_cocci $COCCI $OPT > /dev/null
80 if [ $VERBOSE -ne 0 -a $ONLINE -eq 0 ] ; then
82 FILE
=`echo $COCCI | sed "s|$srctree/||"`
84 echo "Processing `basename $COCCI`"
85 echo "with option(s) \"$OPT\""
87 echo 'Message example to submit a patch:'
89 sed -ne 's|^///||p' $COCCI
91 if [ "$MODE" = "patch" ] ; then
92 echo ' The semantic patch that makes this change is available'
93 elif [ "$MODE" = "report" ] ; then
94 echo ' The semantic patch that makes this report is available'
95 elif [ "$MODE" = "context" ] ; then
96 echo ' The semantic patch that spots this code is available'
97 elif [ "$MODE" = "org" ] ; then
98 echo ' The semantic patch that makes this Org report is available'
100 echo ' The semantic patch that makes this output is available'
104 echo ' More information about semantic patching is available at'
105 echo ' http://coccinelle.lip6.fr/'
108 if [ "`sed -ne 's|^//#||p' $COCCI`" ] ; then
109 echo 'Semantic patch information:'
110 sed -ne 's|^//#||p' $COCCI
115 if [ "$MODE" = "chain" ] ; then
116 run_cmd
$SPATCH -D patch \
117 $FLAGS -sp_file $COCCI $OPT $OPTIONS || \
118 run_cmd
$SPATCH -D report \
119 $FLAGS -sp_file $COCCI $OPT $OPTIONS -no_show_diff || \
120 run_cmd
$SPATCH -D context \
121 $FLAGS -sp_file $COCCI $OPT $OPTIONS || \
122 run_cmd
$SPATCH -D org \
123 $FLAGS -sp_file $COCCI $OPT $OPTIONS -no_show_diff ||
exit 1
124 elif [ "$MODE" = "rep+ctxt" ] ; then
125 run_cmd
$SPATCH -D report \
126 $FLAGS -sp_file $COCCI $OPT $OPTIONS -no_show_diff && \
127 run_cmd
$SPATCH -D context \
128 $FLAGS -sp_file $COCCI $OPT $OPTIONS ||
exit 1
130 run_cmd
$SPATCH -D $MODE $FLAGS -sp_file $COCCI $OPT $OPTIONS ||
exit 1
135 if [ "$COCCI" = "" ] ; then
136 for f
in `find $srctree/scripts/coccinelle/ -name '*.cocci' -type f | sort`; do