comptime.sh 1 KB
Newer Older
1
#!/bin/bash -e
Alam Ed Arias committed
2 3 4 5 6 7
path="."
if [ x"$1" != x ]; then
	path="$1"
fi

versiongit() {
8 9
	gitbranch=`git rev-parse --abbrev-ref HEAD`
	gitversion=`git rev-parse HEAD`
Alam Ed Arias committed
10 11 12
	cat <<EOF > $path/comptime.h

// Do not edit!  This file was autogenerated
13
// by the $0 script with git
Alam Ed Arias committed
14
//
15 16
const char* compbranch = "$gitbranch";
const char* comprevision = "${gitversion:0:8}";
Alam Ed Arias committed
17 18 19 20 21 22 23 24 25 26 27
EOF
exit 0
}

versionsvn() {
	svnrevision=`svnversion -n $1`
	cat <<EOF > $path/comptime.h

// Do not edit!  This file was autogenerated
// by the $0 script with subversion
//
28
const char* compbranch = "Subversion";
Alam Ed Arias committed
29 30 31 32 33 34 35 36 37 38 39
const char* comprevision = "r$svnrevision";
EOF
exit 0
}

versionfake() {
	cat <<EOF > $path/comptime.h

// Do not edit!  This file was autogenerated
// by the $0 script with an unknown or nonexist SCM
//
40
const char* compbranch = "Unknown";
Alam Ed Arias committed
41 42 43 44 45 46 47 48 49 50 51 52 53 54
const char* comprevision = "illegal";
EOF
}

compversion() {
touch $path/comptime.c
versionfake
test -d $path/.svn && versionsvn
test -d $path/../.git && versiongit
exit 1
}

test -f $path/comptime.c && compversion
exit 2