%define krb 0
%define vdt 0
%define epel 0
%define ssl 0
%{?_with_krb:%define krb 1}
%{?_with_vdt:%define vdt 1}
%{?_with_epel:%define epel 1}
%{?_with_ssl:%define ssl 1}

%if %vdt || %epel
%define gsi 1
%else
%define gsi 0
%endif

Summary: dCache Client
Vendor: dcache.org
Name: @PACKAGE@
Version: @VERSION@
Release: @VER_PATCH@
Prefix: /opt/d-cache/dcap
#BuildRoot: %{_tmppath}/%{name}-%{version}-build
BuildRoot: %{_tmppath}/%{name}-root
Source: @PACKAGE@-@VERSION@.tar.gz
License: LGPL

Group: Applications/System
BuildRequires: zlib-devel
%description
dCache is a distributed mass storage system.

This package contains the client components.
%package tests
Summary: dCache Client libraries Tests
Group: Applications/System
%description tests
dCache is a distributed mass storage system.

%package -n libdcap
Summary: dCache Client libraries
Group: Applications/System
%description -n libdcap
dCache is a distributed mass storage system.

This package contains the client libraries dcachedcap.
%package -n libdcap-devel
Summary: dCache Client Headers
Group: Applications/System
Requires: libdcap
%description -n libdcap-devel
This package contains the client library dcachedcap header files.

%if %gsi
%package -n libdcap-tunnel-gsi
Summary: dCache GSI Tunnel
Group: Applications/System
Requires: libdcap
BuildRequires: openssl-devel
%if %vdt
BuildRequires: vdt_globus_essentials
%endif
%if %epel
BuildRequires:  globus-gssapi-gsi-devel
%endif
%description -n libdcap-tunnel-gsi
This package contains the gsi tunnel plugin library used by dcachedcap.
This library is dynamically loaded at run time.
%endif

%if %krb
%package -n libdcap-tunnel-krb
Summary: dCache Kerberos Tunnel
Group: Applications/System
Requires: libdcap
BuildRequires: krb5-devel
%description -n libdcap-tunnel-krb
This package contains the kerberos tunnel plugin library used by dcachedcap.
This library is dynamically loaded at run time.
%endif

%package -n libdcap-tunnel-telnet
Summary: dCache Telnet Tunnel
Group: Applications/System
Requires: libdcap
%description -n libdcap-tunnel-telnet
This package contains the telnet tunnel plugin library used by dcachedcap.
This library is dynamically loaded at run time.

%if %ssl
%package -n libdcap-tunnel-ssl
Summary: dCache SSL Tunnel
Group: Applications/System
Requires: libdcap
BuildRequires: openssl-devel
%description -n libdcap-tunnel-ssl
This package contains the ssl tunnel plugin library used by dcachedcap.
This library is dynamically loaded at run time.
%endif

%prep


%setup -q -n @PACKAGE@-@VERSION@
%build
libdir=%{prefix}/lib
bindir=%{prefix}/bin

%ifos Linux
%ifarch x86_64
libdir=%{prefix}/lib64
%endif
%endif
CPPFLAGS="@CPPFLAGS@" LDFLAGS="@LDFLAGS@" ./configure \
  --bindir=/${bindir} \
  --libdir=/${libdir} \
  --with-doc-dir=%{prefix}/share/doc/@PACKAGE@-@VERSION@ \
  --includedir=%{prefix}/include/ \
  --with-krb5-gssapi-include=@KRB5_GSSAPI_INCLUDE_DIR@ \
  --with-globus-include=@GLOBUS_INCLUDE_DIR@ \
  --with-globus-lib=@GLOBUS_LIB_DIR@
make

%install

if [ -d $RPM_BUILD_ROOT ]; then rm -rf $RPM_BUILD_ROOT; fi
make install DESTDIR=$RPM_BUILD_ROOT
echo --libdir=/${libdir}

%clean
rm -rf $RPM_BUILD_ROOT

%pre

#%post

%preun

#%postun



