File: gitversion.sh.in

package info (click to toggle)
repsnapper 2.5a5-3
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye
  • size: 5,452 kB
  • sloc: cpp: 61,683; ansic: 7,084; perl: 692; xml: 396; makefile: 348; sh: 231
file content (52 lines) | stat: -rwxr-xr-x 1,390 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/sh

if [ "$#" -lt 2 ]; then
  echo "Usage: $0 <output_file.h> <tarball_file.h>"
  exit 1
fi

VERSION_H="$1"
TARBALL_VERSION_H="$2"
TOPSRCDIR=`dirname "${TARBALL_VERSION_H}"`/..

# Check if building from git
if [ ! -d "${TOPSRCDIR}/.git" ]; then
    # Not git, just ensure output file exists
    if [ ! -f "${TARBALL_VERSION_H}" ]; then
        echo "Warning: Not building from git and ${TARBALL_VERSION_H} doesn't exist"
        echo const string GIT_COMMIT=\"Unknown\"\;     > $VERSION_H
        echo const string GIT_COMMIT_DATE=\"Unknown\"\; >> $VERSION_H
    # else
        # echo "Not updating ${VERSION_H} - building from tarball"
    fi
    exit 0
fi

AWK=@AWK@

FSEQUAL="="
# test for BSD awk which needs a blackslash:
FSERROR=$(${AWK} -v FS== '' 2>&1)
if [ "X$FSERROR" != "X" ] ; then
    FSEQUAL="\="
fi

GIT_DIR="${TOPSRCDIR}/.git"
export GIT_DIR
LOG=`git log -1`

COMMIT=`echo "$LOG" | $AWK '/commit/{print $2; exit}'`
DATE=`  echo "$LOG" | $AWK -v FS="Date:   " '/Date:/{print $2; exit}'`

OLDCOMMIT=""
if [ -e $VERSION_H ]; then
    OLDCOMMIT=`$AWK -v FS="$FSEQUAL" '/const string GIT_COMMIT=/{print $2}' $VERSION_H`
fi

if [ "x\"$COMMIT\";" != "x$OLDCOMMIT" ]; then
    # echo "Updating commit"
    echo const string GIT_COMMIT=\"$COMMIT\"\;     > $VERSION_H
    echo const string GIT_COMMIT_DATE=\"$DATE\"\; >> $VERSION_H
#else
    # echo "Commit has not changed"
fi