##
##  aspell.spec -- OpenPKG RPM Package Specification
##  Copyright (c) 2000-2025 OpenPKG Project <http://openpkg.org/>
##
##  Permission to use, copy, modify, and distribute this software for
##  any purpose with or without fee is hereby granted, provided that
##  the above copyright notice and this permission notice appear in all
##  copies.
##
##  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
##  SUCH DAMAGE.
##

#   package version
%define       V_aspell        0.60.8.1
%define       V_aspell_en     2020.12.07-0
%define       V_aspell_de_new 20030222-1
%define       V_aspell_de_old 2.1-1
%define       V_aspell_perl   0.09

#   package information
Name:         aspell
Summary:      Interactive Spell Checker
URL:          http://aspell.net/
Vendor:       Kevin Atkinson
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        BASE
Group:        Writing
License:      GPL
Version:      %{V_aspell}
Release:      20231220

#   package options
%option       with_perl  no

#   list of sources
Source0:      http://ftp.gnu.org/gnu/aspell/aspell-%{V_aspell}.tar.gz
Source1:      http://ftp.gnu.org/gnu/aspell/dict/en/aspell6-en-%{V_aspell_en}.tar.bz2
Source2:      http://ftp.gnu.org/gnu/aspell/dict/de/aspell6-de-%{V_aspell_de_new}.tar.bz2
Source3:      http://ftp.gnu.org/gnu/aspell/dict/de/aspell6-de-alt-%{V_aspell_de_old}.tar.bz2
Source4:      http://www.cpan.org/modules/by-module/Text/Text-Aspell-%{V_aspell_perl}.tar.gz
Patch0:       aspell.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, ncurses, perl, gcc, make
PreReq:       OpenPKG, openpkg >= 20160101, ncurses, perl
%if "%{with_perl}" == "yes"
BuildPreReq:  perl, perl-openpkg >= 5.8.3-20040126
PreReq:       perl, perl-openpkg >= 5.8.3-20040126
%endif

%description
    GNU Aspell is a Free and Open Source spell checker designed to
    eventually replace Ispell. It can either be used as a library
    or as an independent spell checker. Its main feature is that it
    does a much better job of coming up with possible suggestions
    than just about any other spell checker out there for the English
    language, including Ispell and Microsoft Word. It also has many
    other technical enhancements over Ispell such as using shared memory
    for dictionaries and intelligently handling personal dictionaries
    when more than one Aspell process is open at once.

%track
    prog aspell:aspell = {
        version   = %{V_aspell}
        url       = http://ftp.gnu.org/gnu/aspell/
        regex     = aspell-(\d+\.\d+(\.\d+)*)\.tar\.gz
    }
    prog aspell:aspell-en = {
        version   = %{V_aspell_en}
        url       = http://ftp.gnu.org/gnu/aspell/dict/en/
        regex     = aspell\d*-en-(__VER__)\.tar\.bz2
    }
    prog aspell:aspell-de-new = {
        version   = %{V_aspell_de_new}
        url       = http://ftp.gnu.org/gnu/aspell/dict/de/
        regex     = aspell\d*-de-(__VER__)\.tar\.bz2
    }
    prog aspell:aspell-de-old = {
        version   = %{V_aspell_de_old}
        url       = http://ftp.gnu.org/gnu/aspell/dict/de-alt/
        regex     = aspell\d*-de-alt-(__VER__)\.tar\.bz2
    }
    prog aspell:aspell-perl = {
        version   = %{V_aspell_perl}
        url       = http://www.cpan.org/modules/by-module/Text/
        regex     = Text-Aspell-(__VER__)\.tar\.gz
    }

%prep
    %setup -q
    %setup -q -T -D -a 1
    %setup -q -T -D -a 2
    %setup -q -T -D -a 3
%if "%{with_perl}" == "yes"
    %setup -q -T -D -a 4
%endif
    %patch -p0

%build
    #   configure GNU aspell
    CC="%{l_cc}" \
    CXX="%{l_cxx}" \
    CFLAGS="%{l_cflags -O}" \
    CXXFLAGS="%{l_cxxflags -O}" \
    CPPFLAGS="%{l_cppflags}" \
    GREP="grep" \
    ./configure \
        --prefix=%{l_prefix} \
        --mandir=%{l_prefix}/man \
        --infodir=%{l_prefix}/info \
        --sysconfdir=%{l_prefix}/etc/aspell \
        --libdir=%{l_prefix}/lib \
        --enable-pkglibdir=%{l_prefix}/lib/aspell \
        --enable-pkgdatadir=%{l_prefix}/share/aspell \
        --enable-compile-in-filters \
        --disable-shared \
        --disable-nls

    #   build GNU aspell
    %{l_make} %{l_mflags -O}

    #   optionally build Perl API
