#-------------------------------------------------------------------------------
# Helper macros
#-------------------------------------------------------------------------------
%if %{?rhel:1}%{!?rhel:0}
    %if %{rhel} >= 7
        %define use_systemd 1
        %define have_macaroons 1
    %else
        %define use_systemd 0
        %define have_macaroons 0
    %endif
%else
    %if %{?fedora}%{!?fedora:0} >= 28
        %define have_macaroons 1
    %else
        %define have_macaroons 0
    %endif
    %if %{?fedora}%{!?fedora:0} >= 19
        %define use_systemd 1
    %else
        %define use_systemd 0
    %endif
%endif

%if %{?fedora}%{!?fedora:0} >= 22
    %define use_libc_semaphore 1
%else
    %define use_libc_semaphore 0
%endif

%if %{?_with_ceph11:1}%{!?_with_ceph11:0}
    %define _with_ceph 1
%endif

# Remove default rpm python bytecompiling scripts
%global __os_install_post \
    %(echo '%{__os_install_post}' | \
      sed -e 's!/usr/lib[^[:space:]]*/brp-python-bytecompile[[:space:]].*$!!g \
              s!/usr/lib[^[:space:]]*/brp-python-hardlink[[:space:]].*$!!g')

#-------------------------------------------------------------------------------
# Package definitions
#-------------------------------------------------------------------------------
Name:      xrootd
Epoch:     1
Version:   __VERSION__
Release:   __RELEASE__%{?dist}%{?_with_clang:.clang}%{?_with_asan:.asan}
Summary:   Extended ROOT file server
Group:     System Environment/Daemons
License:   LGPLv3+
URL:       http://xrootd.org/

# git clone http://xrootd.org/repo/xrootd.git xrootd
# cd xrootd
# git-archive master | gzip -9 > ~/rpmbuild/SOURCES/xrootd.tgz
Source0:   xrootd.tar.gz

%if %{?_with_compat:1}%{!?_with_compat:0}
Source1:   xrootd-3.3.6.tar.gz
%endif

BuildRoot: %{_tmppath}/%{name}-root

BuildRequires: cmake
BuildRequires: krb5-devel
BuildRequires: readline-devel
BuildRequires: fuse-devel
BuildRequires: libxml2-devel
BuildRequires: krb5-devel
BuildRequires: zlib-devel
BuildRequires: ncurses-devel
BuildRequires: libcurl-devel
BuildRequires: libuuid-devel
%if %{have_macaroons}
BuildRequires: libmacaroons-devel
%endif
BuildRequires: json-c-devel

BuildRequires: python2-devel
%if %{?fedora}%{!?fedora:0} >= 13
BuildRequires: python3-devel
%else
BuildRequires: python%{python3_pkgversion}-devel
%endif

BuildRequires: openssl-devel

BuildRequires: selinux-policy-devel

%if %{?_with_tests:1}%{!?_with_tests:0}
BuildRequires: cppunit-devel
%endif

%if %{?_with_ceph:1}%{!?_with_ceph:0}
    %if %{?_with_ceph11:1}%{!?_with_ceph11:0}
BuildRequires: librados-devel >= 11.0
BuildRequires: libradosstriper-devel >= 11.0
    %else
BuildRequires: ceph-devel >= 0.87
    %endif
%endif

BuildRequires:	doxygen
BuildRequires:	graphviz
%if %{?rhel}%{!?rhel:0} == 5
BuildRequires:	graphviz-gd
%endif

%if %{?_with_clang:1}%{!?_with_clang:0}
BuildRequires: clang
%endif

%if %{?_with_asan:1}%{!?_with_asan:0}
BuildRequires: libasan
Requires: libasan
%endif

Requires:	%{name}-server%{?_isa} = %{epoch}:%{version}-%{release}
Requires:	%{name}-selinux = %{epoch}:%{version}-%{release}

%if %{use_systemd}
BuildRequires:    systemd
BuildRequires:    systemd-devel
Requires(pre):		systemd
Requires(post):		systemd
Requires(preun):	systemd
Requires(postun):	systemd
%else
Requires(pre):		shadow-utils
Requires(pre):		chkconfig
Requires(post):		chkconfig
Requires(preun):	chkconfig
Requires(preun):	initscripts
Requires(postun):	initscripts
%endif

%description
The Extended root file server consists of a file server called xrootd
and a cluster management server called cmsd.

The xrootd server was developed for the root analysis framework to
serve root files. However, the server is agnostic to file types and
provides POSIX-like access to any type of file.

The cmsd server is the next generation version of the olbd server,
originally developed to cluster and load balance Objectivity/DB AMS
database servers. It provides enhanced capability along with lower
latency and increased throughput.

#-------------------------------------------------------------------------------
# libs
#-------------------------------------------------------------------------------
%package libs
Summary:	Libraries used by xrootd servers and clients
Group:		System Environment/Libraries

