# spec file for package PolyBoRi (Version $PBVERSION.$PBRELEASE)
#
# Copyright (c) 2008-2011 The PolyBoRi Team
# This file and all modifications and additions to the pristine
# package are under the same license as the package itself.
#
# Please submit bug fixes or comments via http://polybori.sourceforge.net
#
# norootforbuild

%define pbori_vernaming 0_8-${PBRELEASE}

%define pbori_pythonsearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; import sys; sys.stdout.write(get_python_lib())")
%define pbori_pysite_fallback %{?python_sitelib}%{!?python_sitelib:%pbori_pythonsearch}
%define pbori_pyinstprefix %{?py_sitedir}%{!?py_sitedir:%pbori_pysite_fallback}

%if $PB_M4RI_RPM
%define pbori_have_mr4i_rpm 1
%define pbori_have_not_mr4i_rpm 0
%define pbori_mr4i_url M4RIURL=''
%else
%define pbori_have_mr4i_rpm 0
%define pbori_have_not_mr4i_rpm 1
%define pbori_mr4i_url M4RIURL=%{SOURCE1}
%endif

%define pbori_instdir %{_datadir}/%{name}
%define pbori_docpath %{_defaultdocdir}/%{name}
%define pbori_tmpdoc docs



# Note: m4ri of official fc14 is too old
%if 0%{?fedora_version} >= 15
%define pbori_m4ri m4ri
%define pbori_m4ri_devel m4ri-devel

%else
# Note: Using inofficial m4ri build
%if %{pbori_have_mr4i_rpm}
%if 0%{?redhat_version}%{?centos_version}%{?suse_version}
%define pbori_m4ri m4ri
%define pbori_m4ri_devel m4ri-devel
%endif
%endif
%endif

#Note: boost-test of SLES10 is too old
%if 0%{?suse_version}
%define pbori_check %{suse_version} >= 1100
%else
%define pbori_check 1
%endif

# python-QT binding may have different names
%if 0%{?fedora_version}%{?suse_version}
%if 0%{?suse_version} >= 1100
%define pbori_pyqt python-qt4
%else
%define pbori_pyqt %{?fedora:PyQt4} %{?suse_version:PyQt}
%endif
%else
%define pbori_pyqt python-qt4
%endif

BuildRequires: scons boost-devel gcc gcc-c++ python-devel gd-devel 
BuildRequires: doxygen %{?fedora:tex4ht} %{?pbori_m4ri_devel}
%if 0%{?suse_version} >= 1100
BuildRequires: texlive-latex texlive-tex4ht
%endif


Summary: Framework for Boolean Rings
Name: PolyBoRi
Version: $PBVERSION.${PBRELEASE}
Release: 0
License: GPL-2.0+
Group: Productivity/Scientific/Math
URL: http://polybori.sf.net
Source0: %{name}-%{version}.tar.bz2
%if %{pbori_have_not_mr4i_rpm}
Source1: $PB_M4RI_SRC
%endif
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
Requires: python-%{name} = %{version}-%{release}
%if 0%{?fedora_version} >= 16
Requires: ipython >= 0.6
%else
Requires: IPython >= 0.6
%endif

%description
PolyBoRi is a special purpose computer algebra system for computations in
Boolean Rings. The core is a C++ library, which provides high-level data types
for Boolean polynomials and related structures. As a unique approach, binary
decision diagrams are used as internal storage type for polynomial
structures. On top of this, we provide a Python interface for parsing of
complex polynomial systems, as well as for sophisticated and extendable
strategies for Groebner base computation.
It uses the libraries CUDD and M4RI.

 
%package doc
Summary: Documentation package for %{name}
Group: Documentation/Other
Requires: %{name} = %{version}

%description doc
This package contains the documentation and tutorial of %{name}.



%package -n python-%{name}
Summary: Python core package for %{name} 
Group: Productivity/Scientific/Math
Requires: libpolybori-%{pbori_vernaming} = %{version}
Requires: libpolybori_groebner-%{pbori_vernaming} = %{version}
%if %{defined suse_version}
Requires: python-base = %{py_ver}
%endif

