Blame sysinfo/version.sh

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