2 # Copyright (c) 2016-2019 The Zcash developers
3 # Copyright (c) 2012-2019 The Bitcoin Core developers
4 # Copyright (c) 2012-2019 Bitcoin Developers
5 # Distributed under the MIT software license, see the accompanying
6 # file COPYING or https://www.opensource.org/licenses/mit-license.php .
14 if [ -f "$FILE" ]; then
15 INFO="$(head -n 1 "$FILE")"
18 echo "Usage: $0 <filename> <srcroot>"
25 if [ -e "$(which git 2>/dev/null)" -a "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]; then
26 # clean 'dirty' status of touched files that haven't been modified
27 git diff >/dev/null 2>/dev/null
29 # if latest commit is tagged and not dirty, then override using the tag name
30 RAWDESC=$(git describe --abbrev=0 2>/dev/null)
31 if [ "$(git rev-parse HEAD)" = "$(git rev-list -1 $RAWDESC 2>/dev/null)" ]; then
32 git diff-index --quiet HEAD -- && DESC=$RAWDESC
35 # otherwise generate suffix from git, i.e. string like "59887e8-dirty"
36 SUFFIX=$(git rev-parse --short HEAD)
37 git diff-index --quiet HEAD -- || SUFFIX="$SUFFIX-dirty"
39 # get a string like "2012-04-10 16:27:19 +0200"
40 LAST_COMMIT_DATE="$(git log -n 1 --format="%ci")"
43 if [ -n "$DESC" ]; then
44 NEWINFO="#define BUILD_DESC \"$DESC\""
45 elif [ -n "$SUFFIX" ]; then
46 NEWINFO="#define BUILD_SUFFIX $SUFFIX"
48 NEWINFO="// No build information available"
51 # only update build.h if necessary
52 if [ "$INFO" != "$NEWINFO" ]; then
53 echo "$NEWINFO" >"$FILE"
54 if [ -n "$LAST_COMMIT_DATE" ]; then
55 echo "#define BUILD_DATE \"$LAST_COMMIT_DATE\"" >> "$FILE"