##
##  apr.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_apr       1.7.6
%define       V_apr_util  1.6.3

#   package information
Name:         apr
Summary:      Apache Portable Runtime
URL:          http://apr.apache.org/
Vendor:       Apache Software Foundation
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        BASE
Group:        Libraries
License:      Apache
Version:      %{V_apr}
Release:      20250516

#   package options
%option       with_threads  no
%option       with_db       no
%option       with_gdbm     no
%option       with_iconv    no
%option       with_ldap     no
%option       with_odbc     no
%option       with_pgsql    no
%option       with_mysql    no
%option       with_sqlite   no

#   list of sources
Source0:      http://www.apache.org/dist/apr/apr-%{V_apr}.tar.bz2
Source1:      http://www.apache.org/dist/apr/apr-util-%{V_apr_util}.tar.bz2
Patch0:       apr.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, sed, make
PreReq:       OpenPKG, openpkg >= 20160101, sed
BuildPreReq:  expat
PreReq:       expat
%if "%{with_db}" == "yes"
BuildPreReq:  db >= 4.6
PreReq:       db >= 4.6
%endif
%if "%{with_gdbm}" == "yes"
BuildPreReq:  gdbm
PreReq:       gdbm
%endif
%if "%{with_iconv}" == "yes"
BuildPreReq:  libiconv
PreReq:       libiconv
%endif
%if "%{with_ldap}" == "yes"
BuildPreReq:  openldap, openssl >= 0.9.8
PreReq:       openldap, openssl >= 0.9.8
%endif
%if "%{with_odbc}" == "yes"
BuildPreReq:  ODBC
PreReq:       ODBC
%endif
%if "%{with_pgsql}" == "yes"
BuildPreReq:  postgresql
PreReq:       postgresql
%endif
%if "%{with_mysql}" == "yes"
BuildPreReq:  mysql
PreReq:       mysql
%endif
%if "%{with_sqlite}" == "yes"
BuildPreReq:  sqlite
PreReq:       sqlite
%endif

%description
    Apache Portable Runtime (APR) is a library of C data structures
    and routines, forming a common system portability layer to as many
    operating systems as possible.

%track
    prog apr = {
        version   = %{V_apr}
        url       = http://www.apache.org/dist/apr/
        regex     = apr-(__VER__)\.tar\.bz2
    }
    prog apr:apr-util = {
        version   = %{V_apr_util}
        url       = http://www.apache.org/dist/apr/
        regex     = apr-util-(__VER__)\.tar\.bz2
    }

%prep
    %setup -q -c
    %setup -q -D -T -a 1
    %patch -p0

%build
    ( cd apr-%{V_apr}
      CC="%{l_cc}" \
      CFLAGS="%{l_cflags -O}" \
      CONFIG_SHELL="/bin/sh" \
      ./configure \
          --enable-layout=GNU \
          --prefix=%{l_prefix} \
          --includedir=%{l_prefix}/include/apr \
          --datadir=%{l_prefix}/share/apr \
%if "%{with_threads}" == "yes"
          --enable-threads \
%else
          --disable-threads \
%endif
          --enable-shared \
          --enable-static
      %{l_make} %{l_mflags -O}
    ) || exit $?
    ( cd apr-util-%{V_apr_util}
      cp /dev/null config.cache
%if "%{with_iconv}" == "no"
      ( echo "ac_cv_header_iconv_h=no"
      ) >config.cache
%endif
      CC="%{l_cc}" \
      CFLAGS="%{l_cflags -O}" \
%if "%{with_ldap}" == "yes"
      LIBS="-lssl -lcrypto" \
%endif
      ./configure \
          --cache-file=./config.cache \
          --enable-layout=GNU \
          --prefix=%{l_prefix} \
          --includedir=%{l_prefix}/include/apr \
          --datadir=%{l_prefix}/share/apr \
          --with-apr=`pwd`/../apr-%{V_apr} \
%if "%{with_db}" == "yes"
          --with-berkeley-db=%{l_prefix} \
%endif
%if "%{with_gdbm}" == "yes"
          --with-gdbm=%{l_prefix} \
%endif
%if "%{with_db}" == "yes"
          --with-dbm=db46 \
%else
%if "%{with_gdbm}" == "yes"
          --with-dbm=gdbm \
%else
          --with-dbm=sdbm \
%endif
%endif
          --with-expat=%{l_prefix} \
%if "%{with_iconv}" == "yes"
          --with-iconv=%{l_prefix} \
%endif
%if "%{with_ldap}" == "yes"
          --with-ldap \
          --with-ldap-include=%{l_prefix}/include/ \
          --with-ldap-lib=%{l_prefix}/lib \
%endif
%if "%{with_odbc}" == "yes"
          --with-odbc=%{l_prefix} \
%else
          --without-odbc \
%endif
%if "%{with_pgsql}" == "yes"
          --with-pgsql=%{l_prefix} \
%else
          --without-pgsql \
%endif
%if "%{with_mysql}" == "yes"
          --with-mysql=%{l_prefix} \
%else
          --without-mysql \
%endif
%if "%{with_sqlite}" == "yes"
          --with-sqlite3=%{l_prefix} \
%else
          --without-sqlite3 \
%endif
          --enable-util-dso \
          --enable-shared \
          --enable-static
      %{l_make} %{l_mflags -O}
    ) || exit $?

%install
    ( cd apr-%{V_apr}
      %{l_make} %{l_mflags} install DESTDIR=$RPM_BUILD_ROOT
    ) || exit $?
    ( cd apr-util-%{V_apr_util}
      %{l_make} %{l_mflags} install DESTDIR=$RPM_BUILD_ROOT
    ) || exit $?
    rm -f $RPM_BUILD_ROOT%{l_prefix}/lib/apr.exp
    rm -f $RPM_BUILD_ROOT%{l_prefix}/lib/aprutil.exp
    rm -f $RPM_BUILD_ROOT%{l_prefix}/lib/apr-util-1/*.a
    rm -f $RPM_BUILD_ROOT%{l_prefix}/lib/*.la
    rm -f $RPM_BUILD_ROOT%{l_prefix}/lib/*.so*
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std}

%files -f files

%clean

