Blame sysinfo/version.sh

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