8 if [ -f "$FILE" ]; then
9 INFO="$(head -n 1 "$FILE")"
12 echo "Usage: $0 <filename> <srcroot>"
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
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
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"
33 # get a string like "2012-04-10 16:27:19 +0200"
34 LAST_COMMIT_DATE="$(git log -n 1 --format="%ci")"
37 if [ -n "$DESC" ]; then
38 NEWINFO="#define BUILD_DESC \"$DESC\""
39 elif [ -n "$SUFFIX" ]; then
40 NEWINFO="#define BUILD_SUFFIX $SUFFIX"
42 NEWINFO="// No build information available"
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"