%description -n python-%{name}
This package contains the python core routines of %{name}. Is contains an
interface to the C/C++ Libraries of PolyBoRi as well as python library code
with high-level routines.



%package        -n libpolybori_groebner-%{pbori_vernaming}
Summary:        Core Groebner library for %{name}
Group:          Productivity/Scientific/Math

%description    -n libpolybori_groebner-%{pbori_vernaming}
This package contains the core Groebner library for %{name} for Boolean polynomial
data structures and Groebner basis algorithms.

%package        -n libpolybori-%{pbori_vernaming}
Summary:        Polynomial core library for %{name}
Group:          Productivity/Scientific/Math

%description    -n libpolybori-%{pbori_vernaming}
This package contains the polynomial core library for %{name} for Boolean polynomial
data structures and Groebner basis algorithms.

%package        gui
Summary:        Qt GUI for %{name}
Group:          Productivity/Scientific/Math
Requires:       python-%{name} = %{version}
Requires:       %{pbori_pyqt} 


%description    gui
This packagae contains a PyQt-based GUI for %{name}. It comes with the simple
tool PolyGUI which can load digital systems stored in various formats. The
user can easily compute Groebner bases and switch between different
heuristics and parameters on click.



%package        devel
Summary:        Development files for %{name}
Group:          Development/Libraries/C and C++
Requires:       %{name} = %{version}
Requires:       libpolybori-%{pbori_vernaming} = %{version}
Requires:       libpolybori_groebner-%{pbori_vernaming} = %{version}
Requires:       boost-devel %{?pbori_m4ri_devel}

%description    devel
This package contains headers and runtime libraries for %{name}. It may to
be used for developing computer-algebra applications for Boolean polynomials.



%package        static
Summary:        Static libraries for %{name}
Group:          Development/Libraries/C and C++
Requires:       %{name}-devel = %{version}

%description    static
This package contains static libraries for %{name}. It may to be used for
developing computer-algebra applications for Boolean polynomials without using
having shared libraries in place at runtime.

%if %{pbori_have_not_mr4i_rpm}
%package        -n m4ri
Summary:        The linear algebra dependency for %{name}
Group:          Development/Libraries/C and C++

%description    -n m4ri
This package contains m4ri runtime libraries for %{name}.
This is just for experminents, if the actual m4ri rpm is not available.
It should not be used for public rpms.

%package        -n m4ri-devel
Summary:        The linear algebra dependency for %{name}
Group:          Development/Libraries/C and C++
Requires:       m4ri = %{version}

%description    -n m4ri-devel
This package contains m4ri development libraries and headers for %{name}.
This is just for experminents, if the actual m4ri rpm is not available.
It should not be used for public rpms.
%endif

%define pbori_scons scons %{?jobs:-j%jobs} \\\
        LINKFLAGS="-s" CCFLAGS="%{optflags}" \\\
        EPREFIX=%{buildroot}%{_bindir} \\\
        DEVEL_PREFIX=%{buildroot}%{_prefix} \\\
        DEVEL_INCLUDE_PREFIX=%{buildroot}%{_includedir} \\\
        DEVEL_LIB_PREFIX=%{buildroot}%{_libdir} \\\
        PYINSTALLPREFIX=%{buildroot}%{pbori_pyinstprefix} \\\
        INSTALLDIR=%{buildroot}%{pbori_instdir} \\\
        PYTHON=%{__python} \\\
        DOCDIR=%{buildroot}/%{pbori_docpath} \\\
        MANDIR=%{buildroot}%{_mandir} %{?pbori_mr4i_url}


%prep
%setup -q

%build
%{pbori_scons} prepare-install prepare-devel 
 

%check
%if %{pbori_check}
%{pbori_scons} testsuite/unittests && testsuite/unittests
%endif
ipbori/ipbori -t

%install
%{pbori_scons} install devel-install
%{__mv } $RPM_BUILD_ROOT/%{pbori_docpath} %{pbori_tmpdoc}

%clean
rm -rf $RPM_BUILD_ROOT

