##
##  groonga.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:         groonga
Summary:      Full-Text Search Engine
URL:          http://groonga.org/
Vendor:       Brazil, Inc.
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Database
License:      GPL
Version:      13.0.1
Release:      20230324

#   package options
%option       with_zlib     no
%option       with_zstd     no
%option       with_lz4      no
%option       with_msgpack  no

#   list of sources
Source0:      http://packages.groonga.org/source/groonga/groonga-%{version}.tar.gz
Patch0:       groonga.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, gcc, gcc::with_cxx = yes, pkgconfig
PreReq:       OpenPKG, openpkg >= 20160101
BuildPreReq:  glib
PreReq:       glib
%if "%{with_zlib}" == "yes"
BuildPreReq:  zlib
PreReq:       zlib
%endif
%if "%{with_zstd}" == "yes"
BuildPreReq:  zstd
PreReq:       zstd
%endif
%if "%{with_lz4}" == "yes"
BuildPreReq:  lz4
PreReq:       lz4
%endif
%if "%{with_msgpack}" == "yes"
BuildPreReq:  msgpack
PreReq:       msgpack
%endif

%description
    Groonga is an open-source fulltext search engine and column store.
    It lets you write high-performance applications that requires
    fulltext search.

%track
    prog groonga = {
        version   = %{version}
        url       = http://packages.groonga.org/source/groonga/
        regex     = groonga-(__VER__)\.tar\.gz
    }

%prep
    %setup -q
    %patch -p0

%build
    #   configure program
    CC="%{l_cc} %{l_cflags -O}" \
    CXX="%{l_cxx} %{l_cxxflags -O}" \
    CFLAGS="%{l_cflags -O}" \
    CXXFLAGS="%{l_cxxflags -O}" \
    CPPFLAGS="%{l_cppflags}" \
    LDFLAGS="%{l_ldflags}" \
    ./configure \
        --prefix=%{l_prefix} \
        --mandir=%{l_prefix}/man \
%if "%{with_zlib}" == "yes"
        --with-zlib=%{l_prefix} \
%else
        --without-zlib \
%endif
%if "%{with_zstd}" == "yes"
        --with-zstd=%{l_prefix} \
%else
        --without-zstd \
%endif
%if "%{with_lz4}" == "yes"
        --with-lz4=%{l_prefix} \
%else
        --without-lz4 \
%endif
%if "%{with_msgpack}" == "yes"
        --enable-message-pack \
        --with-message-pack=%{l_prefix} \
%else
        --disable-message-pack \
        --without-message-pack \
%endif
        --without-libstemmer \
        --without-ssl \
        --without-zeromq \
        --disable-groonga-httpd \
        --disable-shared \
        --enable-static \
        --disable-nls

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

%install
    #   install program
    %{l_make} %{l_mflags} install AM_MAKEFLAGS="DESTDIR=$RPM_BUILD_ROOT"

    #   post-adjust installation
    rm -f $RPM_BUILD_ROOT%{l_prefix}/lib/libgroonga.so*
    %{l_shtool} subst \
        -e 's;^\(dlname=.\).*\(.\)$;\1\2;' \
        -e 's;^\(library_names=.\).*\(.\)$;\1\2;' \
        $RPM_BUILD_ROOT%{l_prefix}/lib/libgroonga.la

    #   strip-down installation
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/etc/groonga/windows_event_log
    rm -f $RPM_BUILD_ROOT%{l_prefix}/lib/groonga/plugins/*/*.a
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/doc
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/groonga
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/etc/groonga/httpd
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/man/ja
    strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true

    #   determine installation files
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%config %{l_prefix}/etc/groonga/*'

%files -f files

%clean

