orbea / cross / slibtool

Forked from cross/slibtool 3 years ago
Clone

Blame sysinfo/version.sh

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