%files
%defattr(-,root,root)
%attr(0755,root,root) %{prefix}/bin/dccp
%{prefix}/share/doc/@PACKAGE@-@VERSION@/AUTHORS
%{prefix}/share/doc/@PACKAGE@-@VERSION@/ChangeLog
%{prefix}/share/doc/@PACKAGE@-@VERSION@/COPYING
%{prefix}/share/doc/@PACKAGE@-@VERSION@/INSTALL
%{prefix}/share/doc/@PACKAGE@-@VERSION@/LICENSE
%{prefix}/share/doc/@PACKAGE@-@VERSION@/README



%files tests
%defattr(0755,root,root)
%{prefix}/bin/dcap_test
%{prefix}/bin/dcsuck
%{prefix}/bin/readv_test
%{prefix}/bin/wdccp
%{prefix}/bin/dcap_url-test

%files -n libdcap
%defattr(-,root,root)
%ifarch x86_64
%{prefix}/lib64/libdcap.so*
%{prefix}/lib64/libpdcap.so*
%else
%{prefix}/lib/libdcap.so*
%{prefix}/lib/libpdcap.so*
%endif

%files -n libdcap-devel
%defattr(-,root,root)
%{prefix}/include/dc_hack.h
%{prefix}/include/dcap.h
%{prefix}/include/dcap_errno.h
%{prefix}/share/doc/@PACKAGE@-@VERSION@/examples/dccp.c
%ifarch x86_64
%{prefix}/lib64/libdcap.a
%{prefix}/lib64/libdcap.la
%{prefix}/lib64/libpdcap.a
%{prefix}/lib64/libpdcap.la
%else
%{prefix}/lib/libdcap.a
%{prefix}/lib/libdcap.la
%{prefix}/lib/libpdcap.a
%{prefix}/lib/libpdcap.la
%endif

%if %gsi
%files -n libdcap-tunnel-gsi
%defattr(-,root,root)
%ifarch x86_64
%{prefix}/lib64/libgsiTunnel.a
%{prefix}/lib64/libgsiTunnel.la
%{prefix}/lib64/libgsiTunnel.so*
%else
%{prefix}/lib/libgsiTunnel.a
%{prefix}/lib/libgsiTunnel.la
%{prefix}/lib/libgsiTunnel.so*
%endif
%endif

%if %krb
%files -n libdcap-tunnel-krb
%defattr(-,root,root)
%ifarch x86_64
%{prefix}/lib64/libgssTunnel.a
%{prefix}/lib64/libgssTunnel.la
%{prefix}/lib64/libgssTunnel.so*
%else
%{prefix}/lib/libgssTunnel.a
%{prefix}/lib/libgssTunnel.la
%{prefix}/lib/libgssTunnel.so*
%endif
%endif

%files -n libdcap-tunnel-telnet
%defattr(-,root,root)
%ifarch x86_64
%{prefix}/lib64/libtelnetTunnel.a
%{prefix}/lib64/libtelnetTunnel.la
%{prefix}/lib64/libtelnetTunnel.so*
%else
%{prefix}/lib/libtelnetTunnel.a
%{prefix}/lib/libtelnetTunnel.la
%{prefix}/lib/libtelnetTunnel.so*
%endif

%if %ssl
%files -n libdcap-tunnel-ssl
%defattr(-,root,root)
%ifarch x86_64
%{prefix}/lib64/libsslTunnel.a
%{prefix}/lib64/libsslTunnel.la
%{prefix}/lib64/libsslTunnel.so*
%else
%{prefix}/lib/libsslTunnel.a
%{prefix}/lib/libsslTunnel.la
%{prefix}/lib/libsslTunnel.so*
%endif
%endif
%changelog
* Wed Dec 22 2010 - tigran.mkrtchyan (at) desy.de
- Fixed files ownership

* Thu Nov 19 2009 - owen.synge (at) desy.de
- Repackaged with auto tools

* Fri Sep 26 2009 - owen.synge (at) desy.de
- Added cleaned up packaging.

* Wed Sep 24 2009 - owen.synge (at) desy.de
- Released first version of this packaging.
