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
7aa9df
gitver=$(git rev-parse --verify HEAD      2>/dev/null) || gitver="unknown"
7aa9df
cvdate=$(git show -s --format=%ci $gitver 2>/dev/null) || cvdate=$(date)
f46039
01e609
vmacro=$(printf '%s' "$prefix"'_GIT_VERSION' | tr '[:lower:]' '[:upper:]')
01e609
dmacro=$(printf '%s' "$prefix"'_GIT_DATE   ' | tr '[:lower:]' '[:upper:]')
01e609
cda2fb
cd "$workdir"
01e609
feb924
feb924
# three
01e609
printf '#define %s "%s"\n#define %s "%s"\n' \
01e609
		"$vmacro" "$gitver" \
01e609
		"$dmacro" "$cvdate" \
01e609
	> "$output"
f46039
f46039
# all done
f46039
exit 0