%{!?python_sitearch: %global python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib(1)")}

%global with_lfc %{?_with_lfc:1}%{!?_with_lfc:0}
%global with_java %{!?_without_java:1}%{?_without_java:0}
%global with_gcj %{!?_without_gcj:1}%{?_without_gcj:0}

%global pkgdir @PACKAGE@

Name: nordugrid-arc1
Version: @VERSION@
Release: 1%{?dist}
Summary: ARC
Group: System Environment/Daemons
License: ASL 2.0
URL: http://www.nordugrid.org/
Source: %{name}-%{version}.tar.gz
BuildRoot:%{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)

BuildRequires: cppunit-devel
BuildRequires: pkgconfig
BuildRequires: e2fsprogs-devel
BuildRequires: gettext
BuildRequires: python-devel
BuildRequires: glibmm24-devel
BuildRequires: glib2-devel
BuildRequires: libxml2-devel
BuildRequires: openssl-devel
BuildRequires: xmlsec1-devel >= 1.2.4
BuildRequires: xmlsec1-openssl-devel >= 1.2.4
BuildRequires: gsoap-devel >= 2.7.2
%if %{_vendor} == "suse"
BuildRequires: openldap2-devel
BuildRequires: gettext-devel
%endif
%if %{_vendor} != "suse"
BuildRequires: openldap-devel
%endif
BuildRequires: globus-common-devel
BuildRequires: globus-ftp-client-devel
BuildRequires: globus-ftp-control-devel
BuildRequires: globus-rls-client-devel
%if %{with_lfc}
BuildRequires: LFC-devel
%endif
%if %{_vendor} == "redhat"
BuildRequires: db4-devel
%endif
#%if %{_vendor} == "suse" && %{dist} != ".oss10.3"
#BuildRequires: db-devel
#%endif
#%if %{_vendor} == "suse" && %{dist} == ".oss10.3"
#BuildRequires: libdb_cxx-4_4-devel
#%endif
%if %{_vendor} == "suse"
BuildRequires: db-devel
%endif
%if %{with_java}
BuildRequires: java-devel
BuildRequires: jpackage-utils
%if %{with_gcj}
BuildRequires: java-gcj-compat-devel
%endif
%endif

%define pyver %(python -c 'import sys; print sys.version[:3]')
%if "%{pyver}" < "2.4"
%define ifpy #
%else
%define ifpy %{nil}
%endif

%description
ARC

%package client
Summary: ARC prototype clients
Group: Applications/Internet
Requires: %{name} = %{version}
Requires: %{name}-plugins-base = %{version}

%description client
ARC prototype clients.

%package server
Summary: ARC Hosting Environment Daemon
Group: System Environment/Libraries
Requires: %{name} = %{version}

Requires(post): chkconfig
Requires(preun): chkconfig
Requires(preun): initscripts
Requires(postun): initscripts

%description server
ARC Hosting Environment Daemon (HED).

%package arex
Summary: ARC Remote EXecution service
Group: System Environment/Libraries
Requires: %{name} = %{version}
Requires: %{name}-server = %{version}
Requires: perl-XML-Simple

Requires(post): chkconfig
Requires(preun): chkconfig
Requires(preun): initscripts
Requires(postun): initscripts

%description arex
ARC Remote EXecution service (AREX)

%package plugins-base
Summary: ARC base plugins
Group: System Environment/Libraries
Requires: %{name} = %{version}

%description plugins-base
ARC base plugins. This includes the Message Chain Components (MCCs) and
Data Manager Components (DMCs).

%package plugins-globus
Summary: ARC Globus plugins
Group: System Environment/Libraries
Requires: %{name} = %{version}

%description plugins-globus
ARC Globus plugins. This includes the Globus dependent Data Manager
Components (DMCs).

%package devel
Summary: ARC development files
Group: Development/Libraries
Requires: %{name} = %{version}
Requires: glibmm24-devel
Requires: glib2-devel
Requires: libxml2-devel
Requires: openssl-devel

%description devel
Development files for ARC

%package python
Summary: ARC Python wrapper
Group: Development/Libraries
Requires: %{name} = %{version}
Requires: python

%description python
Python wrapper for ARC

%if %{with_java}
%package java
Summary: ARC Java wrapper
Group: Development/Libraries
Requires: %{name} = %{version}
Requires: java
Requires: jpackage-utils
%if %{with_gcj}
Requires(post): java-gcj-compat
Requires(postun): java-gcj-compat
%endif

%description java
Java wrapper for ARC
%endif

%package janitor
Summary: ARC dynamic installation of runtime environments
Group: Applications/Internet
Requires: perl-redland

%description janitor
The NorduGrid is a collaboration aiming at development, maintenance
and support of the free Grid middleware, known as the Advanced
Resource Connector (ARC).

For grid computing, a major challenge is to keep the working environments
homogeneous between the sites.  To help this situation, runtime
environments have been developed. Those can be added to or removed from
a site, and this Janitor service helps automating this process.

The Janitor is a recent development and the community to prepare
catalogues of dynamically installable packages still needs to
evolve.

%package doc
Summary: ARC API documentation
Group: Documentation

%description doc
ARC API docmentation

%prep
%setup -q

%build
%configure --disable-static \
%if ! %{with_java}
	   --disable-java \
%endif
%if %{with_lfc}
	   --enable-lfc \
%endif
	   --enable-docs

make all doc %{?_smp_mflags}

%check
make check

%install
rm -rf $RPM_BUILD_ROOT

make install DESTDIR=$RPM_BUILD_ROOT

find $RPM_BUILD_ROOT -type f -name \*.la -exec rm -fv '{}' ';'

mkdir -p $RPM_BUILD_ROOT%{_initrddir}
cp -p src/hed/daemon/scripts/arched.redhat $RPM_BUILD_ROOT%{_initrddir}/arched
chmod +x $RPM_BUILD_ROOT%{_initrddir}/arched

# RPM does it's own doc handling
rm -fr $RPM_BUILD_ROOT%{_datadir}/doc/%{pkgdir}

%find_lang arc

%if %{with_gcj}
%{_bindir}/aot-compile-rpm
%endif

%clean
rm -rf $RPM_BUILD_ROOT

%post -p /sbin/ldconfig

%postun -p /sbin/ldconfig

%post server
/sbin/chkconfig --add arched

%preun server
if [ $1 = 0 ]; then
  service arched stop > /dev/null 2>&1
  /sbin/chkconfig --del arched
fi

%postun server
if [ "$1" -ge "1" ]; then
  service arched condrestart > /dev/null 2>&1
fi
exit 0

%post arex
/sbin/chkconfig --add a-rex

%preun arex
if [ $1 = 0 ]; then
  service a-rex stop > /dev/null 2>&1
  /sbin/chkconfig --del a-rex
fi

%postun arex
if [ "$1" -ge "1" ]; then
  service a-rex condrestart > /dev/null 2>&1
fi
exit 0

%post java
%if %{with_gcj}
[ -x %{_bindir}/rebuild-gcj-db ] && %{_bindir}/rebuild-gcj-db
%endif

%postun java
%if %{with_gcj}
[ -x %{_bindir}/rebuild-gcj-db ] && %{_bindir}/rebuild-gcj-db
%endif

%files -f arc.lang
%defattr(-,root,root,-)
%{_libdir}/lib*.so.*
%{_datadir}/%{pkgdir}/schema
%doc ChangeLog README AUTHORS LICENSE

%files client
%defattr(-,root,root,-)
%{_bindir}/arccat
%{_bindir}/arcclean
%{_bindir}/arccp
%{_bindir}/arcdecision
%{_bindir}/arcecho
%{_bindir}/arcget
%{_bindir}/arcinfo
%{_bindir}/arckill
%{_bindir}/arcls
%{_bindir}/arcmigrate
%{_bindir}/arcproxy
%{_bindir}/arcrenew
%{_bindir}/arcresub
%{_bindir}/arcresume
%{_bindir}/arcrm
%{_bindir}/arcslcs
%{_bindir}/arcsrmping
%{_bindir}/arcstat
%{_bindir}/arcsub
%{_bindir}/arcsync
%{_bindir}/chelonia
%{_bindir}/isistest
%{_bindir}/jura
%{_bindir}/perftest
%{_bindir}/saml_assertion_init
%config(noreplace) %{_sysconfdir}/%{pkgdir}/client.conf
%doc %{_mandir}/man1/arccat.1*
%doc %{_mandir}/man1/arcclean.1*
%doc %{_mandir}/man1/arccp.1*
%doc %{_mandir}/man1/arcdecision.1*
%doc %{_mandir}/man1/arcecho.1*
%doc %{_mandir}/man1/arcget.1*
%doc %{_mandir}/man1/arcinfo.1*
%doc %{_mandir}/man1/arckill.1*
%doc %{_mandir}/man1/arcls.1*
%doc %{_mandir}/man1/arcmigrate.1*
%doc %{_mandir}/man1/arcproxy.1*
%doc %{_mandir}/man1/arcrenew.1*
%doc %{_mandir}/man1/arcresub.1*
%doc %{_mandir}/man1/arcresume.1*
%doc %{_mandir}/man1/arcrm.1*
%doc %{_mandir}/man1/arcslcs.1*
%doc %{_mandir}/man1/arcstat.1*
%doc %{_mandir}/man1/arcsrmping.1*
%doc %{_mandir}/man1/arcsub.1*
%doc %{_mandir}/man1/arcsync.1*
%doc %{_mandir}/man1/chelonia.1*
%doc %{_mandir}/man1/perftest.1.gz
%doc %{_mandir}/man1/saml_assertion_init.1*
%doc %{_mandir}/man5/arcclient.xml.5*
%doc src/clients/charon/charon_client.xml.example
%doc src/clients/charon/charon_request.xml.example
%doc src/tests/echo/echo.wsdl

%files server
%defattr(-,root,root,-)
%{_initrddir}/arched
%{_sbindir}/arched
%{_sbindir}/manage_jobq
%{_libdir}/%{pkgdir}/libcharon.so
%{_libdir}/%{pkgdir}/libcompiler.so
%{_libdir}/%{pkgdir}/libdelegation.so
%{_libdir}/%{pkgdir}/libecho.so
%{_libdir}/%{pkgdir}/libgrid_sched.so
%{_libdir}/%{pkgdir}/libhopi.so
%{_libdir}/%{pkgdir}/libisis.so
%{_libdir}/%{pkgdir}/libpaul.so
%{_libdir}/%{pkgdir}/libsaml2sp.so
%{_libdir}/%{pkgdir}/libslcs.so
%{_datadir}/%{pkgdir}/examples/storage_service.xml.example
%doc %{_mandir}/man8/arched.8*
%doc %{_mandir}/man8/manage_jobq.8*
%doc src/services/charon/charon_policy_arc.xml.example
%doc src/services/charon/charon_policy_xacml.xml.example
%doc src/services/charon/charon_service.xml.example
%doc src/services/hopi/hopi_service.xml.example
%doc src/tests/echo/echo_service.xml.example

%files arex
%defattr(-,root,root,-)
%{_initrddir}/a-rex
%{_libexecdir}/%{pkgdir}/cache-clean
%{_libexecdir}/%{pkgdir}/cache-list
%{_libexecdir}/%{pkgdir}/downloader
%{_libexecdir}/%{pkgdir}/gm-jobs
%{_libexecdir}/%{pkgdir}/gm-kick
%{_libexecdir}/%{pkgdir}/smtp-send
%{_libexecdir}/%{pkgdir}/smtp-send.sh
%{_libexecdir}/%{pkgdir}/uploader
%{_libexecdir}/%{pkgdir}/cancel-*-job
%{_libexecdir}/%{pkgdir}/scan-*-job
%{_libexecdir}/%{pkgdir}/submit-*-job
%{_libexecdir}/%{pkgdir}/finish-condor-job
%{_libexecdir}/%{pkgdir}/CEinfo.pl
%{_libdir}/%{pkgdir}/libarex.so
%{_libdir}/%{pkgdir}/ARC0mod.pm
%{_libdir}/%{pkgdir}/FORKmod.pm
%{_libdir}/%{pkgdir}/SGEmod.pm
%{_libdir}/%{pkgdir}/LL.pm
%{_libdir}/%{pkgdir}/LSF.pm
%{_libdir}/%{pkgdir}/PBS.pm
%{_libdir}/%{pkgdir}/Condor.pm
%{_libdir}/%{pkgdir}/SLURM.pm
%{_libdir}/%{pkgdir}/ARC0ClusterInfo.pm
%{_libdir}/%{pkgdir}/ARC0ClusterSchema.pm
%{_libdir}/%{pkgdir}/ARC1ClusterInfo.pm
%{_libdir}/%{pkgdir}/ARC1ClusterSchema.pm
%{_libdir}/%{pkgdir}/ConfigCentral.pm
%{_libdir}/%{pkgdir}/GMJobsInfo.pm
%{_libdir}/%{pkgdir}/HostInfo.pm
%{_libdir}/%{pkgdir}/InfoChecker.pm
%{_libdir}/%{pkgdir}/IniParser.pm
%{_libdir}/%{pkgdir}/LogUtils.pm
%{_libdir}/%{pkgdir}/LRMSInfo.pm
%{_libdir}/%{pkgdir}/Sysinfo.pm
%{_libdir}/%{pkgdir}/cancel_common.sh
%{_libdir}/%{pkgdir}/change-lsf-mode.sh
%{_libdir}/%{pkgdir}/condor_env.pm
%{_libdir}/%{pkgdir}/config_parser.sh
%{_libdir}/%{pkgdir}/configure-*-env.sh
%{_libdir}/%{pkgdir}/submit_common.sh
%{_datadir}/%{pkgdir}/nordugrid.schema
%config(noreplace) %{_sysconfdir}/arc_arex.conf
%doc %{_mandir}/man1/cache-clean.1*
%doc %{_mandir}/man1/cache-list.1*
%doc src/services/a-rex/arex.xml.example
%doc src/services/a-rex/arex_minimalistic.xml.example
%doc src/services/a-rex/arex_secure.xml.example
%doc src/services/a-rex/arc_arex.conf

%files devel
%defattr(-,root,root,-)
%{_includedir}/%{pkgdir}
%{_libdir}/lib*.so
%{_bindir}/wsdl2hed
%doc %{_mandir}/man1/wsdl2hed.1*
%{_libdir}/pkgconfig/arcbase.pc

%files plugins-base
%defattr(-,root,root,-)
%{_libdir}/%{pkgdir}/libaccARC1.so
%{_libdir}/%{pkgdir}/libaccCREAM.so
%{_libdir}/%{pkgdir}/libaccBroker.so
%{_libdir}/%{pkgdir}/libaccUNICORE.so
%{_libdir}/%{pkgdir}/libarcshc.so
%{_libdir}/%{pkgdir}/libdmcarc.so
%{_libdir}/%{pkgdir}/libdmcfile.so
%{_libdir}/%{pkgdir}/libdmchttp.so
%{_libdir}/%{pkgdir}/libdmcldap.so
%{_libdir}/%{pkgdir}/libidentitymap.so
%{_libdir}/%{pkgdir}/libmcchttp.so
%{_libdir}/%{pkgdir}/libmccmsgvalidator.so
%{_libdir}/%{pkgdir}/libmccsoap.so
%{_libdir}/%{pkgdir}/libmcctcp.so
%{_libdir}/%{pkgdir}/libmcctls.so

%files plugins-globus
%defattr(-,root,root,-)
%{_libdir}/%{pkgdir}/libaccARC0.so
%{_libdir}/%{pkgdir}/libdmcgridftp.so
%if %{with_lfc}
%{_libdir}/%{pkgdir}/libdmclfc.so
%endif
%{_libdir}/%{pkgdir}/libdmcrls.so
%{_libdir}/%{pkgdir}/libdmcsrm.so
%{_libdir}/%{pkgdir}/libmccgsi.so

%files python
%defattr(-,root,root,-)
%{python_sitearch}/*
%{_libdir}/%{pkgdir}/libaccPythonBroker.so
%{ifpy}%{_libdir}/%{pkgdir}/libpythonservice.so
%doc src/hed/acc/PythonBroker/SampleBroker.py

%if %{with_java}
%files java
%defattr(-,root,root,-)
%{_libdir}/java/libjarc.so
%{_libdir}/java/arc.jar
%{_libdir}/%{pkgdir}/libjavaservice.so
%if %{with_gcj}
%{_libdir}/gcj/%{name}
%endif
%endif

%files janitor
%defattr(-,root,root,-)
%{_libexecdir}/%{pkgdir}/janitor
%{_datadir}/%{pkgdir}/perl
%doc %{_mandir}/man8/janitor.8*

%files doc
%defattr(-,root,root,-)
%doc doc/tech_doc/doxygen/ARC1-API.pdf
%doc doc/tech_doc/doxygen/ARC1-ChainComponents.pdf
%doc doc/tech_doc/doxygen/ARC1-Services.pdf
%doc doc/tech_doc/hed/ARCHED_article.pdf
%doc doc/tech_doc/chelonia/arc-storage-documentation.pdf
%doc doc/tech_doc/a-rex/arex_tech_doc.pdf
%doc doc/tech_doc/backend_interface/Backends-arc1.pdf
%doc doc/tech_doc/client/client_technical.pdf
%doc doc/tech_doc/infosys/infosys_technical.pdf
%doc doc/tech_doc/infosys/TechnicalHandbook/ISIS-TechnicalHandbook.pdf
%doc doc/manuals/janitor/Janitor.pdf
%doc doc/tech_doc/janitor/Janitor.pdf
%doc doc/tech_doc/jura/jura-tech-doc.pdf
%doc doc/tech_doc/sec/SecurityFrameworkofARC1.pdf
%doc doc/manuals/user_interface/ui.pdf
%doc doc/manuals/ws-quick-guide/ws-quick-guide.pdf
%doc doc/tutorials/ws-programming-tutorial/doc/WS-tutorial.pdf

%changelog
* @SPECDATE@ Anders Waananen <waananen@nbi.dk> - @VERSION@-1
- Initial release
