# Check whether GnuCash should be build with or without the Postgres backend.
# When building GnuCash, pass "--with postgres" or "--without postgres"
# options, as in
#    rpmbuild --with postgres -bb gnucash.spec
%if "%{_with_postgres}" == "--with-postgres"
  %define _with_postgres 1
  %define sql_config --enable-sql
%else
  %define _with_postgres 0
  %define sql_config --disable-sql
%endif
%define version @VERSION@
%define __libtoolize /bin/true

Name:      	gnucash
Summary:   	GnuCash is an application to keep track of your finances.
Version:   	%{version}
Release:  	1
Copyright: 	Free Software Foundation
Group:     	Applications/Finance
URL:            http://www.gnucash.org
Source:    	http://www.gnucash.org/pub/gnucash/sources/stable/gnucash-%{version}.tar.gz
BuildRoot: 	%{_tmppath}/%{name}-%{version}-root
Requires:  	gnome-libs >= 1.2.0, gdk-pixbuf >= 0.2.5, gnome-print >= 0.21
Requires:	guile >= 1.3.4, gtkhtml >= 0.8, Guppi >= 0.35.3
Requires:	g-wrap >= 1.3.2, umb-scheme >= 3.2, gal >= 0.8
BuildPrereq: 	g-wrap-devel >= 1.3.2, gtkhtml-devel >= 0.8
BuildPrereq: 	Guppi-devel, gal-devel, libxml-devel
BuildPrereq: 	libglade-devel, libghttp-devel, python-devel, libtermcap-devel
BuildPrereq: 	readline-devel
Prereq: 	/sbin/ldconfig /sbin/install-info

%description
GnuCash is a personal finance manager. A check-book like
register GUI allows you to enter and track bank accounts,
stocks, income and even currency trades. The interface is
designed to be simple and easy to use, but is backed with
double-entry accounting principles to ensure balanced books.


%if %{_with_postgres}
%package backend-postgres
Summary: Backend for storing GnuCash data in a PostgreSQL database.
Group: Applications/Finance
Requires: gnucash = %{version}
Requires: postgres >= 7.1.3

%description backend-postgres

This package contains a backend for storing your GnuCash accounts and
transactions in a PostgreSQL database.  Install this package if you
want to keep your financial data in a database instead of a flat file
(recommended for large volumes of data and commercial sites).
%endif


%package devel
Summary: Header files for GnuCash development.
Group: Development/Libraries
Requires: gnucash = %{version}

%description devel
This package contains header files for GnuCash development.
Install this package if you want to use GnuCash libraries
in C programs.

%prep
%setup -q

%build
autoconf
%configure %{sql_config}

make RPM_OPT_FLAGS="$RPM_OPT_FLAGS"

cp -p src/backend/postgres/README README.postgres

%install
[ "$RPM_BUILD_ROOT" != "/" ] && rm -rf $RPM_BUILD_ROOT

LIBRARY_PATH=$RPM_BUILD_ROOT%{_libdir}:$RPM_BUILD_ROOT%{_libdir}/gnucash make DESTDIR=$RPM_BUILD_ROOT install

%find_lang %name

%clean
[ "$RPM_BUILD_ROOT" != "/" ] && rm -rf $RPM_BUILD_ROOT

%post
/sbin/ldconfig
/sbin/install-info %{_infodir}/gnucash-design.info.gz %{_infodir}/dir

%postun
/sbin/ldconfig
if [ $1 = 0 ]; then
   /sbin/install-info --delete %{_infodir}/gnucash-design.info.gz %{_infodir}/dir
fi

%files -f %{name}.lang
%defattr(444,root,root,755)
%attr(555,root,root) %{_bindir}/*
%attr(555,root,root) %{_libexecdir}/gnucash
%attr(555,root,root) %{_datadir}/gnucash/finance-quote-helper
%{_mandir}/man1/*
%{_infodir}/*.gz
%{_libdir}/gnucash/libgnc-*
%{_libdir}/gnucash/libgncmod-[a,c-z]*
%{_libdir}/gnucash/libgncmod-b[b-z]*
%{_libdir}/gnucash/libgncmod-backend-file*
%{_libdir}/gnucash/libgw*
%{_libdir}/lib*
%dir %{_datadir}/gnucash
%{_datadir}/gnucash/accounts
%{_datadir}/gnucash/doc
%{_datadir}/gnucash/glade
%{_datadir}/gnucash/guile-modules
%{_datadir}/gnucash/scm
%{_datadir}/gnome/help/gnucash
%{_datadir}/gnome/apps/Applications/*
%{_datadir}/pixmaps/gnucash
%{_datadir}/mime-info/gnucash.*
%config %{_sysconfdir}/gnucash
%doc AUTHORS COPYING ChangeLog ChangeLog.1 HACKING NEWS README README.patches
%doc doc/README.german doc/README.francais doc/guile-hackers.txt


%if %{_with_postgres}
%files backend-postgres
%{_libdir}/gnucash/libgncmod-backend-postgres*
%doc README.postgres
%endif

%files devel
%{_includedir}/gnucash
%{_datadir}/aclocal/gnucash.m4
