Blame sysinfo/version.sh

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