Blame sysinfo/version.sh

5b49a6
#!/bin/sh
5b49a6
5b49a6
usage()
5b49a6
{
5b49a6
cat << EOF >&2
5b49a6
5b49a6
Usage:
5b49a6
  -h            show this HELP message
5b49a6
  -s  SRCDIR    set source directory
5b49a6
  -o  OUTPUT    set output header
5b49a6
  -p  PREFIX    set macro prefix
5b49a6
5b49a6
EOF
5b49a6
exit 1
5b49a6
}
5b49a6
5b49a6
5b49a6
# one
5b49a6
workdir=$(pwd)
5b49a6
srcdir=
5b49a6
output=
5b49a6
prefix=
5b49a6
5b49a6
5b49a6
while getopts "hs:o:p:" opt; do
5b49a6
	case $opt in
5b49a6
	h)
5b49a6
  		usage
5b49a6
  		;;
5b49a6
	s)
5b49a6
    		srcdir="$OPTARG"
5b49a6
    		;;
5b49a6
	o)
5b49a6
    		output="$OPTARG"
5b49a6
    		;;
5b49a6
	p)
5b49a6
    		prefix="$OPTARG"
5b49a6
    		;;
5b49a6
	\?)
5b49a6
    		printf "Invalid option: -%s" "$OPTARG" >&2
5b49a6
    		usage
5b49a6
    		;;
5b49a6
	esac
5b49a6
done
5b49a6
5b49a6
5b49a6
# two
5b49a6
if [ -z "$srcdir" ] || [ -z "$output" ] || [ -z "$prefix" ]; then
5b49a6
	usage
5b49a6
fi
5b49a6
5b49a6
cd "$srcdir" || exit 2
5b49a6
5b49a6
gitver=`git rev-parse --verify HEAD 2>/dev/null` || gitver="unknown"
5b49a6
macro=`echo "$prefix"_GIT_VERSION | tr '[:lower:]' '[:upper:]'`
5b49a6
5b49a6
cd "$workdir" || exit 2
5b49a6
printf "#define $macro\t\"$gitver\"\n" > "$output"
5b49a6
5b49a6
# all done
5b49a6
exit 0