%description libs
This package contains libraries used by the xrootd servers and clients.

#-------------------------------------------------------------------------------
# devel
#------------------------------------------------------------------------------
%package devel
Summary:	Development files for xrootd
Group:		Development/Libraries
Requires:	%{name}-libs%{?_isa} = %{epoch}:%{version}-%{release}

%description devel
This package contains header files and development libraries for xrootd
development.

#-------------------------------------------------------------------------------
# client-libs
#-------------------------------------------------------------------------------
%package client-libs
Summary:	Libraries used by xrootd clients
Group:		System Environment/Libraries
Requires:	%{name}-libs%{?_isa} = %{epoch}:%{version}-%{release}
%if %{use_libc_semaphore}
Requires:       glibc >= 2.21
%endif

%description client-libs
This package contains libraries used by xrootd clients.

#-------------------------------------------------------------------------------
# client-devel
#-------------------------------------------------------------------------------
%package client-devel
Summary:	Development files for xrootd clients
Group:		Development/Libraries
Requires:	%{name}-devel%{?_isa} = %{epoch}:%{version}-%{release}
Requires:	%{name}-client-libs%{?_isa} = %{epoch}:%{version}-%{release}

%description client-devel
This package contains header files and development libraries for xrootd
client development.

#-------------------------------------------------------------------------------
# server-libs
#-------------------------------------------------------------------------------
%package server-libs
Summary:	Libraries used by xrootd servers
Group:		System Environment/Libraries
Requires:	%{name}-libs%{?_isa} = %{epoch}:%{version}-%{release}
Requires:	%{name}-client-libs%{?_isa} = %{epoch}:%{version}-%{release}
Obsoletes:  xrootd-macaroons
Obsoletes:  xrootd-tpc

%description server-libs
This package contains libraries used by xrootd servers.

#-------------------------------------------------------------------------------
# server-devel
#-------------------------------------------------------------------------------
%package server-devel
Summary:	Development files for xrootd servers
Group:		Development/Libraries
Requires:	%{name}-devel%{?_isa} = %{epoch}:%{version}-%{release}
Requires:	%{name}-client-devel%{?_isa} = %{epoch}:%{version}-%{release}
Requires:	%{name}-server-libs%{?_isa} = %{epoch}:%{version}-%{release}

%description server-devel
This package contains header files and development libraries for xrootd
server development.

#-------------------------------------------------------------------------------
# private devel
#-------------------------------------------------------------------------------
%package private-devel
Summary:	Legacy xrootd headers
Group:		Development/Libraries
Requires:	%{name}-libs = %{epoch}:%{version}-%{release}

%description private-devel
This package contains some private xrootd headers. The use of these
headers is strongly discouraged. Backward compatibility between
versions is not guaranteed for these headers.

#-------------------------------------------------------------------------------
# client
#-------------------------------------------------------------------------------
%package client
Summary:	Xrootd command line client tools
Group:		Applications/Internet
Requires:	%{name}-libs%{?_isa} = %{epoch}:%{version}-%{release}
Requires:	%{name}-client-libs%{?_isa} = %{epoch}:%{version}-%{release}

%description client
This package contains the command line tools used to communicate with
xrootd servers.

#-------------------------------------------------------------------------------
# server
#-------------------------------------------------------------------------------
%package server
Summary:   Extended ROOT file server
Group:     System Environment/Daemons
Requires:  %{name}-libs        = %{epoch}:%{version}-%{release}
Requires:  %{name}-client-libs = %{epoch}:%{version}-%{release}
Requires:  %{name}-server-libs = %{epoch}:%{version}-%{release}
Requires:  expect

%description server
XRootD server binaries

#-------------------------------------------------------------------------------
# fuse
#-------------------------------------------------------------------------------
%package fuse
Summary:	Xrootd FUSE tool
Group:		Applications/Internet
Requires:	%{name}-libs%{?_isa} = %{epoch}:%{version}-%{release}
Requires:	%{name}-client-libs%{?_isa} = %{epoch}:%{version}-%{release}
Requires:	fuse

%description fuse
This package contains the FUSE (file system in user space) xrootd mount
tool.

#-------------------------------------------------------------------------------
# python2
#-------------------------------------------------------------------------------
%package -n python2-%{name}
Summary:       Python 2 bindings for XRootD
Group:         Development/Libraries
%if %{?fedora}%{!?fedora:0} >= 13
%{?python_provide:%python_provide python2-%{name}}
%else
Provides:      python-%{name}
%endif
Provides:      %{name}-python = %{epoch}:%{version}-%{release}
Obsoletes:     %{name}-python < 1:4.8.0-1
Requires:      %{name}-client-libs%{?_isa} = %{epoch}:%{version}-%{release}

