1 #!/bin/bash
   2 
   3 function usage {
   4     echo "Usage:  $0 [--sparse][--valgrind][--debug] path/to/file.c"
   5     exit 1
   6 }
   7 
   8 SCRIPT_DIR=$(dirname $0)
   9 if [ -e $SCRIPT_DIR/../smatch ] ; then
  10     CMD=$SCRIPT_DIR/../smatch
  11 elif which smatch | grep smatch > /dev/null ; then
  12     CMD=smatch
  13 else
  14     echo "Smatch binary not found."
  15     exit 1
  16 fi
  17     
  18 POST=""
  19 WINE_ARGS="-p=wine --full-path -D__i386__"
  20 
  21 while true ; do
  22     if [[ "$1" == "--sparse" ]] ; then
  23         CMD="sparse"
  24         shift
  25     elif [[ "$1" == "--valgrind" ]] ; then
  26         PRE="valgrind"
  27         shift
  28     elif [[ "$1" == "" ]] ; then
  29         break
  30     else
  31         if [[ "$1" == "--help" ]] ; then
  32                 $CMD --help
  33                 exit 1
  34         fi
  35         if echo $1 | grep -q ^- ; then
  36                 POST="$POST $1"
  37         else
  38                 break
  39         fi
  40         shift
  41     fi
  42 done
  43 
  44 cname=$1
  45 cname=$(echo ${cname/.o/.c})
  46 if [[ "$cname" == "" ]] ; then
  47     usege
  48 fi
  49 if ! test -e $cname ; then
  50     usege
  51 fi
  52 
  53 oname=$(echo ${cname/.c/.o})
  54 if ! echo $oname | grep .o$ > /dev/null ; then
  55     usege
  56 fi
  57 rm -f $oname
  58 
  59 cur=$(pwd)
  60 file_dir=$(dirname $oname)
  61 o_short_name=$(basename $oname)
  62 cd $file_dir
  63 make CC="$PRE $CMD $POST $WINE_ARGS" $o_short_name
  64 make $o_short_name
  65 cd $cur