##
##  cups.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:         cups
Summary:      Common Unix Printing System (CUPS)
URL:          http://www.cups.org/
Vendor:       Apple Inc.
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Print
License:      GPL/LGPL (with exceptions)
Version:      1.6.1
Release:      20120728

#   package options
%option       with_ssl   no

#   list of sources
Source0:      http://ftp.easysw.com/pub/cups/%{version}/cups-%{version}-source.tar.bz2
Source1:      rc.cups
Source2:      cupsd.conf
Patch0:       cups.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, make, gcc, gcc::with_cxx = yes
PreReq:       OpenPKG, openpkg >= 20160101
BuildPreReq:  zlib, jpeg, png, tiff
PreReq:       zlib, jpeg, png, tiff
%if "%{with_ssl}" == "yes"
BuildPreReq:  openssl
PreReq:       openssl
%endif

%description
    CUPS provides a portable printing layer for Unix-based operating
    systems. It has been developed to promote a standard printing
    solution for all Unix vendors and users. CUPS provides the System V
    and Berkeley command-line interfaces and uses the Internet Printing
    Protocol (IPP) as the basis for managing print jobs and queues.

%track
    prog cups = {
        version   = %{version}
        url       = http://www.cups.org/software.php
        regex     = cups-(\d+(\.\d+)+)-source\.tar\.bz2
    }

%prep
    %setup -q
    %patch -p0

%build
    CC="%{l_cc}" \
    CFLAGS="%{l_cflags -O} %{l_cppflags} -DPID_FILE='\"%{l_prefix}/var/cups/cupsd.pid\"'" \
    CPPFLAGS="%{l_cppflags} -DPID_FILE='\"%{l_prefix}/var/cups/cupsd.pid\"'" \
    LDFLAGS="%{l_ldflags}" \
    LIBS="-lz" \
    ./configure \
        --prefix=%{l_prefix} \
        --bindir=%{l_prefix}/libexec/cups \
        --sbindir=%{l_prefix}/libexec/cups \
        --mandir=%{l_prefix}/man \
        --with-docdir=%{l_prefix}/share/doc/cups \
        --localstatedir=%{l_prefix}/var/cups \
        --with-logdir=%{l_prefix}/var/cups/log \
        --with-rcdir='' \
        --sysconfdir=%{l_prefix}/etc \
        --with-cups-user=%{l_musr} \
        --with-cups-group=%{l_mgrp} \
        --disable-gssapi \
        --disable-slp \
%if "%{with_ssl}" == "yes"
        --enable-ssl \
        --with-openssl-includes=%{l_prefix}/include/openssl \
        --with-openssl-libs=%{l_prefix}/lib \
%else
        --disable-ssl \
%endif
        --disable-pam \
        --disable-shared \
        --without-java \
        --without-perl \
        --without-php \
        --without-python

    %{l_make} %{l_mflags -O}

%install

    #   install CUPS
    DSTROOT="$RPM_BUILD_ROOT" %{l_make} %{l_mflags} install

    #   make binaries accessable (they have been relocated since most of
    #   them are likely to cause name space conflicts)
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/bin
    for i in cups-config lp lpadmin lpc lpinfo lpmove lpoptions lpq lpr lprm \
        lpstat; do
        ln -s ../libexec/cups/$i $RPM_BUILD_ROOT%{l_prefix}/bin/$i
    done

    #   create run-command script
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d
    %{l_shtool} install -c -m 755 %{l_value -s -a} \
        %{SOURCE rc.cups} $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/

    #   provide default configuration
    %{l_shtool} install -c -m 644 %{l_value -s -a} \
        %{SOURCE cupsd.conf} $RPM_BUILD_ROOT%{l_prefix}/etc/cups/

    #   strip installation
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/man/cat*
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/locale
    for lang in de fr; do
        rm -rf $RPM_BUILD_ROOT%{l_prefix}/man/$lang                  || true
        rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/doc/cups/$lang       || true
        rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/cups/templates/$lang || true
    done

    #   generate file list
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std} \
        '%config %{l_prefix}/etc/cups/*'

%files -f files

%clean

%post
    #   after upgrade, restart service
    [ $1 -eq 2 ] || exit 0
    eval `%{l_rc} cups status 2>/dev/null`
    [ ".$cups_active" = .yes ] && %{l_rc} cups restart
    exit 0

%preun
    #   before erase, stop service and remove log files
    [ $1 -eq 0 ] || exit 0
    %{l_rc} cups stop 2>/dev/null
    rm -f $RPM_INSTALL_PREFIX/var/cups/log/* >/dev/null 2>&1 || true
    exit 0

