Blame sysinfo/version.sh

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