%description -n python2-xrootd
Python 2 bindings for XRootD

%if %{?_with_python3:1}%{!?_with_python3:0}
#-------------------------------------------------------------------------------
# python3
#-------------------------------------------------------------------------------
%package -n python3-%{name}
Summary:       Python 3 bindings for XRootD
Group:         Development/Libraries
%if %{?fedora}%{!?fedora:0} >= 13
%{?python_provide:%python_provide python3-%{name}}
%endif
Requires:      %{name}-client-libs%{?_isa} = %{epoch}:%{version}-%{release}

%description -n python3-xrootd
Python 3 bindings for XRootD
%endif

#-------------------------------------------------------------------------------
# doc
#-------------------------------------------------------------------------------
%package doc
Summary:	Developer documentation for the xrootd libraries
Group:		Documentation
%if %{?fedora}%{!?fedora:0} >= 10 || %{?rhel}%{!?rhel:0} >= 6
BuildArch:	noarch
%endif

%description doc
This package contains the API documentation of the xrootd libraries.

#-------------------------------------------------------------------------------
# selinux
#-------------------------------------------------------------------------------
%package selinux
Summary:	 SELinux policy extensions for xrootd.
Group:		 System Environment/Base
%if %{?fedora}%{!?fedora:0} >= 10 || %{?rhel}%{!?rhel:0} >= 6
BuildArch: noarch
%endif
Requires(post):   policycoreutils
Requires(postun): policycoreutils
Requires:         selinux-policy

%description selinux
SELinux policy extensions for running xrootd while in enforcing mode.

#-------------------------------------------------------------------------------
# ceph
#-------------------------------------------------------------------------------
%if %{?_with_ceph:1}%{!?_with_ceph:0}
%package ceph
Summary: Ceph back-end plug-in for XRootD
Group:   Development/Tools
Requires: %{name}-server = %{epoch}:%{version}-%{release}
%description ceph
Ceph back-end plug-in for XRootD.
%endif

#-------------------------------------------------------------------------------
# tests
#-------------------------------------------------------------------------------
%if %{?_with_tests:1}%{!?_with_tests:0}
%package tests
Summary: CPPUnit tests
Group:   Development/Tools
Requires: %{name}-client = %{epoch}:%{version}-%{release}
%description tests
This package contains a set of CPPUnit tests for xrootd.
%endif

%if %{?_with_compat:1}%{!?_with_compat:0}
#-------------------------------------------------------------------------------
# client-compat
#-------------------------------------------------------------------------------
%package client-compat
Summary:	XRootD 3 compatibility client libraries
Group:		System Environment/Libraries

%description client-compat
This package contains compatibility libraries for xrootd 3 clients.

#-------------------------------------------------------------------------------
# server-compat
#-------------------------------------------------------------------------------
%package server-compat
Summary:	XRootD 3 compatibility server binaries
Group:		System Environment/Daemons
Requires:	%{name}-libs%{?_isa} = %{epoch}:%{version}-%{release}

%description server-compat
This package contains compatibility binaries for xrootd 3 servers.

%endif

#-------------------------------------------------------------------------------
# Build instructions
#-------------------------------------------------------------------------------
%prep
%setup -c -n xrootd

%if %{?_with_compat:1}%{!?_with_compat:0}
%setup -T -D -n %{name} -a 1
%endif

%build
cd xrootd

%if %{?_with_clang:1}%{!?_with_clang:0}
export CC=clang
export CXX=clang++
%endif

%if %{?_with_asan:1}%{!?_with_asan:0}
export CXXFLAGS='-fsanitize=address'
%endif

mkdir build
pushd build
cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=RelWithDebInfo \
%if %{?_with_tests:1}%{!?_with_tests:0}
      -DENABLE_TESTS=TRUE \
%else
      -DENABLE_TESTS=FALSE \
%endif
%if %{?_with_ceph:1}%{!?_with_ceph:0}
      -DENABLE_CEPH=TRUE \
%else
      -DENABLE_CEPH=FALSE \
%endif
      -DUSE_LIBC_SEMAPHORE=%{use_libc_semaphore} ../

make -i VERBOSE=1 %{?_smp_mflags}
popd

pushd packaging/common
make -f /usr/share/selinux/devel/Makefile
popd

doxygen Doxyfile

%if %{?_with_compat:1}%{!?_with_compat:0}
pushd ../xrootd-3.3.6
mkdir build
pushd build
cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=RelWithDebInfo -DENABLE_PERL=FALSE ../
make VERBOSE=1 %{?_smp_mflags}
popd
popd
%endif

%if %{?_with_python3:1}%{!?_with_python3:0}
# build python3 bindings
pushd build/bindings/python
%py3_build
popd
%endif

#-------------------------------------------------------------------------------
# Installation
#-------------------------------------------------------------------------------
%install
rm -rf $RPM_BUILD_ROOT

