]> Git Repo - VerusCoin.git/blob - share/genbuild.sh
Merge #4964 from
[VerusCoin.git] / share / genbuild.sh
1 #!/bin/sh
2 if [ $# -gt 1 ]; then
3     cd "$2"
4 fi
5 if [ $# -gt 0 ]; then
6     FILE="$1"
7     shift
8     if [ -f "$FILE" ]; then
9         INFO="$(head -n 1 "$FILE")"
10     fi
11 else
12     echo "Usage: $0 <filename> <srcroot>"
13     exit 1
14 fi
15
16 DESC=""
17 SUFFIX=""
18 LAST_COMMIT_DATE=""
19 if [ -e "$(which git 2>/dev/null)" -a "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]; then
20     # clean 'dirty' status of touched files that haven't been modified
21     git diff >/dev/null 2>/dev/null 
22
23     # if latest commit is tagged and not dirty, then override using the tag name
24     RAWDESC=$(git describe --abbrev=0 2>/dev/null)
25     if [ "$(git rev-parse HEAD)" = "$(git rev-list -1 $RAWDESC)" ]; then
26         git diff-index --quiet HEAD -- && DESC=$RAWDESC
27     fi
28
29     # otherwise generate suffix from git, i.e. string like "59887e8-dirty"
30     SUFFIX=$(git rev-parse --short HEAD)
31     git diff-index --quiet HEAD -- || SUFFIX="$SUFFIX-dirty"
32
33     # get a string like "2012-04-10 16:27:19 +0200"
34     LAST_COMMIT_DATE="$(git log -n 1 --format="%ci")"
35 fi
36
37 if [ -n "$DESC" ]; then
38     NEWINFO="#define BUILD_DESC \"$DESC\""
39 elif [ -n "$SUFFIX" ]; then
40     NEWINFO="#define BUILD_SUFFIX $SUFFIX"
41 else
42     NEWINFO="// No build information available"
43 fi
44
45 # only update build.h if necessary
46 if [ "$INFO" != "$NEWINFO" ]; then
47     echo "$NEWINFO" >"$FILE"
48     if [ -n "$LAST_COMMIT_DATE" ]; then
49         echo "#define BUILD_DATE \"$LAST_COMMIT_DATE\"" >> "$FILE"
50     fi
51 fi
This page took 0.026492 seconds and 4 git commands to generate.