orbea / zippy / sofort

Forked from zippy/sofort 2 years ago
Clone

Blame sysinfo/version.sh

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