##
##  irstlm.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 information
Name:         irstlm
Summary:      IRST LM Toolkit
URL:          http://hlt-mt.fbk.eu/technologies/irstlm
Vendor:       Marcello Federico
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Algorithm
License:      LGPL
Version:      5.80.08
Release:      20160130

#   list of sources
Source0:      http://download.sourceforge.net/irstlm/irstlm-%{version}.tgz
Patch0:       irstlm.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, gcc, gcc::with_cxx = yes, libtool, autoconf, automake
PreReq:       OpenPKG, openpkg >= 20160101, perl

%description
    IRSTLM, the IRST Language Modeling Toolkit, features algorithms and
    data structures suitable to estimate, store, and access very large
    n-gram language models. Our software has been integrated into a
    popular open source Statistical Machine Translation decoder called
    Moses, and is compatible with language models created with other
    tools, such as the SRILM Tooolkit.

%track
    prog irstlm = {
        version   = %{version}
        url       = http://sourceforge.net/projects/irstlm/
        regex     = irstlm-(__VER__)\.tgz
    }

%prep
    %setup -q
    %patch -p0

%build
    #   bootstrap package
    cd trunk
    aclocal
    libtoolize --copy
    autoheader
    automake --add-missing
    autoconf

    #   configure package
    CC="%{l_cc}" \
    CXX="%{l_cxx}" \
    CFLAGS="%{l_cflags -O}" \
    CXXFLAGS="%{l_cxxflags -O}" \
    CPPFLAGS="%{l_cppflags}" \
    LDFLAGS="%{l_ldflags}" \
    ./configure \
        --prefix=%{l_prefix} \
        --includedir=%{l_prefix}/include/irstlm \
        --disable-shared \
        --disable-doc \
        --disable-debugging

    #   build package
    %{l_make} %{l_mflags -O}

%install
    #   install package
    (   cd trunk
        %{l_make} %{l_mflags} install AM_MAKEFLAGS="DESTDIR=$RPM_BUILD_ROOT" DESTDIR=$RPM_BUILD_ROOT
    ) || exit $?

    #   cleanup installation files
    for bin in `cd $RPM_BUILD_ROOT%{l_prefix}/bin; echo *`; do
        case "$bin" in
            *.sh )
                %{l_shtool} subst \
                    -e 's;/bin/bash;%{l_bash};g' \
                    $RPM_BUILD_ROOT%{l_prefix}/bin/$bin
                ;;
            *.pl )
                %{l_shtool} subst \
                    -e 's;/usr/bin/perl;%{l_prefix}/bin/perl;g' \
                    $RPM_BUILD_ROOT%{l_prefix}/bin/$bin
                ;;
            * )
                strip $RPM_BUILD_ROOT%{l_prefix}/bin/$bin
                ;;
        esac
        name=`echo $bin | sed -e 's;\\.sh$;;' -e 's;\\.pl$;;'`
        mv  $RPM_BUILD_ROOT%{l_prefix}/bin/$bin \
            $RPM_BUILD_ROOT%{l_prefix}/bin/irstlm-$name
    done

    #   determine installation files
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std}

%files -f files

%clean

