| Nicolas Palix | 74425ee | 2010-06-06 17:15:01 +0200 | [diff] [blame] | 1 | #!/bin/sh | 
 | 2 |  | 
 | 3 | SPATCH="`which ${SPATCH:=spatch}`" | 
 | 4 |  | 
| Nicolas Palix | 1e9dea2 | 2010-06-13 09:26:34 +0200 | [diff] [blame] | 5 | if [ "$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 | 
 | 16 | else | 
 | 17 |     ONLINE=0 | 
 | 18 |     FLAGS="-very_quiet" | 
 | 19 | fi | 
 | 20 |  | 
| Nicolas Palix | 74425ee | 2010-06-06 17:15:01 +0200 | [diff] [blame] | 21 | if [ ! -x "$SPATCH" ]; then | 
 | 22 |     echo 'spatch is part of the Coccinelle project and is available at http://coccinelle.lip6.fr/' | 
 | 23 |     exit 1 | 
 | 24 | fi | 
 | 25 |  | 
 | 26 | if [ "$MODE" = "" ] ; then | 
| Nicolas Palix | 1e9dea2 | 2010-06-13 09:26:34 +0200 | [diff] [blame] | 27 |     if [ "$ONLINE" = "0" ] ; then | 
 | 28 | 	echo 'You have not explicitly specify the mode to use. Fallback to "report".' | 
 | 29 | 	echo 'You can specify the mode with "make coccicheck MODE=<mode>"' | 
 | 30 | 	echo 'Available modes are: report, patch, context, org' | 
 | 31 |     fi | 
| Nicolas Palix | 74425ee | 2010-06-06 17:15:01 +0200 | [diff] [blame] | 32 |     MODE="report" | 
 | 33 | fi | 
 | 34 |  | 
| Nicolas Palix | 1e9dea2 | 2010-06-13 09:26:34 +0200 | [diff] [blame] | 35 | if [ "$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 '' | 
 | 40 | fi | 
| Nicolas Palix | 74425ee | 2010-06-06 17:15:01 +0200 | [diff] [blame] | 41 |  | 
| Nicolas Palix | 1e9dea2 | 2010-06-13 09:26:34 +0200 | [diff] [blame] | 42 | coccinelle () { | 
| Nicolas Palix | 74425ee | 2010-06-06 17:15:01 +0200 | [diff] [blame] | 43 |     COCCI="$1" | 
| Nicolas Palix | 74425ee | 2010-06-06 17:15:01 +0200 | [diff] [blame] | 44 |  | 
 | 45 |     OPT=`grep "Option" $COCCI | cut -d':' -f2` | 
| Nicolas Palix | 74425ee | 2010-06-06 17:15:01 +0200 | [diff] [blame] | 46 |  | 
 | 47 | #   The option '-parse_cocci' can be used to syntaxically check the SmPL files. | 
 | 48 | # | 
| Nicolas Palix | 1e9dea2 | 2010-06-13 09:26:34 +0200 | [diff] [blame] | 49 | #    $SPATCH -D $MODE $FLAGS -parse_cocci $COCCI $OPT > /dev/null | 
| Nicolas Palix | 74425ee | 2010-06-06 17:15:01 +0200 | [diff] [blame] | 50 |  | 
| Nicolas Palix | 1e9dea2 | 2010-06-13 09:26:34 +0200 | [diff] [blame] | 51 |     if [ "$ONLINE" = "0" ] ; then | 
 | 52 |  | 
 | 53 | 	FILE=`echo $COCCI | sed "s|$srctree/||"` | 
 | 54 |  | 
 | 55 | 	echo "Processing `basename $COCCI` with option(s) \"$OPT\"" | 
 | 56 | 	echo 'Message example to submit a patch:' | 
 | 57 |  | 
 | 58 | 	sed -e '/\/\/\//!d' -e 's|^///||' $COCCI | 
 | 59 |  | 
 | 60 | 	echo ' The semantic patch that makes this change is available' | 
 | 61 | 	echo " in $FILE." | 
 | 62 | 	echo '' | 
 | 63 | 	echo ' More information about semantic patching is available at' | 
 | 64 | 	echo ' http://coccinelle.lip6.fr/' | 
 | 65 | 	echo '' | 
 | 66 |  | 
 | 67 | 	$SPATCH -D $MODE $FLAGS -sp_file $COCCI $OPT -dir $srctree || exit 1 | 
 | 68 |     else | 
 | 69 | 	$SPATCH -D $MODE $FLAGS -sp_file $COCCI $OPT $OPTIONS || exit 1 | 
 | 70 |     fi | 
 | 71 |  | 
| Nicolas Palix | 74425ee | 2010-06-06 17:15:01 +0200 | [diff] [blame] | 72 | } | 
 | 73 |  | 
 | 74 | if [ "$COCCI" = "" ] ; then | 
 | 75 |     for f in `find $srctree/scripts/coccinelle/ -name '*.cocci' -type f | sort`; do | 
| Nicolas Palix | 1e9dea2 | 2010-06-13 09:26:34 +0200 | [diff] [blame] | 76 | 	coccinelle $f | 
| Nicolas Palix | 74425ee | 2010-06-06 17:15:01 +0200 | [diff] [blame] | 77 |     done | 
 | 78 | else | 
| Nicolas Palix | 1e9dea2 | 2010-06-13 09:26:34 +0200 | [diff] [blame] | 79 |     coccinelle $COCCI | 
| Nicolas Palix | 74425ee | 2010-06-06 17:15:01 +0200 | [diff] [blame] | 80 | fi |