-
Notifications
You must be signed in to change notification settings - Fork 5
/
makeversion
executable file
·35 lines (29 loc) · 1.07 KB
/
makeversion
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/sh
# this script creates version.cpp containing version and other compile-time
# information. it expects to get the source directory as only argument.
output=src/version.cpp
src=$1
test "$src" = '' && src=.
date=`date --utc +%Y-%m-%d`
if test -e "$src/.git"; then
commit=`( cd "$src"; git rev-parse HEAD 2> /dev/null; )`
version=`( cd "$src"; git describe --tags HEAD 2> /dev/null; ) || echo "$commit"`
if test "$commit" != ''; then
( cd "$src"; git diff --quiet HEAD; ) || { commit="$commit (dirty)"; version="$version (dirty)"; }
fi
fi
test -z "$commit" -a -e "$src/gitcommit" && commit=`cat "$src/gitcommit"`
test -z "$version" -a -e "$src/version" && version=`cat "$src/version"`
test -z "$commit" && commit=unknown
test -z "$version" && version=unknown
cat > "$output-new" <<EOF
#include "common.h"
const char *const recorderCommit = "$commit";
const char *const recorderDate = "$date";
const char *const recorderVersion = "$version";
EOF
if test -e "$output" && diff -q "$output" "$output-new" > /dev/null 2>&1; then
rm "$output-new"
else
mv -f "$output-new" "$output"
fi