# $Id$

# Note that this package is not relocatable

Name:    @PROJECT@
Version: @VERSION@
Release: @RELEASE@

Summary: Simple Linux Utility for Resource Management

License: GPL 
Group: System Environment/Base
Source: %{name}-%{version}-%{release}.tgz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}
URL: http://www.llnl.gov/linux/slurm
Requires: popt 
Requires: openssl >= 0.9.6

#
# If "--with debug" is set compile with --enable-debug 
#  and do not strip binaries
#
# (See /usr/share/doc/rpm-*/conditionalbuilds)
#
%if %{?_with_debug:1}%{!?_with_debug:0}
  %define _enable_debug --enable-debug
  %define __os_install_post /usr/lib/rpm/brp-compress
%endif

#
# Defaults are --with-elan --with-totalview
# (Use --without [elan|totalview] to disable)
#
%{!?_with_elan: %{!?_without_elan: %define _with_elan --with-elan}}
%{!?_with_totalview: %{!?_without_totalview: %define _with_totalview --with-totalview}}

%{?_with_elan:BuildRequires: qsnetlibs}

%package devel
Summary: Development package for SLURM.
Group: Development/System
Requires: slurm

%package auth-none
Summary: SLURM auth NULL implementation (no authentication)
Group: System Environment/Base
Requires: slurm

%package auth-authd
Summary: SLURM auth implementation using Brent Chun's authd
Group: System Environment/Base
Requires: slurm authd

%package auth-munge
Summary: SLURM auth implementation using Chris Dunlap's Munge
Group: System Environment/Base
Requires: slurm munge

%description 
SLURM is an open source, fault-tolerant, and highly
scalable cluster management and job scheduling system for Linux clusters
containing up to thousands of nodes. Components include machine status,
partition management, job management, and scheduling modules.

%description devel
Development package for SLURM.  This package includes the header files
and static libraries for the SLURM API.

%description auth-none
SLURM NULL authentication module 

%description auth-authd
SLURM authentication module for Brent Chun's authd

%description auth-munge
SLURM authentication module for Chris Dunlap's Munge

%prep
%setup -n %{name}-%{version}-%{release}

%build
%configure --program-prefix=%{?_program_prefix:%{_program_prefix}} \
    --sysconfdir=/etc/slurm		\
    %{?_enable_debug}                   \
    %{?_with_elan}                      \
    %{?_without_elan}                   \
    %{?_with_totalview}                 \
    %{?_without_totalview}

#
# The following was stolen from the E17 packages:
# Build with make -j if SMP is defined in the current environment.
#
if [ "$SMP" != "" ]; then
  (make "MAKE=make -k -j $SMP"; exit 0)
  make
else
  make
fi
#############################################################################

%install
rm -rf "$RPM_BUILD_ROOT"
mkdir -p "$RPM_BUILD_ROOT"
DESTDIR="$RPM_BUILD_ROOT" make install

install -D -m755 etc/init.d.slurm $RPM_BUILD_ROOT/etc/rc.d/init.d/slurm
install -D -m644 etc/slurm.conf.example $RPM_BUILD_ROOT/etc/slurm/slurm.conf

#############################################################################

%clean
rm -rf $RPM_BUILD_ROOT
#############################################################################

%files
%defattr(-,root,root,0755)
%doc AUTHORS
%doc NEWS
%doc README 
%doc DISCLAIMER
%doc COPYING
%doc etc/slurm.conf.example
%doc doc/html
%{_bindir}/*
%{_sbindir}/*
%{_libdir}/*.so*
%{_mandir}/man1/*
%{_mandir}/man5/*
%{_mandir}/man8/*
%dir /etc/slurm
%config(noreplace) /etc/rc.d/init.d/slurm
%config(noreplace) /etc/slurm/slurm.conf
#############################################################################

%files devel
%defattr(-,root,root)
%{_prefix}/include/slurm/*
%{_libdir}/libslurm.a
%{_libdir}/libslurm.la
%{_mandir}/man3/*
#############################################################################

#%if %(test -f %{_libdir}/slurm/auth_none.so && echo 1 || echo 0)
%files auth-none
%defattr(-,root,root)
%{_libdir}/slurm/auth_none.so
#%endif
#############################################################################

%if %(test -f %{_libdir}/slurm/auth_munge.so && echo 1 || echo 0)
%files auth-munge
%defattr(-,root,root)
%{_libdir}/slurm/auth_munge.so
%endif
#############################################################################

%if %(test -f %{_libdir}/slurm/auth_authd.so && echo 1 || echo 0)
%files auth-authd
%defattr(-,root,root)
%{_libdir}/slurm/auth_authd.so
%endif
#############################################################################

%pre
if [ -x /etc/rc.d/init.d/slurm ]; then
    if /etc/rc.d/init.d/slurm status | grep -q running; then
        /etc/rc.d/init.d/slurm stop
    fi
fi

%post
/sbin/ldconfig %{_libdir}
if [ -x /etc/rc.d/init.d/slurm ]; then
    [ -x /sbin/chkconfig ] && /sbin/chkconfig --del slurm
    [ -x /sbin/chkconfig ] && /sbin/chkconfig --add slurm
    if ! /etc/rc.d/init.d/slurm status | grep -q running \
      || ! /etc/rc.d/init.d/slurm test | grep -q  slurmctld; then
        /etc/rc.d/init.d/slurm start
    fi 
fi

%preun
if [ "$1" = 0 ]; then
    if [ -x /etc/rc.d/init.d/slurm ]; then
        [ -x /sbin/chkconfig ] && /sbin/chkconfig --del slurm
        if /etc/rc.d/init.d/slurm status | grep -q running; then
            /etc/rc.d/init.d/slurm stop
        fi
    fi
fi

%postun
if [ "$1" = 0 ]; then
    /sbin/ldconfig %{_libdir}
fi
#############################################################################


%changelog
* Thu Apr 10 2003 Mark Grondona <mgrondona@llnl.gov>
- include html documentation in main package
* Wed Mar 26 2003 Mark Grondona <mgrondona@llnl.gov>
- unconditionally build auth-none subpackage
* Fri Mar 21 2003 Mark Grondona <mgrondona@llnl.gov>
- allow debug builds when %debug macro is defined
- other cleanup
* Sat Jan 26 2003 Joey Ekstrom <jcekstrom@llnl.gov> 
- Started spec file
