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