#-------------------------------------------------------------------------------
# Install 3.3.6 compat
#-------------------------------------------------------------------------------
%if %{?_with_compat:1}%{!?_with_compat:0}
pushd xrootd-3.3.6/build
make install DESTDIR=$RPM_BUILD_ROOT
rm -rf $RPM_BUILD_ROOT%{_includedir}
rm -rf $RPM_BUILD_ROOT%{_datadir}
rm -f $RPM_BUILD_ROOT%{_bindir}/{cconfig,cns_ssi,frm_admin,frm_xfragent,mpxstats}
rm -f $RPM_BUILD_ROOT%{_bindir}/{wait41,xprep,xrd,xrdadler32,XrdCnsd,xrdcopy}
rm -f $RPM_BUILD_ROOT%{_bindir}/{xrdcp,xrdcp-old,xrdfs,xrdgsiproxy,xrdpwdadmin}
rm -f $RPM_BUILD_ROOT%{_bindir}/{xrdqstats,xrdsssadmin,xrdstagetool,xrootdfs}
rm -f $RPM_BUILD_ROOT%{_libdir}/libXrdAppUtils.so
rm -f $RPM_BUILD_ROOT%{_libdir}/{libXrdClient.so,libXrdCl.so,libXrdCryptoLite.so}
rm -f $RPM_BUILD_ROOT%{_libdir}/{libXrdCrypto.so,libXrdFfs.so,libXrdMain.so}
rm -f $RPM_BUILD_ROOT%{_libdir}/{libXrdOfs.so,libXrdPosixPreload.so,libXrdPosix.so}
rm -f $RPM_BUILD_ROOT%{_libdir}/{libXrdServer.so,libXrdUtils.so}

for i in cmsd frm_purged frm_xfrd xrootd; do
  mv $RPM_BUILD_ROOT%{_bindir}/$i $RPM_BUILD_ROOT%{_bindir}/${i}-3
done
popd
%endif

#-------------------------------------------------------------------------------
# Install 4.x.y
#-------------------------------------------------------------------------------
pushd xrootd
pushd  build
make install DESTDIR=$RPM_BUILD_ROOT
cat PYTHON_INSTALLED | sed -e "s|$RPM_BUILD_ROOT||g" > PYTHON_INSTALLED_FILES
popd

