File indexing completed on 2024-04-21 16:31:39

0001 #!/usr/bin/env bash
0002 
0003 # call with
0004 # $ gen-version.sh <output file> <orig version> <git executable>
0005 
0006 OUTPUT=$1
0007 ORIG_VERSION=$2
0008 GIT=$3
0009 
0010 print_file() {
0011     cat <<EOF
0012 #include <qtcurve-utils/utils.h>
0013 QTC_EXPORT const char*
0014 qtcVersion()
0015 {
0016     return "$1";
0017 }
0018 EOF
0019 }
0020 
0021 if [[ -z $GIT ]]; then
0022     GIT=$(which git 2> /dev/null)
0023 fi
0024 
0025 VERSION=$("$GIT" describe 2> /dev/null)
0026 
0027 if [[ -z $VERSION ]]; then
0028     VERSION=$ORIG_VERSION
0029 else
0030     echo "QTCURVE_VERSION_FULL=${VERSION}"
0031 fi
0032 
0033 print_file "$VERSION" > "$OUTPUT".$$
0034 
0035 if [[ -f "$OUTPUT" ]] && diff -q "$OUTPUT" "$OUTPUT".$$ > /dev/null; then
0036     rm "$OUTPUT".$$
0037 else
0038     mv "$OUTPUT".$$ "$OUTPUT"
0039 fi