##
##  mozldap.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:         mozldap
Summary:      Mozilla LDAP SDK
URL:          https://wiki.mozilla.org/LDAP_C_SDK
Vendor:       Mozilla Foundation
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        LDAP
License:      MPL
Version:      6.0.7
Release:      20120715

#   list of sources
Source0:      ftp://ftp.mozilla.org/pub/mozilla.org/directory/c-sdk/releases/v%{version}/src/mozldap-%{version}.tar.gz
Source1:      mozldap.pc
Patch0:       mozldap.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101
PreReq:       OpenPKG, openpkg >= 20160101
BuildPreReq:  nspr, nss, sasl
PreReq:       nspr, nss, sasl

%description
    The C LDAP Application Program Interface (RFC 1823) defines a set of
    API functions that you can use to build LDAP-enabled clients. The
    functionality implemented in the Mozilla LDAP SDK closely follows
    these interfaces. Using the functionality provided, you can enable
    your clients to connect to LDAPv3-compliant servers and perform
    standard LDAP functions. Among other things, with this SDK you
    can: search for and retrieving a list of entries, add new entries
    (modify) the database, update existing entries, delete entries and
    rename entries.

%track
    prog mozldap = {
        version   = %{version}
        url       = ftp://ftp.mozilla.org/pub/mozilla.org/directory/c-sdk/releases/
        regex     = v(__VER__)
    }

%prep
    %setup -q
    %{l_shtool} mkdir -f -p -m 755 mozilla/directory
    mv c-sdk mozilla/directory/
    %patch -p0

%build
    cd mozilla/directory/c-sdk
    %{l_shtool} subst \
        -e 's;^\(TARGETS[^=]*=.$(LIBRARY)\) $(SHARED_LIBRARY);\1;' \
        config/rules.mk
    %{l_shtool} subst \
        -e 's;^MKSHLIB;#MKSHLIB;' \
        -e 's;-Wall;;g' \
        config/*.mk config/*.mk.in
    %{l_shtool} subst \
        -e 's;-Wall;;g' \
        configure
    CC="%{l_cc}" \
    CXX="%{l_cxx}" \
    CFLAGS="%{l_cflags -O}" \
    CXXFLAGS="%{l_cxxflags -O}" \
    CPPFLAGS="-I`pwd`/../../dist/public/ldap -I`pwd`/../../dist/public/ldap-private %{l_cppflags nss .}" \
    LDFLAGS="%{l_ldflags}" \
    ./configure \
        --prefix=%{l_prefix} \
        --with-sasl=%{l_prefix} \
        --with-system-nspr \
        --with-nspr=%{l_prefix} \
        --with-system-nss \
        --with-nss=%{l_prefix} \
        --with-pthreads \
        --disable-debug
    %{l_make} %{l_mflags} DLLLDAP="" DLLPRLDAP="" DLLLDIF="" DLLSSLDAP=""
    ( cd ldap/libraries/libssldap && %{l_make} %{l_mflags} libssldap60.a ) || exit $?
    cp ldap/libraries/lib*/lib*.a ../../dist/lib/ >/dev/null 2>&1 || true

%install
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/bin \
        $RPM_BUILD_ROOT%{l_prefix}/etc/mozldap \
        $RPM_BUILD_ROOT%{l_prefix}/include/mozldap/ldap \
        $RPM_BUILD_ROOT%{l_prefix}/include/mozldap/ldap-private \
        $RPM_BUILD_ROOT%{l_prefix}/lib/pkgconfig
    %{l_shtool} install -c -m 644 \
        mozilla/dist/lib/*.a $RPM_BUILD_ROOT%{l_prefix}/lib/
    %{l_shtool} install -c -m 644 \
        mozilla/dist/public/ldap/*.h $RPM_BUILD_ROOT%{l_prefix}/include/mozldap/ldap/
    %{l_shtool} install -c -m 644 \
        mozilla/dist/public/ldap-private/*.h $RPM_BUILD_ROOT%{l_prefix}/include/mozldap/ldap-private/
    %{l_shtool} install -c -m 644 \
        mozilla/dist/etc/* $RPM_BUILD_ROOT%{l_prefix}/etc/mozldap/
    %{l_shtool} install -c -m 644 %{l_value -s -a} \
        -e 's;@l_version@;%{version};' \
        %{SOURCE mozldap.pc} $RPM_BUILD_ROOT%{l_prefix}/lib/pkgconfig/
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%config %{l_prefix}/etc/mozldap/*'

%files -f files

%clean

