1#!/bin/sh
2
3extract_svn_version()
4{
5    if [ -d "$1"/.svn ]
6    then
7        svnversion -n "$1"
8    elif [ -d "$1"/.git/svn ]
9    then
10        cd "$1" || exit 1
11        git svn info . | grep '^Revision' | cut -d ' ' -f2 | tr -d '\n'
12    else
13        echo "unknown"
14    fi
15}
16
17srcdir="${1:-.}"
18
19if [ -e "$srcdir"/include/vgversion_dist.h ]
20then
21    cp "$srcdir"/include/vgversion_dist.h include/vgversion.h.tmp
22else
23    cat > include/vgversion.h.tmp <<EOF
24/* Do not edit: file generated by auxprogs/make_or_upd_vgversion_h.
25   This file defines VGSVN and VEXSVN, used to report SVN revision
26   when using command line options:  -v --version 
27*/
28#define VGSVN "$(extract_svn_version "$srcdir/.")"
29#define VEXSVN "$(extract_svn_version "$srcdir/VEX")"
30EOF
31fi
32
33if [ -f include/vgversion.h ]
34then
35    # There is already a vgversion.h.
36    # Update it only if we found a different and real svn version
37    if grep -q unknown include/vgversion.h.tmp ||
38       cmp -s include/vgversion.h include/vgversion.h.tmp
39    then
40        rm -f include/vgversion.h.tmp
41    else
42        mv include/vgversion.h.tmp include/vgversion.h
43    fi
44else
45    # There is no vgversion.h. Use the one just generated, whatever it is.
46    mv include/vgversion.h.tmp include/vgversion.h
47fi
48