##
##  citadel.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_citadel     7.33
%define       V_libcitadel  1.08

#   package information
Name:         citadel
Summary:      Messaging and Collaboration Platform
URL:          http://www.citadel.org/
Vendor:       The Citadel development team
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Mail
License:      GNU
Version:      %{V_citadel}
Release:      20080304

#   package options
%option       with_ical   no
%option       with_ldap   no

#   list of sources
Source0:      http://easyinstall.citadel.org/citadel-%{V_citadel}.tar.gz
Source1:      http://easyinstall.citadel.org/libcitadel-%{V_libcitadel}.tar.gz
Patch0:       citadel.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, make, gcc
PreReq:       OpenPKG, openpkg >= 20160101
BuildPreReq:  zlib, ncurses, openssl, db
PreReq:       zlib, ncurses, openssl, db
%if "%{with_ical}" == "yes"
BuildPreReq:  libical
PreReq:       libical
%endif
%if "%{with_ldap}" == "yes"
PreReq:       openldap
%endif

%description
    Since 1981, Citadel systems have brought people together like no
    other software has ever been capable of doing. Citadel/UX is a
    state-of-the-art messaging platform which can be used to build an
    online community that puts users in touch with each other without
    calling attention to itself.

%track
    prog citadel = {
        version   = %{version}
        url       = http://www.citadel.org/doku.php?id=installation:start
        regex     = citadel-(__VER__)\.tar\.gz
    }

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

%build
    ( cd libcitadel-%{V_libcitadel}
      CC="%{l_cc}" \
      CXX="%{l_cxx}" \
      CFLAGS="%{l_cflags -O} %{l_cppflags ncurses}" \
      CXXFLAGS="%{l_cxxflags -O} %{l_cppflags ncurses}" \
      CPPFLAGS="%{l_cppflags} %{l_cppflags ncurses}" \
      LDFLAGS="%{l_ldflags}" \
      LIBS="-lz" \
      ./configure \
          --prefix=%{l_prefix} \
          --disable-shared
      %{l_make} %{l_mflags -O}
    ) || exit $?
    CC="%{l_cc}" \
    CXX="%{l_cxx}" \
    CFLAGS="%{l_cflags -O} %{l_cppflags ncurses}" \
    CXXFLAGS="%{l_cxxflags -O} %{l_cppflags ncurses}" \
    CPPFLAGS="%{l_cppflags} %{l_cppflags ncurses} -I`pwd`/libcitadel-%{V_libcitadel}/lib" \
    LDFLAGS="%{l_ldflags} -L`pwd`/libcitadel-%{V_libcitadel}/.libs" \
    LIBS="-lz" \
    ./configure \
        --prefix=%{l_prefix} \
        --with-db=%{l_prefix} \
        --with-ssl=%{l_prefix} \
        --with-ncurses \
        --with-zlib \
        --without-pam \
%if "%{with_ical}" == "yes"
        --with-libical \
%else
        --without-libical \
%endif
%if "%{with_ldap}" == "yes"
        --with-ldap \
%else
        --without-ldap \
%endif
        --without-kthread \
        --enable-autologin \
        --enable-chkpwd \
        --without-newt
    %{l_make} %{l_mflags -O}

%install
    %{l_shtool} mkdir -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/bin \
        $RPM_BUILD_ROOT%{l_prefix}/sbin \
        $RPM_BUILD_ROOT%{l_prefix}/etc/citadel \
        $RPM_BUILD_ROOT%{l_prefix}/var/citadel \
        $RPM_BUILD_ROOT%{l_prefix}/libexec/citadel \
        $RPM_BUILD_ROOT%{l_prefix}/share/citadel/bio \
        $RPM_BUILD_ROOT%{l_prefix}/share/citadel/bitbucket \
        $RPM_BUILD_ROOT%{l_prefix}/share/citadel/files \
        $RPM_BUILD_ROOT%{l_prefix}/share/citadel/images \
        $RPM_BUILD_ROOT%{l_prefix}/share/citadel/info \
        $RPM_BUILD_ROOT%{l_prefix}/share/citadel/userpics \
        $RPM_BUILD_ROOT%{l_prefix}/share/citadel/help \
        $RPM_BUILD_ROOT%{l_prefix}/share/citadel/messages \
        $RPM_BUILD_ROOT%{l_prefix}/var/citadel/network/spoolin \
        $RPM_BUILD_ROOT%{l_prefix}/var/citadel/network/spoolout \
        $RPM_BUILD_ROOT%{l_prefix}/var/citadel/network/systems
    %{l_shtool} install -c -m 744 %{l_value -s -a} \
        citadel citserver citmail getmail userlist chkpwd \
        $RPM_BUILD_ROOT%{l_prefix}/sbin/
    %{l_shtool} install -c -m 744 %{l_value -s -a} \
        help/[a-z]* $RPM_BUILD_ROOT%{l_prefix}/share/citadel/help/
    %{l_shtool} install -c -m 744 %{l_value -s -a} \
        messages/[a-z]* $RPM_BUILD_ROOT%{l_prefix}/share/citadel/messages/
    %{l_shtool} install -c -m 744 %{l_value -s -a} \
        network/mail.aliases $RPM_BUILD_ROOT%{l_prefix}/var/citadel/network/
    strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std} \
        '%attr(4755,%{l_susr},%{l_rgrp}) %{l_prefix}/sbin/chkpwd'

%files -f files

%clean

