# $Id: Portfile 34007 2008-02-10 12:37:16Z gui_dos@macports.org $

PortSystem 1.0

name            chmsee
version         1.0.0
revision        1
description     Viewer for CHM files.
long_description ChmSee is an HTML Help viewer for Unix/Linux. \
                It is based on CHMLIB and use Gtk2+ as frontend \
                toolkit. Because of using gecko as HTML rendering \
                engine, ChmSee can support rich features of modern \
                HTML page, such as CSS and JavaScript.
maintainers     nomaintainer
categories      x11
platforms       darwin
homepage        http://chmsee.gro.clinux.org/
master_sites    http://gro.clinux.org/frs/download.php/2040/
checksums       md5 65fddfe20f4a1537e539998201a0ccfd
depends_build   port:intltool
depends_lib     port:gtk2 \
                port:libglade2 \
                port:chmlib \
                port:openssl \
                port:firefox-x11
configure.args  --with-openssl=${prefix}
configure.cflags-append -I${prefix}/include/openssl
configure.ldflags-append -lssl -lcrypto

post-extract {
    reinplace "s|defined(__linux__)|defined(__APPLE__)|" ${worksrcpath}/src/chmfile.c
    
    #Changing fixed fonts doesn't work, therefore always use the original fonts 
    reinplace "s|use_document_fonts\", 0|use_document_fonts\", 1|" \
        ${worksrcpath}/src/default-prefs-common.js
}

post-destroot {
        # In order to call gecko, chmsee must be installed in the same directory as FireFox.
        # Move it and put a symlink in the bin directory
        if { [catch {set ff [registry_active "firefox-x11"]} result]} {
                ui_err "FireFox is not active: $result"
        } else {
                set ffver [lindex $ff 0 1]
                xinstall -d ${destroot}${prefix}/lib/firefox-${ffver}
                move ${destroot}${prefix}/bin/chmsee ${destroot}${prefix}/lib/firefox-${ffver}
                ln -s ${prefix}/lib/firefox-${ffver}/chmsee ${destroot}${prefix}/bin
        }
}
