File sundials.spec of Package sundials

#
# spec file for package sundials
#
# Copyright (c) 2012 SUSE LINUX Products GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#

%if 0%{?sles_version}
%define _mpi openmpi mvapich2
%else
%define _mpi openmpi
%endif

Summary:        Suite of nonlinear solvers
License:        BSD-3-Clause
Group:          System/Libraries
Name:           sundials
Version:        2.5.0
Release:        0
# SUNDIALS is licensed under BSD with some additional (but unrestrictive) clauses.
# Check the file 'LICENSE' for details.
Url:            http://www.llnl.gov/casc/sundials/
Source0:        http://www.llnl.gov/casc/sundials/download/code/%{name}-%{version}.tar.bz2
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
#Parallel build seems to require some fixes from upstream
# BuildRequires: openmpi-devel
BuildRequires:  fdupes
BuildRequires:  gcc-fortran
BuildRequires:  openmpi-devel
%if 0%{?sles_version}
BuildRequires:  mvapich2-devel
%endif

%description
SUNDIALS is a SUite of Non-linear DIfferential/ALgebraic equation Solvers
for use in writing mathematical software.

SUNDIALS was implemented with the goal of providing robust time integrators
and nonlinear solvers that can easily be incorporated into existing simulation
codes. The primary design goals were to require minimal information from the
user, allow users to easily supply their own data structures underneath the
solvers, and allow for easy incorporation of user-supplied linear solvers and
preconditioners. 

%package devel
Summary:        Suite of nonlinear solvers (developer files)
Group:          Development/Libraries/C and C++
Requires:       %{name} = %{version}-%{release}

%description devel
SUNDIALS is a SUite of Non-linear DIfferential/ALgebraic equation Solvers
for use in writing mathematical software.

This package contains the developer files (.so file, header files)

%package devel-static
Summary:        Suite of nonlinear solvers (static libraries)
Group:          Development/Libraries/C and C++
Requires:       %{name}-devel = %{version}-%{release}

%description devel-static
SUNDIALS is a SUite of Non-linear DIfferential/ALgebraic equation Solvers
for use in writing mathematical software.

This package contains the static library files (.a files). These libraries
provide support for using SUNDIALS from Fortran.


%package doc
Summary:        Suite of nonlinear solvers (documentation)
Group:          Documentation/Other

%description doc
SUNDIALS is a SUite of Non-linear DIfferential/ALgebraic equation Solvers
for use in writing mathematical software.

This package contains the documentation files

%package openmpi
Summary:        Suite of nonlinear solvers (static libraries)
Group:          System/Libraries

%description openmpi
SUNDIALS is a SUite of Non-linear DIfferential/ALgebraic equation Solvers
for use in writing mathematical software.

SUNDIALS was implemented with the goal of providing robust time integrators
and nonlinear solvers that can easily be incorporated into existing simulation
codes. The primary design goals were to require minimal information from the
user, allow users to easily supply their own data structures underneath the
solvers, and allow for easy incorporation of user-supplied linear solvers and
preconditioners. 

%package openmpi-devel
Summary:        Suite of nonlinear solvers (developer files)
Group:          Development/Libraries/Parallel
Requires:       %{name}-openmpi = %{version}-%{release}

%description openmpi-devel
SUNDIALS is a SUite of Non-linear DIfferential/ALgebraic equation Solvers
for use in writing mathematical software.

This package contains the developer files (.so file, header files)

%package openmpi-devel-static
Summary:        Suite of nonlinear solvers (static libraries)
Group:          Development/Libraries/Parallel
Requires:       %{name}-openmpi-devel = %{version}-%{release}

%description openmpi-devel-static
SUNDIALS is a SUite of Non-linear DIfferential/ALgebraic equation Solvers
for use in writing mathematical software.

This package contains the static library files (.a files). These libraries
provide support for using SUNDIALS from Fortran.

%if 0%{?sles_version}
%package mvapich2
Summary:        Suite of nonlinear solvers (static libraries)
Group:          System/Libraries

