Blame sysinfo/version.sh

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