##
##  qdbm.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:         qdbm
Summary:      Quick Database Manager
URL:          http://fallabs.com/qdbm/
Vendor:       Mikio Hirabayashi
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        PLUS
Group:        Database
License:      LGPL
Version:      1.8.78
Release:      20140301

#   package options
%option       with_ndbm  no
%option       with_perl  no
%option       with_cxx   no

#   list of sources
Source0:      http://fallabs.com/qdbm/qdbm-%{version}.tar.gz
Patch0:       qdbm.patch

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

%description
    QDBM is a library of routines for managing a database. The database
    is a simple data file containing records, each is a pair of a key
    and a value. Every key and value is serial bytes with variable
    length. Both binary data and character string can be used as a key
    and a value. There is neither concept of data tables nor data types.
    Records are organized in hash table or B+ tree. Additionally, QDBM
    also provides NDBM and GDBM backward compatibility C APIs.

%track
    prog qdbm = {
        version   = %{version}
        url       = http://fallabs.com/qdbm/
        regex     = qdbm-(__VER__)\.tar\.gz
    }

%prep
    %setup -q
    %patch -p0

%build
    ( echo "ac_cv_lib_iconv_main=no"
      echo "ac_cv_lib_z_main=no"
    ) >config.cache
    CC="%{l_cc}" \
    CFLAGS="%{l_cflags -O}" \
    ./configure \
        --cache-file=./config.cache \
        --prefix=%{l_prefix} \
        --includedir=%{l_prefix}/include/qdbm \
        --disable-zlib \
        --disable-iconv \
        --enable-nowarn
    %{l_make} %{l_mflags -O} \
        MYLIBS="libqdbm.a"
%if "%{with_cxx}" == "yes"
    (   cd plus
        CC="%{l_cc}" \
        CFLAGS="%{l_cflags -O}" \
        CXX="%{l_cxx}" \
        CXXFLAGS="%{l_cxxflags}" \
        ./configure \
            --cache-file=../config.cache \
            --prefix=%{l_prefix}
        %{l_make} %{l_mflags -O} \
            MYLIBS="libxqdbm.a"
    ) || exit $?
%endif
%if "%{with_perl}" == "yes"
    %{l_prefix}/bin/perl-openpkg prepare
    for dir in depot curia villa; do
        (   cd perl/$dir
            %{l_prefix}/bin/perl-openpkg \
                --args PREFIX=%{l_prefix} \
                --args CC=%{l_cc} \
                --args LD=%{l_cc} \
                --args "OPTIMIZE='%{l_cflags -O}'" \
                --args "INC='-I../.. %{l_cppflags}'" \
                --args "LIBS='-L../.. %{l_ldflags} -lqdbm'" \
                configure build
        ) || exit $?
    done
%endif

%install
    %{l_make} %{l_mflags} install \
        DESTDIR=$RPM_BUILD_ROOT \
        MYLIBS="libqdbm.a"
%if "%{with_cxx}" == "yes"
    (   cd plus
        %{l_make} %{l_mflags} install \
            DESTDIR=$RPM_BUILD_ROOT \
            MYLIBS="libxqdbm.a"
    ) || exit $?
    rm -fr $RPM_BUILD_ROOT%{l_prefix}/share/qdbm/plus*
%endif
    strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true
    rm -f $RPM_BUILD_ROOT%{l_prefix}/share/qdbm/[A-Z]*
    rm -f $RPM_BUILD_ROOT%{l_prefix}/share/qdbm/spex-ja.html
%if "%{with_ndbm}" == "yes"
    ln  $RPM_BUILD_ROOT%{l_prefix}/include/qdbm/relic.h \
        $RPM_BUILD_ROOT%{l_prefix}/include/ndbm.h
    ln  $RPM_BUILD_ROOT%{l_prefix}/lib/libqdbm.a \
        $RPM_BUILD_ROOT%{l_prefix}/lib/libndbm.a
%endif
%if "%{with_perl}" == "yes"
    %{l_prefix}/bin/perl-openpkg prepare
    for dir in depot curia villa; do
        (   cd perl/$dir
            %{l_prefix}/bin/perl-openpkg install
        ) || exit $?
    done
    %{l_prefix}/bin/perl-openpkg -F perl-openpkg-files fixate cleanup
%else
    >perl-openpkg-files
%endif
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} `cat perl-openpkg-files`

%files -f files

%clean

