# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
# $Id: Portfile 40399 2008-09-30 15:40:42Z macsforever2000@macports.org $

PortSystem        1.0

name              gnucash
version           2.2.7
revision          1

categories        gnome x11
maintainers       nomaintainer
platforms         darwin

description       a personal and small-business financial-accounting software
long_description  GnuCash is a personal and small-business \
                  financial-accounting software, freely licensed under the \
                  GNU GPL.  Designed to be easy to use, yet powerful and \
                  flexible, GnuCash allows you to track bank accounts, \
                  stocks, income and expenses. As quick and intuitive to \
                  use as a checkbook register, it is based on professional \
                  accounting principles to ensure balanced books and \
                  accurate reports.

homepage          http://www.gnucash.org/
master_sites      sourceforge \
                  http://www.gnucash.org/pub/gnucash/sources/stable/
use_bzip2         yes
checksums         md5 0f3f324c274b136070b769aa10591ccf \
                  sha1 55aeb126de4b195b3a84b8fe88cc16e8679f3cc5 \
                  rmd160 db6cf249ca8f2a2497d48b4a1815b6ae5c681b97

depends_lib       port:p5-xml-parser \
                  path:${prefix}/lib/pkgconfig/glib-2.0.pc:glib2 \
                  port:gconf \
                  port:guile16 \
                  port:slib \
                  port:slib-guile16 \
                  port:popt \
                  port:libgnomeui \
                  port:libgnomeprintui \
                  port:libgtkhtml3 \
                  port:libgsf \
                  port:goffice \
                  port:aqbanking3 \
                  port:libofx \
                  port:p5-finance-quote

depends_build     port:libtool
depends_run       port:evince

configure.args    --disable-glibtest \
                  --disable-dependency-tracking --enable-hbci --enable-ofx

patchfiles        patch-configure.diff patch-lib_libc_libc-missing-noop.c.diff

post-patch {
    reinplace "/^DYLD_LIBRARY_PATH/s|=\"|=\"/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ImageIO.framework/Versions/A/Resources@-PATH_SEPARATOR-@|" ${worksrcpath}/src/bin/gnucash.in
    reinplace "/^DYLD_LIBRARY_PATH/s|=\"|=\"/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ImageIO.framework/Versions/A/Resources@-PATH_SEPARATOR-@|" ${worksrcpath}/src/bin/overrides/gnucash-env.in
    fs-traverse src_file ${worksrcpath}/src {
        if { [ file isfile ${src_file} ] } {
            reinplace "s|\\<guile\\/|\\<guile16\\/|g"   ${src_file}
            reinplace "s|libguile\\.h|libguile16\\.h|g" ${src_file}
            reinplace "s|exec\\ guile|exec\\ guile16|g" ${src_file}
        }
    }
}

variant without_quotes description {Does not depend on building p5-finance-quote} {
    depends_lib-delete  port:p5-finance-quote
}

variant without_hbci description {Disables HBCI support} {
    depends_lib-delete  port:aqbanking3
    configure.args-delete   --enable-hbci
    configure.args-append   --disable-hbci
}

variant without_ofx description {Disables ofx support} {
    depends_lib-delete  port:libofx
    configure.args-delete   --enable-ofx
    configure.args-append   --disable-ofx
}

set storagedir  ${prefix}/etc/macports/gconf
set storagefile $storagedir/${name}

post-destroot {
    # We need to register some stuff to gconf. Just putting the
    # schema files to the right place is not enough.
    # For now we store the files in
    # ${prefix}/etc/macports/gconf/${name} and use that file
    # in post-activate. Until there is no better solution
    # this will make it into the gnomeportgroup

    fs-traverse schema ${destroot}${prefix}/etc/gconf/schemas {
        if { [ file isfile $schema ] } {
            lappend schemafiles $schema
        }
    }

    if { [ llength $schemafiles ] > 0 } {
        file mkdir ${destroot}${storagedir}
        set fh [open ${destroot}${storagefile} w]
        foreach file $schemafiles {
            puts $fh [exec basename $file]
        }
        close $fh
    }
}

post-activate {
    if { [file exists ${storagefile} ] } {
        set fh [open ${storagefile} r]
        while { ! [eof $fh] } {
            lappend schemafiles [gets $fh]
        }
        close $fh
    }

    set schemastring [join $schemafiles " "]

        system "cd ${prefix}/etc/gconf/schemas && \
        GCONF_CONFIG_SOURCE=`${prefix}/bin/gconftool-2 --get-default-source` ${prefix}/bin/gconftool-2 --makefile-install-rule $schemastring"
}

