#   ---------------------------------------------------------------------- copyright and license ---
#
#   file: rpm/locale-en_RU.spec.in
#
#   Copyright © 2013—2014, 2016—2021 Van de Bugger.
#
#   This file is a part of Locale en_RU.
#
#   Locale en_RU is free software: you can redistribute it and/or modify it under the terms of the
#   GNU General Public License as published by the Free Software Foundation, either version 3 of
#   the License, or (at your option) any later version.
#
#   Locale en_RU 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.
#
#   You should have received a copy of the GNU General Public License along with Locale en_RU. If
#   not, see <http://www.gnu.org/licenses/>.
#
#   SPDX-License-Identifier: GPL-3.0-or-later
#
#   ---------------------------------------------------------------------- copyright and license ---

#   In OpenSuse documentation files are expected to be in `/usr/share/doc/packages/${name}`, while
#   `make` by default installs documents to `/usr/share/doc/${name}`. `rpmbuild` fails because it
#   can't find files it expected location.
#
#   I would expect OpenSuse's `$configure` macro passes `--docdir` option to `configure` command,
#   bit it does not. Let's fix it:
#
%if 0%{?suse_version}
    %global configure %{configure} --docdir=%{_docdir}/%{name}
%endif

%global _localedef   %{_bindir}/localedef
%global _make        %{_bindir}/make
%global _perl        %{_bindir}/perl
%global _i18ndir     %{_datadir}/i18n
%global _charmapsdir %{_i18ndir}/charmaps
%global _localesdir  %{_i18ndir}/locales

%global _archive     %{_prefix}/lib/locale/locale-archive
%global _template    %{_archive}.tmpl

Name:          locale-en_RU
Version:       0.5.5
Release:       0.vdb.4
Summary:       English language for Russia
Group:         System Environment/Base
License:       GPLv3+
URL:           https://en-ru.sourceforge.io/
Source0:       https://sourceforge.net/projects/en-ru/files/0.5.5/%{name}-%{version}.tar.gz
BuildArch:     noarch

# Build requires Perl 5.14:
%global perl_version 5.14.0
%if 0%{?fedora} || 0%{?rhel}
    # Fedora and RHEL use epoch 4:
    %global perl_version 4:%{perl_version}
%endif
%if 0%{?suse_version}
    # OpenSuse does not use epoch in Perl version.
%endif

BuildRequires: gcc-c++
    # There is one test written in C++.
BuildRequires: make
BuildRequires: %{_make}
BuildRequires: perl >= %{perl_version}
BuildRequires: %{_perl}
BuildRequires: perl(utf8)
BuildRequires: perl(open)
BuildRequires: %{_localedef}
BuildRequires: %{_charmapsdir}/UTF-8.gz
    # F24 moves charmaps from glibc-common to glibc-locale-source. Let us require specific file
    # instead of package so the requirement can be fulfilled by any version of Fedora.

Requires:      %{_localedef}
Requires:      %{_charmapsdir}/UTF-8.gz
    # F24 moves charmaps from glibc-common to glibc-locale-source. Let us require specific file
    # instead of package so the requirement can be fulfilled by any version of Fedora.

Conflicts:     glibc-locale-en_RU = 0.001

%description
This is a glibc locale, namely, English language locale for Russia.
It consistently sticks to English language, but makes other parameters
more suitable for Russians, e. g.:

    *   Ridiculous 12-hour clock is replaced with 24-hour clock.
    *   Long date format is changed from confusing mm/dd/yyyy to
        unambiguous ISO yyyy-mm-dd.
    *   Weeks start on Monday, not Sunday.
    *   Thousand separator set to narrow non-breaking space. Decimal
        mark is dot, not comma -- it is an English variant of SI style.
    *   Imperial units replaced with metric units.
    *   Default paper sheet size is A4.
    *   Territory is changed to Russia: country name, country phone code,
        currency name, etc.

%prep
%setup -q
%{__mkdir} _build
cd _build
%{__ln_s} ../configure .

%build
cd _build
export PERL=%{_perl}
export LOCALEDEF=%{_localedef}
%{configure} --disable-rpm --disable-html --srcdir=..
%{make_build}

%install
cd _build
%{make_install}

%check
cd _build
VERBOSE=1 %{_make} check

%post
%{_localedef} --quiet -c -i %{_localesdir}/en_RU -f UTF-8 en_RU.utf8
    # There is a problem here: We cannot specify absolute path of charmap file.
    # localedef issues a lot of warnings on ${_charmapsdir}/UTF-8.gz,
    # and cannot find ${_charmapsdir}/UTF-8, so we have to use plain UTF-8.

%preun
# Remove locale only if we are deleting the last package.
if test "$1" -eq 0; then
    %{_localedef} --quiet --delete-from-archive en_RU.utf8
fi

