Reicher82 / python / sbpython3

Forked from python/sbpython3 3 years ago
Clone

Blame sofort/tools/version.sh

5dc983
#!/bin/sh
5dc983
7415ae
# version.sh: detect git repository info, output defs as a C header.
7415ae
# this file is covered by COPYING.SOFORT.
7415ae
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
8119b5
workdir=$(pwd -P)
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
	\?)
7215ad
		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
15136c
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
15136c
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