Files

55 lines
1.5 KiB
Bash
Raw Permalink Normal View History

2012-04-07 02:06:53 +02:00
#!/bin/sh
2013-05-27 19:55:01 -04:00
if [ $# -gt 1 ]; then
cd "$2"
fi
2012-04-07 02:06:53 +02:00
if [ $# -gt 0 ]; then
FILE="$1"
shift
if [ -f "$FILE" ]; then
INFO="$(head -n 1 "$FILE")"
fi
else
2013-05-27 19:55:01 -04:00
echo "Usage: $0 <filename> <srcroot>"
2012-04-07 02:06:53 +02:00
exit 1
fi
DESC=""
SUFFIX=""
LAST_COMMIT_DATE=""
2014-11-03 11:14:57 +01:00
if [ -e "$(which git 2>/dev/null)" -a "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]; then
2012-04-07 02:06:53 +02:00
# clean 'dirty' status of touched files that haven't been modified
2018-10-30 10:38:50 +01:00
git diff >/dev/null 2>/dev/null
2012-04-07 02:06:53 +02:00
# if latest commit is tagged and not dirty, then override using the tag name
RAWDESC=$(git describe --abbrev=0 2>/dev/null)
if [ "$(git rev-parse HEAD)" = "$(git rev-list -1 $RAWDESC 2>/dev/null)" ]; then
git diff-index --quiet HEAD -- && DESC=$RAWDESC
fi
# otherwise generate suffix from git, i.e. string like "59887e8-dirty"
2018-10-30 10:38:50 +01:00
GIT_COMMIT=$(git rev-parse --short HEAD)
git diff-index --quiet HEAD -- || SUFFIX="$GIT_COMMIT-dirty"
2012-04-07 02:06:53 +02:00
# get a string like "2012-04-10 16:27:19 +0200"
2018-11-03 16:44:12 +01:00
LAST_COMMIT_DATE="$(git log -n 1 --format="%ci" | grep -v gpg)"
2012-04-07 02:06:53 +02:00
fi
if [ -n "$DESC" ]; then
NEWINFO="#define BUILD_DESC \"$DESC\""
elif [ -n "$SUFFIX" ]; then
NEWINFO="#define BUILD_SUFFIX $SUFFIX"
2012-04-07 02:06:53 +02:00
else
NEWINFO="// No build information available"
fi
# only update build.h if necessary
if [ "$INFO" != "$NEWINFO" ]; then
echo "$NEWINFO" >"$FILE"
2018-10-30 10:38:50 +01:00
if [ -n "$GIT_COMMIT" ]; then
echo "#define GIT_COMMIT_ID \"$GIT_COMMIT\"" >> "$FILE"
fi
if [ -n "$LAST_COMMIT_DATE" ]; then
echo "#define BUILD_DATE \"$LAST_COMMIT_DATE\"" >> "$FILE"
fi
2012-04-07 02:06:53 +02:00
fi