SRB2/comptime.sh
GoldenTails a614865d35 Make comptime.sh conform to POSIX and less redundant, among other improvements
- Shebang now directly calls /bin/sh
- Improved indenting within the comprevision() function
- Quoted several strings to prevent possible argument splitting
- Replaced archaic backtick command statements with more descriptive `"$(...)"` statements
- Replaced direct references to `test` with more readable, but equivalent `[ ... ]` statements
- Replaced the ${str:0:8} bashism with an equivalent statement using POSIX cut
- Moved redundant definitions of the comptime.h body to a single function that takes arguments
2022-04-04 20:02:30 -05:00

44 lines
746 B
Bash
Executable file

#!/bin/sh
path="."
if [ x"$1" != x ]; then
path="$1"
fi
version() {
cat <<EOF > "$path/comptime.h"
// Do not edit! This file was autogenerated
// by the $0 script with git
//
const char* compbranch = "$1";
const char* comprevision = "$2";
EOF
}
versiongit() {
gitbranch="$(git rev-parse --abbrev-ref HEAD)"
gitversion="$(git rev-parse HEAD | cut -c -8)"
version "$gitbranch" "$gitversion";
exit 0
}
versionsvn() {
svnrevision="$(svnversion -n $1)"
version "Subversion" "r$svnrevision";
exit 0
}
versionfake() {
version "Unknown" "illegal";
}
compversion() {
touch "$path/comptime.c"
versionfake
[ -d "$path/.svn" ] && versionsvn
[ -d "$path/../.git" ] && versiongit
exit 1
}
[ -f "$path/comptime.c" ] && compversion
exit 2