#!/bin/sh

set -e
set -u

myself=`echo "$0" | sed 's,.*/,,'`

say()
{
	echo "$myself: $@."
}

die()
{
	echo >&2 "$myself: $@."
	exit 1
}

general_args='--analyze'
include_args='
    -I.
    -Ilib
    -Ilib/ev
    -Ilib/pidfile
    -Isrc/common
    -I/usr/local/include
    -I/usr/pkg/include'
definition_args='
    -DHAVE_CONFIG_H
    -DNSCA_VERSION=PACKAGE_VERSION
    -DSYSCONFDIR="/foo"
    -DLOCALSTATEDIR="/bar"'

test -f 'lib/system.h' \
    || die 'Please call me from the NSCA-ng source directory'
test -f 'config.h' \
    || die "Please run ./configure before calling $0"

files=`find 'src' -type 'f' -name '*.c' -print`

echo "Letting Clang analyze the following list of files:"
echo
echo "$files"
echo

exec clang $general_args $include_args $definition_args $files
