#!/bin/sh

# Copyright © 2009-2017 Jakub Wilk <jwilk@jwilk.net>
#
# This file is part of pdf2djvu.
#
# pdf2djvu is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# pdf2djvu is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.

set -e -u
version=${1:?"no version number provided"}
windows_version="$(printf -- '%s' "$version" | sed -e 's/[.]/,/g')"
po_files=$(ls po/*.po po/*.pot 2>/dev/null || true)
doc_po_files=$(ls doc/po/*.po doc/po/*.pot 2>/dev/null || true)
PS4='$ '
set -x
dch -m -v "$version" -u low -c doc/changelog
sed -i -E -e "s/(AC_INIT[(]\[\S+\],) \[[0-9.]+\]/\1 [$version]/" configure.ac
sed -i -E -e "s/(VERSION) [0-9,]+/\1 $windows_version/" win32-version.rc
sed -i -E -e "s/<(!ENTITY version) '[0-9.]+'>/<\1 '$version'>/" doc/*.xml
sed -i -E -e 's/(Project-Id-Version: \S+) [0-9.]+/\1 '"$version"'/' $po_files $doc_po_files
sed -i -E -e '/#[.] type: Content of the version entity/,/^$/ { s/(msg(id|str)) ".*"/\1 "'"$version"'"/; }' $doc_po_files
