##
##  tre.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:         tre
Summary:      POSIX RegEx Library with Fuzzy Matching
URL:          http://laurikari.net/tre/
Vendor:       Ville Laurikari
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        BASE
Group:        RegExp
License:      GPL
Version:      0.8.0
Release:      20180715

#   package options
%option       with_agrep  no
%option       with_utf8   yes

#   list of sources
Source0:      http://laurikari.net/tre/tre-%{version}.tar.bz2

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, gcc
PreReq:       OpenPKG, openpkg >= 20160101
%if "%{with_utf8}" == "yes"
BuildPreReq:  libutf8
PreReq:       libutf8
%endif

%description
    TRE is a lightweight, robust, and efficient POSIX compliant regexp
    matching library with some exciting features such as approximate
    (fuzzy) matching. At the core of TRE is a new algorithm for regular
    expression matching with submatch addressing. The algorithm uses
    linear worst-case time in the length of the text being searched,
    and quadratic worst-case time in the length of the used regular
    expression. In other words, the time complexity of the algorithm
    is O(M2N), where M is the length of the regular expression and N
    is the length of the text. The used space is also quadratic on the
    length of the regex, but does not depend on the searched string.
    This quadratic behaviour occurs only on pathological cases which are
    probably very rare in practice.

%track
    prog tre = {
        version   = %{version}
        url       = https://laurikari.net/tre/download/
        regex     = tre-(__VER__)\.tar\.bz2
    }

%prep
    %setup -q

%build
    CC="%{l_cc}" \
    CFLAGS="%{l_cflags -O}" \
    CPPFLAGS="%{l_cppflags}" \
    LDFLAGS="%{l_ldflags}" \
    GREP="grep" \
    ./configure \
        --prefix=%{l_prefix} \
%if "%{with_agrep}" == "yes"
        --enable-agrep \
%else
        --disable-agrep \
%endif
%if "%{with_utf8}" == "yes"
        --with-libutf8=%{l_prefix} \
        --enable-wchar \
        --enable-multibyte \
%else
        --without-libutf8 \
        --disable-wchar \
        --disable-multibyte \
%endif
        --without-alloca \
        --enable-system-abi \
        --disable-nls \
        --without-libiconv-prefix \
        --without-libintl-prefix \
        --disable-shared
    %{l_make} %{l_mflags -O}

%install
    %{l_make} %{l_mflags} install AM_MAKEFLAGS="DESTDIR=$RPM_BUILD_ROOT"
    strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/locale
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std}

%files -f files

%clean

