## START: Set by rpmautospec
## (rpmautospec version 0.3.5)
## RPMAUTOSPEC: autorelease, autochangelog
%define autorelease(e:s:pb:n) %{?-p:0.}%{lua:
    release_number = 1;
    base_release_number = tonumber(rpm.expand("%{?-b*}%{!?-b:1}"));
    print(release_number + base_release_number - 1);
}%{?-e:.%{-e*}}%{?-s:.%{-s*}}%{!?-n:%{?dist}}
## END: Set by rpmautospec

%if 0%{?fedora} >= 36 || 0%{?rhel} > 9
%global dict_dirname hunspell
%else
%global dict_dirname myspell
%endif

%global gittag libreoffice-7.5.5.1

Name:           hunspell-dictionaries
Summary:        Hunspell dictionaries
# Bump epoch to be sure we're replacing the old single packages
Epoch:          1
Version:        7.5.5.1
Release:        %autorelease
# The main package is empty, therefore there's no license
# Considering the Fedora default license
License:        MIT
URL:            https://github.com/LibreOffice/dictionaries
Source:         %{url}/archive/%{gittag}/%{gittag}.tar.gz

BuildArch:      noarch

%description
Hunspell dictionaries provided by LibreOffice.


%package -n hunspell-af
Summary:        Afrikaans hunspell dictionaries
License:        LGPL-2.1-or-later
Requires:       hunspell-filesystem
Supplements:    (hunspell and langpacks-af)

%description -n hunspell-af
Afrikaans hunspell dictionaries.


%package -n hunspell-ar
Summary:        Arabic hunspell dictionaries
License:        GPL-2.0-or-later OR LGPL-2.1-or-later OR MPL-1.1
Requires:       hunspell-filesystem
Supplements:    (hunspell and langpacks-ar)

%description -n hunspell-ar
Arabic (Egypt, Algeria, etc.) hunspell dictionaries.


%package -n hunspell-be
Summary:        Belarusian hunspell dictionaries
License:        CC-BY-SA-4.0 OR LGPL-3.0-only
Requires:       hunspell-filesystem
Supplements:    (hunspell and langpacks-be)

%description -n hunspell-be
Belarusian hunspell dictionaries.


%package -n hunspell-bg
Summary:        Bulgarian hunspell dictionaries
License:        GPL-2.0-or-later
Requires:       hunspell-filesystem
Supplements:    (hunspell and langpacks-bg)

%description -n hunspell-bg
Bulgarian hunspell dictionaries.


%package -n hunspell-bn
Summary:        Bengali hunspell dictionaries
License:        GPL-2.0-or-later
Requires:       hunspell-filesystem
Supplements:    (hunspell and langpacks-bn)

%description -n hunspell-bn
Bengali hunspell dictionaries.


%package -n hunspell-br
Summary:        Breton hunspell dictionaries
License:        LGPL-2.1-or-later
Requires:       hunspell-filesystem
Supplements:    (hunspell and langpacks-br)

%description -n hunspell-br
Breton hunspell dictionaries.


%package -n hunspell-it
Summary:        Italian hunspell dictionaries
License:        GPL-3.0-only
Requires:       hunspell-filesystem
Supplements:    (hunspell and langpacks-it)

%description -n hunspell-it
Italian hunspell dictionaries.


%prep
%autosetup -n dictionaries-%{gittag}


%build
# Nothing to do


%install
mkdir -p %{buildroot}%{_datadir}/%{dict_dirname}

declare -a langs=(
    "af_ZA"
    "bg_BG"
    "bn_BD"
    "br_FR"
    "it_IT"
)
for lang in ${langs[@]}
do
    cp -p $lang/$lang.dic $lang/$lang.aff %{buildroot}%{_datadir}/%{dict_dirname}
done

# These need renames
cp -p ar/ar.dic %{buildroot}%{_datadir}/%{dict_dirname}/ar_TN.dic
cp -p ar/ar.aff %{buildroot}%{_datadir}/%{dict_dirname}/ar_TN.aff
cp -p be_BY/be-official.dic %{buildroot}%{_datadir}/%{dict_dirname}/be_BY.dic
cp -p be_BY/be-official.aff %{buildroot}%{_datadir}/%{dict_dirname}/be_BY.aff

# Aliases for specific languages
pushd %{buildroot}%{_datadir}/%{dict_dirname}/

declare -A aliases=(
    [af_ZA]="af_NA"
    [ar_TN]="ar_AE ar_BH ar_DJ ar_DZ ar_EG ar_ER ar_IL ar_IN ar_IQ ar_JO ar_KM ar_KW ar_LB ar_LY ar_MA ar_MR ar_OM ar_PS ar_QA ar_SA ar_SD ar_SO ar_SY ar_TD ar_YE"
    [bn_BD]="bn_IN"
    [it_IT]="it_CH"
)
for main_lang in ${!aliases[@]}
do
    declare -a alias_langs=(${aliases[$main_lang]})
    for alias in ${alias_langs[@]}
    do
        ln -s $main_lang.aff $alias.aff
        ln -s $main_lang.dic $alias.dic
    done
done

popd


%files -n hunspell-af
%doc af_ZA/README_af_ZA.txt
%{_datadir}/%{dict_dirname}/af_*.aff
%{_datadir}/%{dict_dirname}/af_*.dic

%files -n hunspell-ar
%license ar/COPYING.txt
%doc ar/AUTHORS.txt ar/README_ar.txt
%{_datadir}/%{dict_dirname}/ar_*.aff
%{_datadir}/%{dict_dirname}/ar_*.dic

%files -n hunspell-be
%doc be_BY/README_be_BY.txt
%{_datadir}/%{dict_dirname}/be_*.aff
%{_datadir}/%{dict_dirname}/be_*.dic

%files -n hunspell-bg
%license bg_BG/COPYING
%{_datadir}/%{dict_dirname}/bg_*.aff
%{_datadir}/%{dict_dirname}/bg_*.dic

%files -n hunspell-bn
%license bn_BD/COPYING
%{_datadir}/%{dict_dirname}/bn_*.aff
%{_datadir}/%{dict_dirname}/bn_*.dic

%files -n hunspell-br
%license br_FR/LICENSES-en.txt
%{_datadir}/%{dict_dirname}/br_*.aff
%{_datadir}/%{dict_dirname}/br_*.dic

%files -n hunspell-it
%doc it_IT/CHANGELOG.txt it_IT/README_it_IT.txt
%{_datadir}/%{dict_dirname}/it_*.aff
%{_datadir}/%{dict_dirname}/it_*.dic


%changelog
* Sat Jul 01 2023 John Doe <packager@example.com> - 1:7.5.5.1-1
- Uncommitted changes