File indexing completed on 2024-04-28 05:10:38

0001 #!/bin/sh
0002 ##########################################################################
0003 ##                                                                      ##
0004 ##  This script is part of Akonadi Client.                              ##
0005 ##                                                                      ##
0006 ##  This file may be distributed and/or modified under the terms of     ##
0007 ##  the GNU General Public License version 2 or any later version,      ##
0008 ##  as published by the Free Software Foundation and appearing in       ##
0009 ##  the file COPYING included in the packaging of this file.            ##
0010 ##                                                                      ##
0011 ##  Author:  Jonathan Marten <jjm AT keelhaul DOT me DOT uk>            ##
0012 ##                                                                      ##
0013 ##########################################################################
0014 
0015 SRC=$1                                                  # CMAKE_CURRENT_SOURCE_DIR
0016 BIN=$2                                                  # CMAKE_CURRENT_BINARY_DIR
0017 VER=$3                                                  # base application version
0018 
0019 VCSTYPE=                                                # VCS type detected
0020 VCSREV=                                                 # VCS revision
0021 
0022 if [ -d "$SRC/.svn" ]                                   # is source under SVN?
0023 then
0024         VCSTYPE="SVN"
0025         VCSREV=`svn info $SRC 2>/dev/null | sed -n -e'/^Revision:/ { s/^[^:]*: *//;p;q }'`
0026         echo "Current $VCSTYPE revision: ${VCSREV:-unknown}"
0027 else                                                    # source not under SVN
0028         if [ -d "$SRC/.git" ]                           # try for GIT instead
0029         then
0030                 VCSTYPE="GIT"
0031                 VCSREV=`cd $SRC && git describe 2>/dev/null`
0032                                                         # formatted version
0033                 if [ ! -n "$VCSREV" ]                   # if not available then
0034                 then                                    # hash of last commit
0035                         VCSREV=`cd $SRC && git log -1 --abbrev-commit | sed -e 's/commit  *//;q'`
0036                 fi
0037                 echo "Current $VCSTYPE revision: ${VCSREV:-unknown}"
0038         fi
0039 fi
0040 
0041 
0042 TMPFILE="$BIN/version.h.tmp"                            # temporary header file
0043 {
0044         echo "#ifndef VERSION"
0045         echo "#define VERSION              \"${VER}\""
0046         echo "#endif"
0047         echo
0048         echo "#define VCS_REVISION_STRING  \"${VCSREV}\""
0049         echo "#define VCS_TYPE_STRING      \"${VCSTYPE}\""
0050         if [ -n "$VCSREV" ]
0051         then
0052                 echo "#define VCS_HAVE_VERSION     1"
0053         fi
0054         echo
0055 } >$TMPFILE
0056 
0057 
0058 OUTFILE="$BIN/version.h"                                # the real header file
0059 if [ ! -f $OUTFILE ]                                    # does not exist yet
0060 then
0061         echo "Creating $OUTFILE..."
0062 else                                                    # already exists
0063         if cmp -s $TMPFILE $OUTFILE                     # is it still current?
0064         then
0065                 rm $TMPFILE                             # yes, nothing to do
0066                 exit 0
0067         else
0068                 echo "Updating $OUTFILE..."
0069         fi
0070 fi
0071 mv $TMPFILE $OUTFILE                                    # update the header file
0072 exit 0                                                  # successfully updated