%description mvapich2
SUNDIALS is a SUite of Non-linear DIfferential/ALgebraic equation Solvers
for use in writing mathematical software.

SUNDIALS was implemented with the goal of providing robust time integrators
and nonlinear solvers that can easily be incorporated into existing simulation
codes. The primary design goals were to require minimal information from the
user, allow users to easily supply their own data structures underneath the
solvers, and allow for easy incorporation of user-supplied linear solvers and
preconditioners. 

%package mvapich2-devel
Summary:        Suite of nonlinear solvers (developer files)
Group:          Development/Libraries/Parallel
Requires:       %{name}-mvapich2 = %{version}-%{release}

%description mvapich2-devel
SUNDIALS is a SUite of Non-linear DIfferential/ALgebraic equation Solvers
for use in writing mathematical software.

This package contains the developer files (.so file, header files)

%package mvapich2-devel-static
Summary:        Suite of nonlinear solvers (static libraries)
Group:          Development/Libraries/Parallel
Requires:       %{name}-mvapich2-devel = %{version}-%{release}

%description mvapich2-devel-static
SUNDIALS is a SUite of Non-linear DIfferential/ALgebraic equation Solvers
for use in writing mathematical software.

This package contains the static library files (.a files). These libraries
provide support for using SUNDIALS from Fortran.
%endif


%prep
%setup -q 

# prepare source for mpi build
set -- *
for i in %_mpi
do
    mkdir %{name}-$i
    cp -ap "$@" %{name}-$i
done

%build
%configure \
  F77=gfortran \
  --enable-static=yes \
  --enable-shared=yes \
  --disable-mpi
make %{?_smp_mflags}

i=openmpi
cd %{name}-$i
%define _prefix /usr/%_lib/mpi/gcc/$i
%configure \
   F77=gfortran \
    --enable-static=yes \
    --enable-shared=yes \
       --enable-mpi \
       --with-mpi-root=/usr/%_lib/mpi/gcc/$i \
       --with-mpicc=/usr/%_lib/mpi/gcc/$i/bin/mpicc \
       --with-mpif77=/usr/%_lib/mpi/gcc/$i/bin/mpif77 \
       --with-mpi-flags=-L/usr/%_lib/mpi/gcc/$i/%_lib \
       --with-mpi-libs=-lmpi
make %{?_smp_mflags}
cd ..

%if 0%{?sles_version}
i=mvapich2
cd %{name}-$i
%define _prefix /usr/%_lib/mpi/gcc/$i
%configure \
   F77=gfortran \
    --enable-static=yes \
    --enable-shared=yes \
       --enable-mpi \
       --with-mpi-root=/usr/%_lib/mpi/gcc/$i \
       --with-mpicc=/usr/%_lib/mpi/gcc/$i/bin/mpicc \
       --with-mpif77=/usr/%_lib/mpi/gcc/$i/bin/mpif77 \
       --with-mpi-flags=-L/usr/%_lib/mpi/gcc/$i/%_lib \
       --with-mpi-libs="-lmpich -lrdmacm -libverbs -libumad"
make %{?_smp_mflags}
cd ..
%endif

%define _prefix /usr

%install
# SUNDIALS does not support the 'DESTDIR' method, hence:

mkdir -p ${RPM_BUILD_ROOT}%{_bindir}
mkdir -p ${RPM_BUILD_ROOT}%{_includedir}
mkdir -p ${RPM_BUILD_ROOT}%{_libdir}

