3 SPATCH="`which ${SPATCH:=spatch}`"
5 trap kill_running SIGTERM SIGINT
8 # The verbosity may be set by the environmental parameter V=
9 # as for example with 'make V=1 coccicheck'
11 if [ -n "$V" -a "$V" != "0" ]; then
18 NPROC=$(getconf _NPROCESSORS_ONLN)
23 FLAGS="$SPFLAGS -very_quiet"
25 # spatch only allows include directories with the syntax "-I include"
26 # while gcc also allows "-Iinclude" and "-include include"
27 COCCIINCLUDE=${LINUXINCLUDE//-I/-I }
28 COCCIINCLUDE=${COCCIINCLUDE//-include/-I}
30 if [ "$C" = "1" -o "$C" = "2" ]; then
33 # Take only the last argument, which is the C file to test
35 OPTIONS="$COCCIINCLUDE $1"
38 if [ "$KBUILD_EXTMOD" = "" ] ; then
39 OPTIONS="-dir $srctree $COCCIINCLUDE"
41 OPTIONS="-dir $KBUILD_EXTMOD $COCCIINCLUDE"
45 if [ "$KBUILD_EXTMOD" != "" ] ; then
46 OPTIONS="-patch $srctree $OPTIONS"
49 if [ ! -x "$SPATCH" ]; then
50 echo 'spatch is part of the Coccinelle project and is available at http://coccinelle.lip6.fr/'
54 if [ "$MODE" = "" ] ; then
55 if [ "$ONLINE" = "0" ] ; then
56 echo 'You have not explicitly specified the mode to use. Using default "report" mode.'
57 echo 'Available modes are the following: patch, report, context, org'
58 echo 'You can specify the mode with "make coccicheck MODE=<mode>"'
59 echo 'Note however that some modes are not implemented by some semantic patches.'
64 if [ "$MODE" = "chain" ] ; then
65 if [ "$ONLINE" = "0" ] ; then
66 echo 'You have selected the "chain" mode.'
67 echo 'All available modes will be tried (in that order): patch, report, context, org'
69 elif [ "$MODE" = "report" -o "$MODE" = "org" ] ; then
70 FLAGS="$FLAGS -no_show_diff"
73 if [ "$ONLINE" = "0" ] ; then
75 echo 'Please check for false positives in the output before submitting a patch.'
76 echo 'When using "patch" mode, carefully review the patch before submitting it.'
82 if [ $VERBOSE -ne 0 ] ; then
83 echo "Running ($NPROC in parallel): $@"
85 for i in $(seq 0 $(( NPROC - 1)) ); do
86 eval "$@ -max $NPROC -index $i &"
88 if [ $VERBOSE -eq 2 ] ; then
89 echo "${SPATCH_PID[$i]} running"
96 for i in $(seq $(( NPROC - 1 )) ); do
97 if [ $VERBOSE -eq 2 ] ; then
98 echo "Killing ${SPATCH_PID[$i]}"
100 kill ${SPATCH_PID[$i]} 2>/dev/null
107 OPT=`grep "Option" $COCCI | cut -d':' -f2`
109 # The option '-parse_cocci' can be used to syntactically check the SmPL files.
111 # $SPATCH -D $MODE $FLAGS -parse_cocci $COCCI $OPT > /dev/null
113 if [ $VERBOSE -ne 0 -a $ONLINE -eq 0 ] ; then
115 FILE=`echo $COCCI | sed "s|$srctree/||"`
117 echo "Processing `basename $COCCI`"
118 echo "with option(s) \"$OPT\""
120 echo 'Message example to submit a patch:'
122 sed -ne 's|^///||p' $COCCI
124 if [ "$MODE" = "patch" ] ; then
125 echo ' The semantic patch that makes this change is available'
126 elif [ "$MODE" = "report" ] ; then
127 echo ' The semantic patch that makes this report is available'
128 elif [ "$MODE" = "context" ] ; then
129 echo ' The semantic patch that spots this code is available'
130 elif [ "$MODE" = "org" ] ; then
131 echo ' The semantic patch that makes this Org report is available'
133 echo ' The semantic patch that makes this output is available'
137 echo ' More information about semantic patching is available at'
138 echo ' http://coccinelle.lip6.fr/'
141 if [ "`sed -ne 's|^//#||p' $COCCI`" ] ; then
142 echo 'Semantic patch information:'
143 sed -ne 's|^//#||p' $COCCI
148 if [ "$MODE" = "chain" ] ; then
149 run_cmd $SPATCH -D patch \
150 $FLAGS -sp_file $COCCI $OPT $OPTIONS || \
151 run_cmd $SPATCH -D report \
152 $FLAGS -sp_file $COCCI $OPT $OPTIONS -no_show_diff || \
153 run_cmd $SPATCH -D context \
154 $FLAGS -sp_file $COCCI $OPT $OPTIONS || \
155 run_cmd $SPATCH -D org \
156 $FLAGS -sp_file $COCCI $OPT $OPTIONS -no_show_diff || exit 1
157 elif [ "$MODE" = "rep+ctxt" ] ; then
158 run_cmd $SPATCH -D report \
159 $FLAGS -sp_file $COCCI $OPT $OPTIONS -no_show_diff && \
160 run_cmd $SPATCH -D context \
161 $FLAGS -sp_file $COCCI $OPT $OPTIONS || exit 1
163 run_cmd $SPATCH -D $MODE $FLAGS -sp_file $COCCI $OPT $OPTIONS || exit 1
168 if [ "$COCCI" = "" ] ; then
169 for f in `find $srctree/scripts/coccinelle/ -name '*.cocci' -type f | sort`; do