%post -n libpolybori-%{pbori_vernaming}  -p /sbin/ldconfig
%post -n libpolybori_groebner-%{pbori_vernaming} -p /sbin/ldconfig
%postun -n libpolybori-%{pbori_vernaming} -p /sbin/ldconfig
%postun -n libpolybori_groebner-%{pbori_vernaming} -p /sbin/ldconfig
%if %{pbori_have_not_mr4i_rpm}
%post -n m4ri -p /sbin/ldconfig
%postun -n m4ri -p /sbin/ldconfig
%endif


%files
%defattr(-,root,root,-)
%attr(755, root, root) %{_bindir}/ipbori*
%attr(644,root,man) %{_mandir}/man1/ipbori*.1*
%{pbori_instdir}
%exclude %{pbori_instdir}/gui
%doc README LICENSE ChangeLog

%files -n libpolybori-%{pbori_vernaming}
%defattr(-,root,root,-)
%attr(755, root, root) %{_libdir}/libpolybori-${PBVERSION}.so.${PBRELEASE}*


%files -n libpolybori_groebner-%{pbori_vernaming}
%defattr(-,root,root,-)
%attr(755, root, root) %{_libdir}/libpolybori_groebner-${PBVERSION}.so.${PBRELEASE}*


%files -n python-%{name}
%defattr(-,root,root,-)
%{pbori_pyinstprefix}/polybori


%files doc
%defattr(-,root,root,-)
%doc README LICENSE ChangeLog %{pbori_tmpdoc}/*

%files gui
%defattr(-,root,root,-)
%attr(755, root, root) %{_bindir}/PolyGUI*
%attr(644,root,man) %{_mandir}/man1/PolyGUI*.1*
%{pbori_instdir}/gui

%files devel
%defattr(-,root,root,-)
%attr(755, root, root) %{_libdir}/libpolybori*.so
%{_includedir}/polybori
%{_includedir}/polybori.h
%doc README LICENSE ChangeLog

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

%if %{pbori_have_not_mr4i_rpm}
%files  -n m4ri
%defattr(-,root,root,-)
%attr(755, root, root) %{_libdir}/libm4ri-*.so*

%files  -n m4ri-devel
%defattr(-,root,root,-)
%attr(755, root, root) %{_libdir}/libm4ri.so
%attr(644, root, root) %{_libdir}/libm4ri.a
%{_includedir}/m4ri

%endif

%changelog
* Wed Feb 13 2012 Alexander Dreyer <adreyer@gmx.de> ${PBVERSION}.${PBRELEASE}-0
- Latest sources (PolyBoRi ${PBVERSION}.${PBRELEASE})
* Mon Feb 13 2012 Alexander Dreyer <adreyer@gmx.de> - 
- Libraries moved to libs package.
* Wed Aug 17 2011 Alexander Dreyer <adreyer@gmx.de> - 
- Releasing PolyBoRi 0.8.0.
* Tue Aug 16 2011 Alexander Dreyer <adreyer@gmx.de> - 
- Adding -devel, -gui-and -static packages.
* Tue Apr 26 2011 Alexander Dreyer <adreyer@gmx.de> - 
- Updating sources to PolyBoRi 0.7.1.
* Wed Apr 20 2011 Alexander Dreyer <adreyer@gmx.de> - 
- Updating SPEC file, added PolyGUI, splitted doc and python.
* Fri Jan 29 2010 Alexander Dreyer <adreyer@gmx.de> - 
- Updating sources (PolyBoRi 0.6-4).
* Tue Mar 31 2009 Alexander Dreyer <adreyer@gmx.de> - 
- Updating sources (PolyBoRi 0.6-0).
* Mon Jul 08 2008 Alexander Dreyer <adreyer@gmx.de> - 
- Updating sources (PolyBoRi 0.5-0).
* Sun May 04 2008 Alexander Dreyer <adreyer@gmx.de> - 
- Updating sources, adding man page (PolyBoRi 0.4-0).
* Thu Mar 13 2008 Alexander Dreyer <adreyer@gmx.de> - 
- Updating sources (PolyBoRi 0.3-1).
* Wed Mar 07 2008 Alexander Dreyer <adreyer@gmx.de> - 
- More standard-conforming rpm (PolyBoRi 0.3-0).
* Wed Feb 13 2008 Alexander Dreyer <adreyer@gmx.de> - 
- Initial build (PolyBoRi 0.2-0).
