#!/bin/sh
# vim: expandtab sw=4 ts=4 sts=4:

if [ -z "$1" ] ; then
    echo "Usage: set-version VERSION"
    exit 1
fi

version=$1
version_win=`echo $1| tr . , `,0

do_replace() {
    sed "s/@VERSION@/$version/; s/@VERSION_WIN@/$version_win/" < $1 > $2
}

echo "Setting version to $version"

# Packaging
do_replace packaging/rpm/gammu.spec.in gammu.spec
do_replace packaging/slackware/description-pak.in description-pak

# Windows build
do_replace win32/dll/msvc06.mak/gammu.rc.in win32/dll/msvc06.mak/gammu.rc
do_replace win32/dll/msvc2003.mak/gammu.rc.in win32/dll/msvc2003.mak/gammu.rc
do_replace win32/gammu-binary/bcc06.mak/gammu.bpr.in win32/gammu-binary/bcc06.mak/gammu.bpr
do_replace win32/gammu-binary/msvc06.mak/gammu.rc.in win32/gammu-binary/msvc06.mak/gammu.rc
do_replace win32/gammu-binary/msvc2003.mak/gammu.rc.in win32/gammu-binary/msvc2003.mak/gammu.rc

# CMakeLists.txt
sed -i "s/set (VERSION \"[^\"]*\"\\(.*\\))/set (VERSION \"$version\"\1)/; s/set (VERSION_WIN \"[^\"]*\"\\(.*\\))/set (VERSION_WIN \"$version_win\"\1)/;" CMakeLists.txt

# Update ChangeLog
if ! grep -q " - $version" ChangeLog ; then
    sed -i -e '/^=========$/ a\
    ' -e '/^=========$/ a\
2008???? - '"$version"'
    ' ChangeLog
fi
