09157951638 / compilers / bcparser

Forked from compilers/bcparser a year ago
Clone

Blame sysinfo/version.sh

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