Blame sofort/version.sh

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