xref: /illumos-gate/usr/src/tools/smatch/src/smatch_scripts/wine_checker.sh (revision 45ede40b2394db7967e59f19288fae9b62efd4aa)
1#!/bin/bash
2
3function usage {
4    echo "Usage:  $0 [--sparse][--valgrind][--debug] path/to/file.c"
5    exit 1
6}
7
8SCRIPT_DIR=$(dirname $0)
9if [ -e $SCRIPT_DIR/../smatch ] ; then
10    CMD=$SCRIPT_DIR/../smatch
11elif which smatch | grep smatch > /dev/null ; then
12    CMD=smatch
13else
14    echo "Smatch binary not found."
15    exit 1
16fi
17
18POST=""
19WINE_ARGS="-p=wine --full-path -D__i386__"
20
21while 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
42done
43
44cname=$1
45cname=$(echo ${cname/.o/.c})
46if [[ "$cname" == "" ]] ; then
47    usege
48fi
49if ! test -e $cname ; then
50    usege
51fi
52
53oname=$(echo ${cname/.c/.o})
54if ! echo $oname | grep .o$ > /dev/null ; then
55    usege
56fi
57rm -f $oname
58
59cur=$(pwd)
60file_dir=$(dirname $oname)
61o_short_name=$(basename $oname)
62cd $file_dir
63make CC="$PRE $CMD $POST $WINE_ARGS" $o_short_name
64make $o_short_name
65cd $cur
66