4 # This script requires at least spatch
8 SPATCH
="`which ${SPATCH:=spatch}`"
10 trap kill_running SIGTERM SIGINT
13 # The verbosity may be set by the environmental parameter V=
14 # as for example with 'make V=1 coccicheck'
16 if [ -n "$V" -a "$V" != "0" ]; then
23 NPROC
=$
(getconf _NPROCESSORS_ONLN
)
28 FLAGS
="$SPFLAGS --very-quiet"
30 # spatch only allows include directories with the syntax "-I include"
31 # while gcc also allows "-Iinclude" and "-include include"
32 COCCIINCLUDE
=${LINUXINCLUDE//-I/-I }
33 COCCIINCLUDE
=${COCCIINCLUDE// -include/ --include}
35 if [ "$C" = "1" -o "$C" = "2" ]; then
38 # Take only the last argument, which is the C file to test
40 OPTIONS
="$COCCIINCLUDE $1"
43 if [ "$KBUILD_EXTMOD" = "" ] ; then
44 OPTIONS
="--dir $srctree $COCCIINCLUDE"
46 OPTIONS
="--dir $KBUILD_EXTMOD $COCCIINCLUDE"
50 if [ "$KBUILD_EXTMOD" != "" ] ; then
51 OPTIONS
="--patch $srctree $OPTIONS"
54 if [ ! -x "$SPATCH" ]; then
55 echo 'spatch is part of the Coccinelle project and is available at http://coccinelle.lip6.fr/'
59 if [ "$MODE" = "" ] ; then
60 if [ "$ONLINE" = "0" ] ; then
61 echo 'You have not explicitly specified the mode to use. Using default "report" mode.'
62 echo 'Available modes are the following: patch, report, context, org'
63 echo 'You can specify the mode with "make coccicheck MODE=<mode>"'
64 echo 'Note however that some modes are not implemented by some semantic patches.'
69 if [ "$MODE" = "chain" ] ; then
70 if [ "$ONLINE" = "0" ] ; then
71 echo 'You have selected the "chain" mode.'
72 echo 'All available modes will be tried (in that order): patch, report, context, org'
74 elif [ "$MODE" = "report" -o "$MODE" = "org" ] ; then
75 FLAGS
="$FLAGS --no-show-diff"
78 if [ "$ONLINE" = "0" ] ; then
80 echo 'Please check for false positives in the output before submitting a patch.'
81 echo 'When using "patch" mode, carefully review the patch before submitting it.'
87 if [ $VERBOSE -ne 0 ] ; then
88 echo "Running ($NPROC in parallel): $@"
90 for i
in $
(seq 0 $
(( NPROC
- 1)) ); do
91 eval "$@ --max $NPROC --index $i &"
93 if [ $VERBOSE -eq 2 ] ; then
94 echo "${SPATCH_PID[$i]} running"
101 for i
in $
(seq $
(( NPROC
- 1 )) ); do
102 if [ $VERBOSE -eq 2 ] ; then
103 echo "Killing ${SPATCH_PID[$i]}"
105 kill ${SPATCH_PID[$i]} 2>/dev
/null
112 OPT
=`grep "Option" $COCCI | cut -d':' -f2`
114 # The option '--parse-cocci' can be used to syntactically check the SmPL files.
116 # $SPATCH -D $MODE $FLAGS -parse_cocci $COCCI $OPT > /dev/null
118 if [ $VERBOSE -ne 0 -a $ONLINE -eq 0 ] ; then
120 FILE
=`echo $COCCI | sed "s|$srctree/||"`
122 echo "Processing `basename $COCCI`"
123 echo "with option(s) \"$OPT\""
125 echo 'Message example to submit a patch:'
127 sed -ne 's|^///||p' $COCCI
129 if [ "$MODE" = "patch" ] ; then
130 echo ' The semantic patch that makes this change is available'
131 elif [ "$MODE" = "report" ] ; then
132 echo ' The semantic patch that makes this report is available'
133 elif [ "$MODE" = "context" ] ; then
134 echo ' The semantic patch that spots this code is available'
135 elif [ "$MODE" = "org" ] ; then
136 echo ' The semantic patch that makes this Org report is available'
138 echo ' The semantic patch that makes this output is available'
142 echo ' More information about semantic patching is available at'
143 echo ' http://coccinelle.lip6.fr/'
146 if [ "`sed -ne 's|^//#||p' $COCCI`" ] ; then
147 echo 'Semantic patch information:'
148 sed -ne 's|^//#||p' $COCCI
153 if [ "$MODE" = "chain" ] ; then
154 run_cmd
$SPATCH -D patch \
155 $FLAGS --cocci-file $COCCI $OPT $OPTIONS || \
156 run_cmd
$SPATCH -D report \
157 $FLAGS --cocci-file $COCCI $OPT $OPTIONS --no-show-diff || \
158 run_cmd
$SPATCH -D context \
159 $FLAGS --cocci-file $COCCI $OPT $OPTIONS || \
160 run_cmd
$SPATCH -D org \
161 $FLAGS --cocci-file $COCCI $OPT $OPTIONS --no-show-diff ||
exit 1
162 elif [ "$MODE" = "rep+ctxt" ] ; then
163 run_cmd
$SPATCH -D report \
164 $FLAGS --cocci-file $COCCI $OPT $OPTIONS --no-show-diff && \
165 run_cmd
$SPATCH -D context \
166 $FLAGS --cocci-file $COCCI $OPT $OPTIONS ||
exit 1
168 run_cmd
$SPATCH -D $MODE $FLAGS --cocci-file $COCCI $OPT $OPTIONS ||
exit 1
173 if [ "$COCCI" = "" ] ; then
174 for f
in `find $srctree/scripts/coccinelle/ -name '*.cocci' -type f | sort`; do