%if "%{with_perl}" == "yes"
    %{l_prefix}/bin/perl-openpkg prepare
    %{l_shtool} subst \
        -e 's;\(-laspell\);-L../.libs \1;' \
        Text-Aspell-%{V_aspell_perl}/Makefile.PL
    %{l_prefix}/bin/perl-openpkg -d Text-Aspell-%{V_aspell_perl} \
        --args CCFLAGS="-I`pwd`/interfaces/cc" \
        configure build
%endif

%install

    #   install GNU aspell
    %{l_make} %{l_mflags} install AM_MAKEFLAGS="DESTDIR=$RPM_BUILD_ROOT"
    %{l_shtool} subst \
        -e 's;/usr/bin/perl;%{l_prefix}/bin/perl;' \
        $RPM_BUILD_ROOT%{l_prefix}/bin/aspell-import
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/doc
    rm -f $RPM_BUILD_ROOT%{l_prefix}/bin/run-with-aspell
    strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/lib/aspell

    #   install GNU aspell English (EN) dictionary
    ( cd aspell6-en-%{V_aspell_en}
      export DESTDIR="$RPM_BUILD_ROOT"
      export PREZIP="../prezip-bin"
      export ASPELL="../aspell"
      export ASPELL_FLAGS="--prefix=$RPM_BUILD_ROOT%{l_prefix}"
      ASPELL_FLAGS="$ASPELL_FLAGS --dict-dir=$RPM_BUILD_ROOT%{l_prefix}/lib/aspell"
      ASPELL_FLAGS="$ASPELL_FLAGS --data-dir=$RPM_BUILD_ROOT%{l_prefix}/share/aspell"
      ./configure
      %{l_make} %{l_mflags}
      %{l_make} %{l_mflags} install
    ) || exit $?

    #   install GNU aspell German (DE) dictionary (new spelling)
    ( cd aspell6-de-%{V_aspell_de_new}
      export DESTDIR="$RPM_BUILD_ROOT"
      export PREZIP="../prezip-bin"
      export ASPELL="../aspell"
      export ASPELL_FLAGS="--prefix=$RPM_BUILD_ROOT%{l_prefix}"
      ASPELL_FLAGS="$ASPELL_FLAGS --dict-dir=$RPM_BUILD_ROOT%{l_prefix}/lib/aspell"
      ASPELL_FLAGS="$ASPELL_FLAGS --data-dir=$RPM_BUILD_ROOT%{l_prefix}/share/aspell"
      ./configure
      %{l_make} %{l_mflags}
      %{l_make} %{l_mflags} install
    ) || exit $?

    #   install GNU aspell German (DE) dictionary (old spelling)
    ( cd aspell6-de-alt-%{V_aspell_de_old}
      export DESTDIR="$RPM_BUILD_ROOT"
      export PREZIP="../prezip-bin"
      export ASPELL="../aspell"
      export ASPELL_FLAGS="--prefix=$RPM_BUILD_ROOT%{l_prefix}"
      ASPELL_FLAGS="$ASPELL_FLAGS --dict-dir=$RPM_BUILD_ROOT%{l_prefix}/lib/aspell"
      ASPELL_FLAGS="$ASPELL_FLAGS --data-dir=$RPM_BUILD_ROOT%{l_prefix}/share/aspell"
      ./configure
      %{l_make} %{l_mflags}
      %{l_make} %{l_mflags} install
    ) || exit $?

    #   optionally install Perl API
%if "%{with_perl}" == "yes"
    %{l_prefix}/bin/perl-openpkg -d Text-Aspell-%{V_aspell_perl} install
    %{l_prefix}/bin/perl-openpkg -F perl-openpkg-files fixate cleanup
%else
    >perl-openpkg-files
%endif

    #   strip down installation
    rm -f $RPM_BUILD_ROOT%{l_prefix}/info/dir

    #   determine installation files
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} `cat perl-openpkg-files`

%files -f files

%clean