# configuration stuff
rm -rf $RPM_BUILD_ROOT%{_sysconfdir}/xrootd/*

# ceph posix unversioned so
rm -f $RPM_BUILD_ROOT%{_libdir}/libXrdCephPosix.so

# config paths
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/%{name}/config.d/

# var paths
mkdir -p $RPM_BUILD_ROOT%{_var}/log/xrootd
mkdir -p $RPM_BUILD_ROOT%{_var}/run/xrootd
mkdir -p $RPM_BUILD_ROOT%{_var}/spool/xrootd

# init stuff
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/xrootd

%if %{use_systemd}

mkdir -p $RPM_BUILD_ROOT%{_unitdir}
install -m 644 packaging/common/xrootd@.service $RPM_BUILD_ROOT%{_unitdir}
install -m 644 packaging/common/xrdhttp@.socket   $RPM_BUILD_ROOT%{_unitdir}
install -m 644 packaging/common/xrootd@.socket    $RPM_BUILD_ROOT%{_unitdir}
install -m 644 packaging/common/cmsd@.service $RPM_BUILD_ROOT%{_unitdir}
install -m 644 packaging/common/frm_xfrd@.service $RPM_BUILD_ROOT%{_unitdir}
install -m 644 packaging/common/frm_purged@.service $RPM_BUILD_ROOT%{_unitdir}

# tmpfiles.d
mkdir -p $RPM_BUILD_ROOT%{_tmpfilesdir}
install -m 0644 packaging/rhel/xrootd.tmpfiles $RPM_BUILD_ROOT%{_tmpfilesdir}/%{name}.conf

%else

mkdir -p $RPM_BUILD_ROOT%{_initrddir}
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig
install -m 644 packaging/rhel/xrootd.sysconfig $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/xrootd

install -m 755 packaging/rhel/cmsd.init $RPM_BUILD_ROOT%{_initrddir}/cmsd
install -m 755 packaging/rhel/frm_purged.init $RPM_BUILD_ROOT%{_initrddir}/frm_purged
install -m 755 packaging/rhel/frm_xfrd.init $RPM_BUILD_ROOT%{_initrddir}/frm_xfrd
install -m 755 packaging/rhel/xrootd.init $RPM_BUILD_ROOT%{_initrddir}/xrootd
install -m 755 packaging/rhel/xrootd.functions $RPM_BUILD_ROOT%{_initrddir}/xrootd.functions

%endif

# logrotate
mkdir $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d
install -p -m 644 packaging/common/xrootd.logrotate $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/xrootd

install -m 644 packaging/common/xrootd-clustered.cfg $RPM_BUILD_ROOT%{_sysconfdir}/xrootd/xrootd-clustered.cfg
install -m 644 packaging/common/xrootd-standalone.cfg $RPM_BUILD_ROOT%{_sysconfdir}/xrootd/xrootd-standalone.cfg
install -m 644 packaging/common/xrootd-filecache-clustered.cfg $RPM_BUILD_ROOT%{_sysconfdir}/xrootd/xrootd-filecache-clustered.cfg
install -m 644 packaging/common/xrootd-filecache-standalone.cfg $RPM_BUILD_ROOT%{_sysconfdir}/xrootd/xrootd-filecache-standalone.cfg
%if %{use_systemd}
install -m 644 packaging/common/xrootd-http.cfg $RPM_BUILD_ROOT%{_sysconfdir}/xrootd/xrootd-http.cfg
%endif

# client plug-in config
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/xrootd/client.plugins.d
install -m 644 packaging/common/client-plugin.conf.example $RPM_BUILD_ROOT%{_sysconfdir}/xrootd/client.plugins.d/client-plugin.conf.example

# client config
install -m 644 packaging/common/client.conf $RPM_BUILD_ROOT%{_sysconfdir}/xrootd/client.conf

# documentation
mkdir -p %{buildroot}%{_docdir}/%{name}-%{version}
cp -pr doxydoc/html %{buildroot}%{_docdir}/%{name}-%{version}

# selinux
mkdir -p %{buildroot}%{_datadir}/selinux/packages/%{name}
install -m 644 -p packaging/common/xrootd.pp \
    %{buildroot}%{_datadir}/selinux/packages/%{name}/%{name}.pp

%if %{?_with_python3:1}%{!?_with_python3:0}
# install python3 bindings
pushd build/bindings/python
%py3_install
popd
%endif

%clean
rm -rf $RPM_BUILD_ROOT

#-------------------------------------------------------------------------------
# RPM scripts
#-------------------------------------------------------------------------------
%post   libs -p /sbin/ldconfig
%postun libs -p /sbin/ldconfig

%post   client-libs -p /sbin/ldconfig
%postun client-libs -p /sbin/ldconfig

%post   server-libs -p /sbin/ldconfig
%postun server-libs -p /sbin/ldconfig

%pre server

getent group xrootd >/dev/null || groupadd -r xrootd
getent passwd xrootd >/dev/null || \
       useradd -r -g xrootd -c "XRootD runtime user" \
       -s /sbin/nologin -d %{_localstatedir}/spool/xrootd xrootd
exit 0

%if %{use_systemd}

%post server
if [ $1 -eq 1 ] ; then
    /usr/bin/systemctl daemon-reload >/dev/null 2>&1 || :
fi

%preun server
if [ $1 -eq 0 ] ; then
    for DAEMON in xrootd cmsd frm_purged frm xfrd; do
        for INSTANCE in `/usr/bin/systemctl | grep $DAEMON@ | awk '{print $1;}'`; do
            /usr/bin/systemctl --no-reload disable $INSTANCE > /dev/null 2>&1 || :
            /usr/bin/systemctl stop $INSTANCE > /dev/null 2>&1 || :
        done
    done
fi

%postun server
if [ $1 -ge 1 ] ; then
    /usr/bin/systemctl daemon-reload >/dev/null 2>&1 || :
    for DAEMON in xrootd cmsd frm_purged frm xfrd; do
        for INSTANCE in `/usr/bin/systemctl | grep $DAEMON@ | awk '{print $1;}'`; do
            /usr/bin/systemctl try-restart $INSTANCE >/dev/null 2>&1 || :
        done
    done
fi

%else

%post server
if [ $1 -eq 1 ]; then
    /sbin/chkconfig --add xrootd
    /sbin/chkconfig --add cmsd
    /sbin/chkconfig --add frm_purged
    /sbin/chkconfig --add frm_xfrd
fi

%preun server
if [ $1 -eq 0 ]; then
    /sbin/service xrootd stop >/dev/null 2>&1 || :
    /sbin/service cmsd stop >/dev/null 2>&1 || :
    /sbin/service frm_purged stop >/dev/null 2>&1 || :
    /sbin/service frm_xfrd stop >/dev/null 2>&1 || :
    /sbin/chkconfig --del xrootd
    /sbin/chkconfig --del cmsd
    /sbin/chkconfig --del frm_purged
    /sbin/chkconfig --del frm_xfrd
fi

%postun server
if [ $1 -ge 1 ]; then
    /sbin/service xrootd condrestart >/dev/null 2>&1 || :
    /sbin/service cmsd condrestart >/dev/null 2>&1 || :
    /sbin/service frm_purged condrestart >/dev/null 2>&1 || :
    /sbin/service frm_xfrd condrestart >/dev/null 2>&1 || :
fi

%endif

#-------------------------------------------------------------------------------
# Add a new user and group if necessary
#-------------------------------------------------------------------------------
%pre fuse
getent group xrootd >/dev/null || groupadd -r xrootd
getent passwd xrootd >/dev/null || \
       useradd -r -g xrootd -c "XRootD runtime user" \
       -s /sbin/nologin -d %{_localstatedir}/spool/xrootd xrootd
exit 0

#-------------------------------------------------------------------------------
# Selinux
#-------------------------------------------------------------------------------
%post selinux
/usr/sbin/semodule -i %{_datadir}/selinux/packages/%{name}/%{name}.pp >/dev/null 2>&1 || :

%postun selinux
if [ $1 -eq 0 ] ; then
    /usr/sbin/semodule -r %{name} >/dev/null 2>&1 || :
fi

#-------------------------------------------------------------------------------
# Files
#-------------------------------------------------------------------------------
%files
# empty

%files server
%defattr(-,root,root,-)
%{_bindir}/cconfig
%{_bindir}/cmsd
%{_bindir}/cns_ssi
%{_bindir}/frm_admin
%{_bindir}/frm_purged
%{_bindir}/frm_xfragent
%{_bindir}/frm_xfrd
%{_bindir}/mpxstats
%{_bindir}/wait41
%{_bindir}/XrdCnsd
%{_bindir}/xrdpwdadmin
%{_bindir}/xrdsssadmin
%{_bindir}/xrdmapc
%{_bindir}/xrootd
%{_bindir}/xrdpfc_print
%{_bindir}/xrdacctest
%{_mandir}/man8/cmsd.8*
%{_mandir}/man8/cns_ssi.8*
%{_mandir}/man8/frm_admin.8*
%{_mandir}/man8/frm_purged.8*
%{_mandir}/man8/frm_xfragent.8*
%{_mandir}/man8/frm_xfrd.8*
%{_mandir}/man8/mpxstats.8*
%{_mandir}/man8/XrdCnsd.8*
%{_mandir}/man8/xrdpwdadmin.8*
%{_mandir}/man8/xrdsssadmin.8*
%{_mandir}/man8/xrootd.8*
%{_mandir}/man8/xrdpfc_print.8*
%{_datadir}/xrootd
%attr(-,xrootd,xrootd) %config(noreplace) %{_sysconfdir}/xrootd/xrootd-clustered.cfg
%attr(-,xrootd,xrootd) %config(noreplace) %{_sysconfdir}/xrootd/xrootd-standalone.cfg
%attr(-,xrootd,xrootd) %config(noreplace) %{_sysconfdir}/xrootd/xrootd-filecache-clustered.cfg
%attr(-,xrootd,xrootd) %config(noreplace) %{_sysconfdir}/xrootd/xrootd-filecache-standalone.cfg
%if %{use_systemd}
%attr(-,xrootd,xrootd) %config(noreplace) %{_sysconfdir}/xrootd/xrootd-http.cfg
%endif
%attr(-,xrootd,xrootd) %dir %{_var}/log/xrootd
%attr(-,xrootd,xrootd) %dir %{_var}/run/xrootd
%attr(-,xrootd,xrootd) %dir %{_var}/spool/xrootd
%attr(-,xrootd,xrootd) %dir %{_sysconfdir}/%{name}/config.d
%config(noreplace) %{_sysconfdir}/logrotate.d/xrootd

%if %{use_systemd}
%{_unitdir}/*
%{_tmpfilesdir}/%{name}.conf
%else
%config(noreplace) %{_sysconfdir}/sysconfig/xrootd
%{_initrddir}/*
%endif

%files libs
%defattr(-,root,root,-)
%{_libdir}/libXrdAppUtils.so.1*
%{_libdir}/libXrdClProxyPlugin-4.so
%{_libdir}/libXrdCks*-4.so
%{_libdir}/libXrdCrypto.so.1*
%{_libdir}/libXrdCryptoLite.so.1*
%{_libdir}/libXrdCryptossl-4.so
%{_libdir}/libXrdSec*-4.so
%{_libdir}/libXrdUtils.so.*
%{_libdir}/libXrdXml.so.*

%files devel
%defattr(-,root,root,-)
%dir %{_includedir}/xrootd
%{_bindir}/xrootd-config
%{_includedir}/xrootd/XProtocol
%{_includedir}/xrootd/Xrd
%{_includedir}/xrootd/XrdCks
%{_includedir}/xrootd/XrdNet
%{_includedir}/xrootd/XrdOuc
%{_includedir}/xrootd/XrdSec
%{_includedir}/xrootd/XrdSys
%{_includedir}/xrootd/XrdVersion.hh
%{_libdir}/libXrdAppUtils.so
%{_libdir}/libXrdCrypto.so
%{_libdir}/libXrdCryptoLite.so
%{_libdir}/libXrdUtils.so
%{_libdir}/libXrdXml.so
%{_includedir}/xrootd/XrdXml/XrdXmlReader.hh

%files client-libs
%defattr(-,root,root,-)
%{_libdir}/libXrdCl.so.2*
%{_libdir}/libXrdClient.so.2*
%{_libdir}/libXrdFfs.so.2*
%{_libdir}/libXrdPosix.so.2*
%{_libdir}/libXrdPosixPreload.so.1*
%{_sysconfdir}/xrootd/client.plugins.d/client-plugin.conf.example
%config(noreplace) %{_sysconfdir}/xrootd/client.conf
# This lib may be used for LD_PRELOAD so the .so link needs to be included
%{_libdir}/libXrdPosixPreload.so

%files client-devel
%defattr(-,root,root,-)
%{_bindir}/xrdgsitest
%{_includedir}/xrootd/XrdCl
%{_includedir}/xrootd/XrdClient
%{_includedir}/xrootd/XrdPosix
%{_libdir}/libXrdCl.so
%{_libdir}/libXrdClient.so
%{_libdir}/libXrdFfs.so
%{_libdir}/libXrdPosix.so
%{_mandir}/man1/xrdgsitest.1*

%files server-libs
%defattr(-,root,root,-)
%{_libdir}/libXrdBwm-4.so
%{_libdir}/libXrdPss-4.so
%{_libdir}/libXrdXrootd-4.so
%{_libdir}/libXrdFileCache-4.so
%{_libdir}/libXrdBlacklistDecision-4.so
%{_libdir}/libXrdHttp-4.so
%{_libdir}/libXrdHttpTPC-4.so
%{_libdir}/libXrdHttpUtils.so.*
%if %{have_macaroons}
%{_libdir}/libXrdMacaroons-4.so
%endif
%{_libdir}/libXrdN2No2p-4.so
%{_libdir}/libXrdOssSIgpfsT-4.so
%{_libdir}/libXrdServer.so.*
%{_libdir}/libXrdSsi-4.so
%{_libdir}/libXrdSsiLib.so.*
%{_libdir}/libXrdSsiLog-4.so
%{_libdir}/libXrdSsiShMap.so.*
%{_libdir}/libXrdThrottle-4.so

%files server-devel
%defattr(-,root,root,-)
%{_includedir}/xrootd/XrdAcc
%{_includedir}/xrootd/XrdCms
%{_includedir}/xrootd/XrdFileCache
%{_includedir}/xrootd/XrdOss
%{_includedir}/xrootd/XrdSfs
%{_includedir}/xrootd/XrdXrootd
%{_includedir}/xrootd/XrdHttp
%{_libdir}/libXrdServer.so
%{_libdir}/libXrdHttpUtils.so

%files private-devel
%defattr(-,root,root,-)
%{_includedir}/xrootd/private
%{_libdir}/libXrdSsiLib.so
%{_libdir}/libXrdSsiShMap.so

%files client
%defattr(-,root,root,-)
%{_bindir}/xprep
%{_bindir}/xrd
%{_bindir}/xrdadler32
%{_bindir}/xrdcopy
%{_bindir}/xrdcp
%{_bindir}/xrdcp-old
%{_bindir}/xrdfs
%{_bindir}/xrdgsiproxy
%{_bindir}/xrdstagetool
%{_mandir}/man1/xprep.1*
%{_mandir}/man1/xrd.1*
%{_mandir}/man1/xrdadler32.1*
%{_mandir}/man1/xrdcopy.1*
%{_mandir}/man1/xrdcp.1*
%{_mandir}/man1/xrdcp-old.1*
%{_mandir}/man1/xrdfs.1*
%{_mandir}/man1/xrdgsiproxy.1*
%{_mandir}/man1/xrdstagetool.1*

%files fuse
%defattr(-,root,root,-)
%{_bindir}/xrootdfs
%{_mandir}/man1/xrootdfs.1*
%dir %{_sysconfdir}/xrootd

%files -n python2-%{name} -f xrootd/build/PYTHON_INSTALLED_FILES
%defattr(-,root,root,-)

%if %{?_with_python3:1}%{!?_with_python3:0}
%files -n python3-%{name}
%defattr(-,root,root,-)
%{python3_sitearch}/*
%endif

%files doc
%defattr(-,root,root,-)
%doc %{_docdir}/%{name}-%{version}

%if %{?_with_ceph:1}%{!?_with_ceph:0}
%files ceph
%defattr(-,root,root,-)
%{_libdir}/libXrdCeph-4.so
%{_libdir}/libXrdCephXattr-4.so
%{_libdir}/libXrdCephPosix.so*
%endif

%if %{?_with_tests:1}%{!?_with_tests:0}
%files tests
%defattr(-,root,root,-)
%{_bindir}/text-runner
%{_bindir}/xrdshmap
%{_libdir}/libXrdClTests.so
%{_libdir}/libXrdClTestsHelper.so
%{_libdir}/libXrdClTestMonitor*.so

%if %{?_with_ceph:1}%{!?_with_ceph:0}
%{_libdir}/libXrdCephTests*.so
%endif
%endif

%files selinux
%defattr(-,root,root)
%{_datadir}/selinux/packages/%{name}/%{name}.pp

%if %{?_with_compat:1}%{!?_with_compat:0}
%files client-compat
%defattr(-,root,root,-)
%{_libdir}/libXrdAppUtils.so.0*
%{_libdir}/libXrdCksCalczcrc32.so*
%{_libdir}/libXrdClient.so.1*
%{_libdir}/libXrdCl.so.1*
%{_libdir}/libXrdCryptoLite.so.0*
%{_libdir}/libXrdCrypto.so.0*
%{_libdir}/libXrdCryptossl.so*
%{_libdir}/libXrdFfs.so.1*
%{_libdir}/libXrdPosixPreload.so.0*
%{_libdir}/libXrdPosix.so.1*
%{_libdir}/libXrdSecgsiAuthzVO.so*
%{_libdir}/libXrdSecgsiGMAPDN.so*
%{_libdir}/libXrdSecgsi.so*
%{_libdir}/libXrdSeckrb5.so*
%{_libdir}/libXrdSecpwd.so*
%{_libdir}/libXrdSec.so*
%{_libdir}/libXrdSecsss.so*
%{_libdir}/libXrdSecunix.so*
%{_libdir}/libXrdUtils.so.1*

%files server-compat
%defattr(-,root,root,-)
%{_bindir}/cmsd-3
%{_bindir}/frm_purged-3
%{_bindir}/frm_xfrd-3
%{_bindir}/xrootd-3
%{_libdir}/libXrdBwm.so*
%{_libdir}/libXrdMain.so.1*
%{_libdir}/libXrdOfs.so.1*
%{_libdir}/libXrdPss.so*
%{_libdir}/libXrdServer.so.1*
%{_libdir}/libXrdXrootd.so*
%endif

#-------------------------------------------------------------------------------
# Changelog
#-------------------------------------------------------------------------------
%changelog
* Tue Jan 08 2019 Edgar Fajardo <emfajard@ucsd.edu>
- Create config dir /etc/xrootd/config.d

* Tue May 08 2018 Michal Simon <michal.simon@cern.ch> 
- Make python3 sub-package optional

* Fri Nov 10 2017 Michal Simon <michal.simon@cern.ch> - 1:4.8.0-1
- Add python3 sub-package
- Rename python sub-package

* Tue Dec 13 2016 Gerardo Ganis <gerardo.ganis@cern.ch>
- Add xrdgsitest to xrootd-client-devel

* Mon Mar 16 2015 Lukasz Janyst <ljanyst@cern.ch>
- create the python package

* Wed Mar 11 2015 Lukasz Janyst <ljanyst@cern.ch>
- create the xrootd-ceph package

* Thu Oct 30 2014 Lukasz Janyst <ljanyst@cern.ch>
- update for 4.1 and introduce 3.3.6 compat packages

* Thu Aug 28 2014 Lukasz Janyst <ljanyst@cern.ch>
- add support for systemd

* Wed Aug 27 2014 Lukasz Janyst <ljanyst@cern.ch>
- use generic selinux policy build mechanisms

* Tue Apr 01 2014 Lukasz Janyst <ljanyst@cern.ch>
- correct the license field (LGPLv3+)
- rename to xrootd4
- add 'conflicts' statements
- remove 'provides' and 'obsoletes'

* Mon Mar 31 2014 Lukasz Janyst <ljanyst@cern.ch>
- Add selinux policy

* Fri Jan 24 2014 Lukasz Janyst <ljanyst@cern.ch>
- Import XrdHttp

* Fri Jun 7 2013 Lukasz Janyst <ljanyst@cern.ch>
- adopt the EPEL RPM layout by Mattias Ellert

* Tue Apr 2 2013 Lukasz Janyst <ljanyst@cern.ch>
- remove perl

* Thu Nov 1 2012 Justin Salmon <jsalmon@cern.ch>
- add tests package

* Fri Oct 21 2011 Lukasz Janyst <ljanyst@cern.ch> 3.1.0-1
- bump the version to 3.1.0

* Mon Apr 11 2011 Lukasz Janyst <ljanyst@cern.ch> 3.0.3-1
- the first RPM release - version 3.0.3
- the detailed release notes are available at:
  http://xrootd.org/download/ReleaseNotes.html