# install serial libs
cp src/nvec_ser/.libs/*.a ${RPM_BUILD_ROOT}%{_libdir}

for dir in cvode ida kinsol; do
 cp src/$dir/fcmix/.libs/*.a ${RPM_BUILD_ROOT}%{_libdir}
done

for dir in cvode cvodes ida kinsol nvec_ser; do
  cp -P src/$dir/.libs/*.so* ${RPM_BUILD_ROOT}%{_libdir}
done

cp -r include/* ${RPM_BUILD_ROOT}%{_includedir}
install -m755 bin/sundials-config ${RPM_BUILD_ROOT}%{_bindir}

# install parallel libs
for i in %_mpi
do
   mkdir -p ${RPM_BUILD_ROOT}/usr/%_lib/mpi/gcc/$i/bin
   mkdir -p ${RPM_BUILD_ROOT}/usr/%_lib/mpi/gcc/$i/include
   mkdir -p ${RPM_BUILD_ROOT}/usr/%_lib/mpi/gcc/$i/%{_lib}
   
   cd %{name}-$i
   for dir in cvode ida kinsol; do
    cp src/$dir/fcmix/.libs/*.a ${RPM_BUILD_ROOT}/usr/%_lib/mpi/gcc/$i/%{_lib}
   done

   for dir in cvode cvodes ida kinsol nvec_par; do
     cp -P src/$dir/.libs/*.so* ${RPM_BUILD_ROOT}/usr/%_lib/mpi/gcc/$i/%{_lib}
   done

   cp -r include/* ${RPM_BUILD_ROOT}/usr/%_lib/mpi/gcc/$i/include
   install -m755 bin/sundials-config ${RPM_BUILD_ROOT}/usr/%_lib/mpi/gcc/$i/bin
   cd ..
done

%fdupes ${RPM_BUILD_ROOT}

%clean
rm -rf ${RPM_BUILD_ROOT}

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

%post openmpi -p /sbin/ldconfig
%postun openmpi -p /sbin/ldconfig

%if 0%{?sles_version}
%post mvapich2 -p /sbin/ldconfig
%postun mvapich2 -p /sbin/ldconfig
%endif

%files
%defattr(-,root,root,-)
%doc LICENSE README
%{_libdir}/*.so.[0-9].*
%{_libdir}/*.so.[0-9]

%files doc
%defattr(-,root,root,-)
%doc doc/cvode/cv_examples.pdf
%doc doc/cvode/cv_guide.pdf
%doc doc/kinsol/kin_examples.pdf
%doc doc/kinsol/kin_guide.pdf
%doc doc/cvodes/cvs_examples.pdf
%doc doc/cvodes/cvs_guide.pdf
%doc doc/ida/ida_examples.pdf
%doc doc/ida/ida_guide.pdf

%files devel
%defattr(-,root,root,-)
%{_libdir}/*.so
%{_includedir}/*
%{_bindir}/sundials-config

%files devel-static
%defattr(-,root,root,-)
%{_libdir}/*.a

%files openmpi
%defattr(-,root,root,-)
%doc LICENSE README
/usr/%_lib/mpi/gcc/openmpi/%_lib/*.so.[0-9].*
/usr/%_lib/mpi/gcc/openmpi/%_lib/*.so.[0-9]

%files openmpi-devel
%defattr(-,root,root,-)
/usr/%_lib/mpi/gcc/openmpi/%_lib/*.so
/usr/%_lib/mpi/gcc/openmpi/include/*
/usr/%_lib/mpi/gcc/openmpi/bin/sundials-config

%files openmpi-devel-static
%defattr(-,root,root,-)
/usr/%_lib/mpi/gcc/openmpi/%_lib/*.a

%if 0%{?sles_version}
%files mvapich2
%defattr(-,root,root,-)
%doc LICENSE README
/usr/%_lib/mpi/gcc/mvapich2/%_lib/*.so.[0-9].*
/usr/%_lib/mpi/gcc/mvapich2/%_lib/*.so.[0-9]

%files mvapich2-devel
%defattr(-,root,root,-)
/usr/%_lib/mpi/gcc/mvapich2/%_lib/*.so
/usr/%_lib/mpi/gcc/mvapich2/include/*
/usr/%_lib/mpi/gcc/mvapich2/bin/sundials-config

%files mvapich2-devel-static
%defattr(-,root,root,-)
/usr/%_lib/mpi/gcc/mvapich2/%_lib/*.a
%endif

%changelog