Merge #9867: Replace remaining sprintf with snprintf
[bitcoinplatinum.git] / share / genbuild.sh
blobeecac4bd00b920327a61ce8167e785c57e0aecd3
1 #!/bin/sh
2 # Copyright (c) 2012-2016 The Bitcoin Core developers
3 # Distributed under the MIT software license, see the accompanying
4 # file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 if [ $# -gt 1 ]; then
7 cd "$2"
8 fi
9 if [ $# -gt 0 ]; then
10 FILE="$1"
11 shift
12 if [ -f "$FILE" ]; then
13 INFO="$(head -n 1 "$FILE")"
15 else
16 echo "Usage: $0 <filename> <srcroot>"
17 exit 1
20 DESC=""
21 SUFFIX=""
22 if [ -e "$(which git 2>/dev/null)" -a "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]; then
23 # clean 'dirty' status of touched files that haven't been modified
24 git diff >/dev/null 2>/dev/null
26 # if latest commit is tagged and not dirty, then override using the tag name
27 RAWDESC=$(git describe --abbrev=0 2>/dev/null)
28 if [ "$(git rev-parse HEAD)" = "$(git rev-list -1 $RAWDESC 2>/dev/null)" ]; then
29 git diff-index --quiet HEAD -- && DESC=$RAWDESC
32 # otherwise generate suffix from git, i.e. string like "59887e8-dirty"
33 SUFFIX=$(git rev-parse --short HEAD)
34 git diff-index --quiet HEAD -- || SUFFIX="$SUFFIX-dirty"
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"
45 # only update build.h if necessary
46 if [ "$INFO" != "$NEWINFO" ]; then
47 echo "$NEWINFO" >"$FILE"