Blame sysinfo/version.sh

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