##
##  sendfile.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:         sendfile
Summary:      Simple Asynchronous File Transfer (SAFT)
URL:          http://fex.belwue.de/saft/sendfile.html
Vendor:       Ulli Horlacher
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        PLUS
Group:        Networking
License:      GPL
Version:      2.1b
Release:      20160405

#   list of sources
Source0:      http://fex.belwue.de/download/sendfile-%{version}.tar.gz
Source1:      sendfiledx.tar.gz
Source2:      sendfile.cf
Source3:      rc.sendfile
Patch0:       sendfile.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, gcc
PreReq:       OpenPKG, openpkg >= 20160101
BuildPreReq:  readline
PreReq:       readline

%description
    Sendfile is a Unix implementation of Simple Asynchronous File
    Transfer (SAFT) which can be used to asynchronously send/receive
    files over the Internet.

%track
    prog sendfile = {
        version   = %{version}
        url       = http://fex.belwue.de/saft/sendfile.html
        regex     = sendfile-(\d+\.\d+[a-z]?)\.tar\.gz
    }

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

%build
    #   configure program
    ./makeconfig \
        CC="%{l_cc}" \
        CFLAGS="\"%{l_cflags -O}\"" \
        CPPFLAGS="%{l_cppflags}" \
        LDFLAGS="%{l_ldflags}" \
        FIFODIR=%{l_prefix}/var/sendfile/run \
        SPOOL=%{l_prefix}/var/sendfile/spool \
        BINDIR=%{l_prefix}/bin \
        MANDIR=%{l_prefix}/man \
        CONFIG=%{l_prefix}/etc/sendfile \
        SERVERDIR=%{l_prefix}/sbin \
        TAR=%{l_tar} \
        GZIP=%{l_gzip} \
        BZIP2=%{l_bzip2} \
        PGP=%{l_prefix}/bin/pgp \
        RECODE=%{l_prefix}/bin/recode \
        METAMAIL=%{l_prefix}/bin/metamail \
        SENDMAIL=%{l_prefix}/sbin/sendmail

    #   build program
    %{l_make} %{l_mflags}

    #   build sendfiledx addon
    ( cd sendfiledx
      CC="%{l_cc}" \
      CFLAGS="%{l_cflags -O}" \
      ./configure
      %{l_make} %{l_mflags}
    ) || exit $?

%install
    #   create installation hierarchy
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/bin \
        $RPM_BUILD_ROOT%{l_prefix}/sbin \
        $RPM_BUILD_ROOT%{l_prefix}/man/man1 \
        $RPM_BUILD_ROOT%{l_prefix}/man/man7 \
        $RPM_BUILD_ROOT%{l_prefix}/man/man8 \
        $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d \
        $RPM_BUILD_ROOT%{l_prefix}/etc/sendfile \
        $RPM_BUILD_ROOT%{l_prefix}/var/sendfile/spool \
        $RPM_BUILD_ROOT%{l_prefix}/var/sendfile/spool/OUTGOING \
        $RPM_BUILD_ROOT%{l_prefix}/var/sendfile/spool/LOG \
        $RPM_BUILD_ROOT%{l_prefix}/var/sendfile/run

    #   install programs
    ( cd src
      %{l_shtool} install -c -s -m 755 \
          fetchfile receive sendfile sendmsg utf7encode wlock \
          $RPM_BUILD_ROOT%{l_prefix}/bin/
      %{l_shtool} install -c -s -m 755 \
          sendfiled $RPM_BUILD_ROOT%{l_prefix}/sbin/
    ) || exit $?
    ( cd etc
      %{l_shtool} install -c -m 755 \
          check_sendfile sf_cleanup sfconf sfdconf \
          $RPM_BUILD_ROOT%{l_prefix}/bin/
    ) || exit $?
    %{l_shtool} install -c -s -m 755 \
        sendfiledx/sendfiledx $RPM_BUILD_ROOT%{l_prefix}/sbin/
    ln $RPM_BUILD_ROOT%{l_prefix}/bin/utf7encode \
       $RPM_BUILD_ROOT%{l_prefix}/bin/utf7decode
    ln $RPM_BUILD_ROOT%{l_prefix}/bin/receive \
       $RPM_BUILD_ROOT%{l_prefix}/bin/rf
    ln $RPM_BUILD_ROOT%{l_prefix}/bin/sendfile \
       $RPM_BUILD_ROOT%{l_prefix}/bin/sf
    ln $RPM_BUILD_ROOT%{l_prefix}/bin/sendmsg \
       $RPM_BUILD_ROOT%{l_prefix}/bin/sm

    #   install manual pages
    %{l_shtool} install -c -m 755 \
        doc/*.1 $RPM_BUILD_ROOT%{l_prefix}/man/man1/
    %{l_shtool} install -c -m 755 \
        doc/*.7 $RPM_BUILD_ROOT%{l_prefix}/man/man7/
    %{l_shtool} install -c -m 755 \
        doc/*.8 $RPM_BUILD_ROOT%{l_prefix}/man/man8/

    #   install default configuration
    %{l_shtool} install -c -m 644 %{l_value -s -a} \
        %{SOURCE sendfile.cf} $RPM_BUILD_ROOT%{l_prefix}/etc/sendfile/
    %{l_shtool} install -c -m 644 \
        etc/sendfile.deny $RPM_BUILD_ROOT%{l_prefix}/etc/sendfile/

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

    #   determine installation files
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%config %{l_prefix}/etc/sendfile/*'

%files -f files

%clean

