Blame sofort/tools/version.sh

0efa8c
#!/bin/sh
0efa8c
0f42ff
set -eu
0f42ff
0efa8c
usage()
0efa8c
{
0efa8c
cat << EOF >&2
0efa8c
0efa8c
Usage:
0efa8c
  -h            show this HELP message
0efa8c
  -s  SRCDIR    set source directory
0efa8c
  -o  OUTPUT    set output header
0efa8c
  -p  PREFIX    set macro prefix
0efa8c
0efa8c
EOF
0efa8c
exit 1
0efa8c
}
0efa8c
0efa8c
0efa8c
# one
565fd4
workdir=$(pwd -P)
0efa8c
srcdir=
0efa8c
output=
0efa8c
prefix=
0efa8c
0efa8c
0efa8c
while getopts "hs:o:p:" opt; do
0efa8c
	case $opt in
0efa8c
	h)
0efa8c
  		usage
0efa8c
  		;;
0efa8c
	s)
0efa8c
    		srcdir="$OPTARG"
0efa8c
    		;;
0efa8c
	o)
0efa8c
    		output="$OPTARG"
0efa8c
    		;;
0efa8c
	p)
0efa8c
    		prefix="$OPTARG"
0efa8c
    		;;
0efa8c
	\?)
0efa8c
    		printf "Invalid option: -%s" "$OPTARG" >&2
0efa8c
    		usage
0efa8c
    		;;
0efa8c
	esac
0efa8c
done
0efa8c
0efa8c
0efa8c
# two
0efa8c
if [ -z "$srcdir" ] || [ -z "$output" ] || [ -z "$prefix" ]; then
0efa8c
	usage
0efa8c
fi
0efa8c
0f42ff
cd "$srcdir"
0efa8c
9eccdb
gitver=$(git rev-parse --verify HEAD      2>/dev/null) || gitver="unknown"
9eccdb
cvdate=$(git show -s --format=%ci $gitver 2>/dev/null) || cvdate=$(date)
0efa8c
c5ed63
vmacro=$(printf '%s' "$prefix"'_GIT_VERSION' | tr '[:lower:]' '[:upper:]')
c5ed63
dmacro=$(printf '%s' "$prefix"'_GIT_DATE   ' | tr '[:lower:]' '[:upper:]')
c5ed63
0f42ff
cd "$workdir"
c5ed63
1e3213
1e3213
# three
c5ed63
printf '#define %s "%s"\n#define %s "%s"\n' \
c5ed63
		"$vmacro" "$gitver" \
c5ed63
		"$dmacro" "$cvdate" \
c5ed63
	> "$output"
0efa8c
0efa8c
# all done
0efa8c
exit 0