##
##  csync.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:         csync
Summary:      Bidirectional Filesystem Synchronisation
URL:          http://www.csync.org/
Vendor:       Andreas Schneider
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Filesystem
License:      GPL
Version:      20150605
Release:      20150605

#   list of sources
Source0:      http://download.openpkg.org/components/versioned/csync/csync-%{version}.tar.xz
Patch0:       csync.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, cmake
PreReq:       OpenPKG, openpkg >= 20160101
BuildPreReq:  log4c, check, sqlite, iniparser, libsmbclient, argp, libssh2
PreReq:       log4c, check, sqlite, iniparser, libsmbclient, argp, libssh2

%description
    CSync is a lightweight utility to synchronize files between two
    directories on a system or between multiple systems. It synchronizes
    bidirectionally and allows the user to keep two copies of files and
    directories in sync. CSync uses widely adopted protocols, such as
    SMB or SFTP, so that there is no need for a server component. It is
    a user-level program which means you don’t need to be a superuser
    or administrator.

%track
    prog csync = {
        version   = %{version}
        url       = http://www.csync.org/files/
        regex     = csync-(__VER__)\.tar\.gz
    }

%prep
    %setup -q -n csync
    %patch -p0

%build
    cd build
    cmake \
        -DCMAKE_BUILD_TYPE="Release" \
        -DCMAKE_INSTALL_PREFIX="%{l_prefix}" \
        -DINFO_INSTALL_DIR="%{l_prefix}/info" \
        -DMAN_INSTALL_DIR="%{l_prefix}/man" \
        -DLIBEXEC_INSTALL_DIR="%{l_prefix}/libexec/csync" \
        -DLIB_INSTALL_DIR="%{l_prefix}/lib/csync" \
        -DCMAKE_C_COMPILER="%{l_cc}" \
        -DCMAKE_C_FLAGS="%{l_cflags} %{l_cppflags}" \
        -DCMAKE_EXE_LINKER_FLAGS="%{l_ldflags}" \
        -DCLIENT_LINK_LIBRARIES="%{l_prefix}/lib/libargp.a" \
        -DCMAKE_CXX_COMPILER="%{l_cxx}" \
        -DINIPARSER_INCLUDE_DIRS="%{l_prefix}/include/iniparser" \
        -DSQLITE3_INCLUDE_DIRS="%{l_prefix}/include" \
        -DSQLITE3_LIBRARY="%{l_prefix}/lib/libsqlite3.a" \
        -DLIBSSH_INCLUDE_DIRS="%{l_prefix}/include/libssh" \
        ..
    %{l_make} %{l_mflags}

%install
    ( cd build
      %{l_make} %{l_mflags} install DESTDIR=$RPM_BUILD_ROOT
    ) || exit $?
    strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/include/csync
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/doc
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/libexec/csync
    mv  $RPM_BUILD_ROOT%{l_prefix}/bin/csync \
        $RPM_BUILD_ROOT%{l_prefix}/libexec/csync/
    ( echo "#!/bin/sh"
      echo "LD_LIBRARY_PATH=\"%{l_prefix}/lib/csync\""
      echo "export LD_LIBRARY_PATH"
      echo "exec %{l_prefix}/libexec/csync/csync \${1+\"\$@\"}"
    ) >$RPM_BUILD_ROOT%{l_prefix}/bin/csync
    chmod a+x $RPM_BUILD_ROOT%{l_prefix}/bin/csync
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%config %{l_prefix}/etc/csync/*'

%files -f files

%clean

