Blame sysinfo/version.sh

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