#
# Spec file for Fedora and other RedHat distros and derivatives
#
# Check whether GnuCash should build optional modules.
# To modify parameters, edit the .spec file, 0 is off, 1 is on
%define _with_postgres 0
%define _with_ofx 1
%define _with_hbci 1
%define _with_dbi 1

# The --whatprovides redhat-release lets us work on RHEL as well as FC
# Granted, it will look weird, but at least it wont fail outright.
%define fc_rel %(rpm -q --queryformat='%{VERSION}' --whatprovides redhat-release)

# Edit dist if not a Fedora release
%define dist FC%{fc_rel}

%define version 2.6.12
%define __libtoolize /bin/true

%define libgnomeui_version 2.8.0
%define libgnomeprintui_version 2.8.0
%define guile_version 1.6.0
%define gtkhtml3_version 3.1
%define libofx_version 0.8.0
%define aqbanking_version 1.3
%define postgresql_version 7.1.3

Name:      	gnucash
Summary:   	GnuCash is an application to keep track of your finances.
Version:   	%{version}
Release:  	1.%{dist}
License:	GPL
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

Prereq:         GConf2
Prereq:         /usr/bin/gconftool-2
Prereq: 	/sbin/ldconfig
PreReq:		/sbin/install-info

Requires:  	libgnomeui >= %{libgnomeui_version}
Requires:	libgnomeprintui22 >= %{libgnomeprintui22_version}
Requires:	guile >= %{guile_version}
Requires:	gtkhtml3 >= %{gtkhtml3_version}
Requires:	slib >= 3a1

BuildRequires:  gcc, intltool
BuildRequires: 	libgnomeui-devel >= %{libgnomeui_version}
BuildRequires: 	libgnomeprintui22-devel >= %{libgnomeprintui22_version}
BuildRequires: 	gtkhtml3-devel >= %{gtkhtml3_version}
BuildRequires: 	bzip2-devel, expat-devel, guile-devel
BuildRequires: 	libglade2-devel, libgsf-devel
BuildRequires: 	libjpeg-devel, openssl-devel
BuildRequires:	goffice-devel

%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.


%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.


%if %{_with_ofx}
%package ofx
Summary: Enables OFX importing in GnuCash
Group: Applications/Finance
Requires: gnucash = %{version}
Requires: libofx >= %{libofx_version}
BuildRequires: libofx-devel

%description ofx
This package adds OFX file import support to the base
GnuCash package. Install this package if you want to
import OFX files.
%endif

%if %{_with_hbci}
%package hbci
Summary: Enables HBCI importing in GnuCash
Group: Applications/Finance
Requires: gnucash = %{version}
Requires: aqbanking >= %{aqbanking_version}
BuildRequires: aqbanking-devel

%description hbci
This package adds HBCI file import support to the base
GnuCash package. Install this package if you want to
import HBCI files.
%endif

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

%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

%if %{_with_dbi}
%package backend-dbi
Summary: DBI Backend for storing GnuCash data databases.
Group: Applications/Finance
Requires: gnucash = %{version}
Requires: libdbi
BuildRequires: libdbi-devel

%description backend-dbi
This package contains a backend for storing GnuCash accounts in databases
using the libdbi package.  To enable this functionality, you must install
one or more of the libdbi-dbd-* driver packages (e.g.  libdbi-dbd-mysql,
libdbi-dbd-sqlite or libdbi-dbd-pgsql).
%endif

%prep
%setup -q

%build
%configure \
%if %{_with_ofx}
 --enable-ofx \
%endif
%if %{_with_hbci}
 --enable-aqbanking \
%endif
%if %{_with_postgres}
 --enable-sql \
%endif
%if %{_with_dbi}
 --enable-dbi \
%endif
 --enable-gui


make RPM_OPT_FLAGS="$RPM_OPT_FLAGS"

%if %{_with_postgres}
cp -p src/backend/postgres/README README.postgres
%endif

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

export GCONF_DISABLE_MAKEFILE_SCHEMA_INSTALL=1
LIBRARY_PATH=$RPM_BUILD_ROOT%{_libdir}:$RPM_BUILD_ROOT%{_libdir}/gnucash make DESTDIR=$RPM_BUILD_ROOT install
unset GCONF_DISABLE_MAKEFILE_SCHEMA_INSTALL

%find_lang %name

[ "$RPM_BUILD_ROOT" != "/" ] && rm -rf $RPM_BUILD_ROOT/%{_infodir}/dir

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

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

export GCONF_CONFIG_SOURCE=`gconftool-2 --get-default-source`
SCHEMAS=%{_sysconfdir}/gconf/schemas/apps_gnucash*.schemas
for S in $SCHEMAS; do
  gconftool-2 --makefile-install-rule $S > /dev/null
done

%preun
if [ "$1" -eq 0 ]; then
     #deleting the schema on package removal
     export GCONF_CONFIG_SOURCE=`gconftool-2 --get-default-source`
     SCHEMAS=%{_sysconfdir}/gconf/schemas/apps_gnucash*.schemas
     for S in $SCHEMAS; do
       gconftool-2 --makefile-uninstall-rule $S > /dev/null
     done
fi

%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
%{_mandir}/man*/*
%{_infodir}/gnucash*info*
%{_libdir}/*
%{_datadir}/gnucash
%{_datadir}/applications/*
%{_datadir}/xml/gnucash/xsl/*
%{_datadir}/icons/*
%{_sysconfdir}/gconf/schemas/apps_gnucash*
%if %{_with_ofx}
%exclude %{_libdir}/gnucash/libgncmod-ofx*
%endif
%if %{_with_hbci}
%exclude %{_libdir}/gnucash/libgncmod-aqbanking*
%exclude %{_datadir}/gnucash/glade/aqbanking*
%exclude %{_sysconfdir}/gconf/schemas/apps_gnucash_dialog_hbci.schemas
%endif
%if %{_with_postgres}
%exclude %{_libdir}/libgnc-backend-postgres*
%endif
%if %{_with_dbi}
%exclude %{_libdir}/gnucash/libgncmod-backend-dbi*
%endif
%config %{_sysconfdir}/gnucash
%doc AUTHORS COPYING ChangeLog* DOCUMENTERS HACKING LICENSE NEWS README
%doc doc/README.german doc/README.francais doc/guile-hackers.txt

%files devel
%defattr(444,root,root,755)
%{_includedir}/gnucash

%if %{_with_ofx}
%files ofx
%defattr(444,root,root,755)
%{_libdir}/gnucash/libgncmod-ofx*
%doc doc/README.OFX
%endif

%if %{_with_hbci}
%files hbci
%defattr(444,root,root,755)
%{_libdir}/gnucash/libgncmod-aqbanking*
%{_datadir}/gnucash/glade/aqbanking*
%{_sysconfdir}/gconf/schemas/apps_gnucash_dialog_hbci.schemas
%doc doc/README.HBCI
%endif

%if %{_with_postgres}
%files backend-postgres
%defattr(444,root,root,755)
%{_libdir}/libgnc-backend-postgres*
%doc README.postgres
%endif

%if %{_with_dbi}
%files backend-dbi
%defattr(444,root,root,755)
%{_libdir}/gnucash/libgncmod-backend-dbi*
%endif
