Reicher82 / python / sbpython3

Forked from python/sbpython3 3 years ago
Clone

Blame sofort/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
e71772
gitver=$(git rev-parse --verify HEAD      2>/dev/null) || gitver="unknown"
e71772
cvdate=$(git show -s --format=%ci $gitver 2>/dev/null) || cvdate=$(date)
5dc983
b2e22c
vmacro=$(printf '%s' "$prefix"'_GIT_VERSION' | tr '[:lower:]' '[:upper:]')
b2e22c
dmacro=$(printf '%s' "$prefix"'_GIT_DATE   ' | tr '[:lower:]' '[:upper:]')
b2e22c
9c70b6
cd "$workdir"
b2e22c
5196e0
5196e0
# three
b2e22c
printf '#define %s "%s"\n#define %s "%s"\n' \
b2e22c
		"$vmacro" "$gitver" \
b2e22c
		"$dmacro" "$cvdate" \
b2e22c
	> "$output"
5dc983
5dc983
# all done
5dc983
exit 0