[depends] ccache 3.3.1
[bitcoinplatinum.git] / share / genbuild.sh
blob1ef77d706f7aa35316bf498326b6c9ac09d27bf4
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")"
11 else
12 echo "Usage: $0 <filename> <srcroot>"
13 exit 1
16 DESC=""
17 SUFFIX=""
18 if [ -e "$(which git 2>/dev/null)" -a "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]; then
19 # clean 'dirty' status of touched files that haven't been modified
20 git diff >/dev/null 2>/dev/null
22 # if latest commit is tagged and not dirty, then override using the tag name
23 RAWDESC=$(git describe --abbrev=0 2>/dev/null)
24 if [ "$(git rev-parse HEAD)" = "$(git rev-list -1 $RAWDESC 2>/dev/null)" ]; then
25 git diff-index --quiet HEAD -- && DESC=$RAWDESC
28 # otherwise generate suffix from git, i.e. string like "59887e8-dirty"
29 SUFFIX=$(git rev-parse --short HEAD)
30 git diff-index --quiet HEAD -- || SUFFIX="$SUFFIX-dirty"
33 if [ -n "$DESC" ]; then
34 NEWINFO="#define BUILD_DESC \"$DESC\""
35 elif [ -n "$SUFFIX" ]; then
36 NEWINFO="#define BUILD_SUFFIX $SUFFIX"
37 else
38 NEWINFO="// No build information available"
41 # only update build.h if necessary
42 if [ "$INFO" != "$NEWINFO" ]; then
43 echo "$NEWINFO" >"$FILE"