Blame sysinfo/version.sh

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