#!/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
export version
perl -pi -e 's/(AC_INIT[(]\[\S+\],) \[[0-9.]+\]/\1 [$ENV{version}]/' configure.ac
perl -pi -e 's/(VERSION) [0-9,]+/\1 $ENV{version}/' win32-version.rc
perl -pi -e "s/<(!ENTITY version) '[0-9.]+'>/<\1 '\$ENV{version}'>/" doc/*.xml
perl -pi -e 's/(Project-Id-Version: \S+) [0-9.]+/\1 $ENV{version}/' $po_files $doc_po_files
perl -pi -e '/^#[.] type: Content of the version entity/ and $t = 1; $t and s/^(msg(id|str)) ".*"/\1 "$ENV{version}"/; /^$/ and $t = 0; ' $doc_po_files