%if 0%{?fedora} >= 31
# Do *not* indent the next line! Indented $filetriggerin directive is not recognized!
%filetriggerin -- %{_archive}
# If glibc-all-langpacks is updated, locale en_RU disappears because glibc-all-langpacks
# replaces entire locale archive.
%{_localedef} --quiet -c -i %{_localesdir}/en_RU -f UTF-8 en_RU.utf8
%else
# Do *not* indent the next line! Indented $filetriggerin directive is not recognized!
%filetriggerin -- %{_template}
# If glibc-all-langpacks is updated, locale en_RU disappears because glibc-all-langpacks rebuilds
# entire locale archive in its posttrans scriplet. triggerin sriplet does not help because
# glibc-all-langpacks' posttrans works after locale-en_RU triggerin, so I cannot fix locale
# archive. :-( Let me try to hack archive template instead:
if [[ -s %{_template} ]]; then
    # Unfortunately, localedef cannot update arbitrary locale archive. The archive must be
    # usr/lib/locale/locale-archive, I can specify only prefix, so I have to create a temp dir
    # and usr/lib/locale/.
    prefix=/tmp/%{name}-%{version}-%{release}.$$
    %{__mkdir_p} ${prefix}%{dirname:%{_archive}}
    %{__ln_s} %{_template} ${prefix}%{_archive}
    %{_localedef} --quiet --prefix=${prefix} -c -i %{_localesdir}/en_RU -f UTF-8 en_RU.utf8
    %{__rm} -rf ${prefix}
fi
%endif

%files
%defattr( -, root, root, - )
%{_localesdir}/en_RU
%dir %{_docdir}/%{name}
%doc %{_docdir}/%{name}/*

%changelog
* Mon Aug  9 2021 Van de Bugger - 0.5.5-0.vdb.4
- Rebuilt for F34.

* Wed Oct 28 2020 Van de Bugger - 0.5.5-0.vdb.3
- Rebuilt for F33.

* Wed May 06 2020 Van de Bugger - 0.5.5-0.vdb.2
- Rebuilt for F32.

* Sun Feb 02 2020 Van de Bugger - 0.5.5-0.vdb.1
- Updated to v0.5.5.
- Locale din't survive glibc update in F31. Fixed again.

* Tue Nov 26 2019 Van de Bugger - 0.5.4-0.vdb.3
- Locale din't survive glibc update in F31. Fixed.

* Sat Nov 02 2019 Van de Bugger - 0.5.4-0.vdb.2
- Spec fixed to enable OpenSuse and Mageia builds.
- Rebuild for F31.

* Wed Mar 27 2019 Van de Bugger - 0.5.4-0.1
- Updated to v0.5.4.

* Thu Nov 01 2018 Van de Bugger - 0.5.3-2
- locale-en_RU survives updating the glic-all-langpacks.

* Wed Oct 31 2018 Van de Bugger - 0.5.3-1
- Updated to v0.5.3.
- make_build and make_install macros used.

* Mon Apr 10 2017 Van de Bugger - 0.5.2-1
- Updated to v0.5.2.
- Source0 tag specified properly.

* Wed Aug 03 2016 Van de Bugger - 0.5.1-3
- BuildRequires tag was accidentally used instead of Requires tag. Fixed.

* Mon Jun 27 2016 Van de Bugger - 0.5.1-2
- F24 moves charmaps from glibc-common to glibc-locale-source. Fix to work in F24.
- _bindir macro used few times.

* Fri Feb 19 2016 Van de Bugger - 0.5.1-1
- Build requires make and /usr/bin/make.
- Build requires perl modules: perl(open), perl(utf8), not perl-open package.
- Build requires glibc-common and /usr/bin/localedef.
- Since we explicitly require /usr/bin/perl and /usr/bin/localedef, they are passed to configure.

* Sun Feb 14 2016 Van de Bugger - 0.5-1
- Locale updated to v0.5.
- perl-open was a missed build requirement, added now.
- Test result is not ignored now.

* Wed Nov 12 2014 Van de Bugger - 0.4.3-1
- HTML documentation bug fixing and improvements.
- Many changes in build and test infrastructure, not visible to end users.

* Tue Nov 4 2014 Van de Bugger - 0.4-1
- Locale updated to v0.4.
- Documentation is installed to unversioned directory, like other Fedora 20 packages.

* Sun Oct 27 2013 Van de Bugger - 0.3-1
- Locale updated to v0.3.
- Fixed bug in spec file which prevents upgrade.
- This package conflicts with glibc-locale-en_RU-0.001 to avoid the bug described above.
- Documentation added.

* Sat Oct 5 2013 Van de Bugger - 0.2-1
- Project renamed from "glibc-locale-en_RU" to "locale-en_RU".

* Thu Mar 14 2013 Van de Bugger - 0.1-1
- Initial release.

# end of file #