#!/bin/bash

if [ -d ".git" ]
then
# If we have a git directory use that as an information source
 VERSION=`git describe --abbrev=0`
 HASH=`git show --format="%h" --no-patch master`
 BRANCH=`git rev-parse --abbrev-ref HEAD`
elif [ "$#" = "3" ]
then
# If we have 3 commandline arguments use them
 VERSION="$1"
 HASH="$2"
 BRANCH="$3"
else
# We don't know our version
 VERSION="Unknown"
 HASH="none"
 BRANCH="Unknown"
fi

echo "#ifndef HAVE_VERSION_H"
echo "#define HAVE_VERSION_H"
echo ""
echo "#define VERSION \"$VERSION\""
echo "#define HASH \"$HASH\""
echo "#define BRANCH \"$BRANCH\""
echo "#define VERSION_FULL VERSION\"-\"HASH\" (\"BRANCH\")\""
echo "char* version();"
echo ""
echo "#endif"