Blame sysinfo/version.sh

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