# -*- 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 120220 2014-05-19 19:59:04Z snc@macports.org $

PortSystem          1.0
PortGroup           app 1.0
PortGroup           active_variants 1.1

name                pspp-devel
set buildstamp      20140519030502
set buildhash       g30b49e
version             0.8.3
revision            3
# depends_test port:p5.16-text-diff
categories          math
license             GPL-3+
maintainers         snc
conflicts           pspp
description         Statistical analysis of sampled data (free \
                    replacement for SPSS).
long_description    PSPP is a program for \
                    statistical analysis of sampled data. It is a Free \
                    replacement for the proprietary program SPSS, and \
                    appears very similar to it with a few exceptions.

homepage            http://www.gnu.org/software/pspp/
platforms           darwin

master_sites        http://pspp.benpfaff.org/~blp/pspp-master/${buildstamp}/source
distname            pspp-${version}-${buildhash}

depends_lib-append  path:lib/pkgconfig/cairo.pc:cairo \
                    port:fontconfig \
                    port:freetype \
                    port:gettext \
                    path:lib/pkgconfig/glib-2.0.pc:glib2 \
                    port:gsl \
                    port:libiconv \
                    port:libxml2 \
                    port:ncurses \
                    path:lib/pkgconfig/pango.pc:pango \
                    port:readline \
                    port:zlib

depends_build-append    port:pkgconfig

checksums           rmd160  8cf6d3088f891c94ab03552a5a5561e322a80f36 \
                    sha256  74a493107aee4a8ce2a98ca7c516eeffc7720cb8177f5662380bdc03e63d460c

post-extract {
    if {[variant_isset gui]} {
        copy ${filespath}/PSPP ${worksrcpath}
        file attributes ${worksrcpath}/PSPP -permissions ugo+rx
    }
}

post-patch {
    if {[variant_isset gui]} {
        reinplace s|@@PREFIX@@|${prefix}| ${worksrcpath}/PSPP
    }
}

#configure.cflags-append -g
configure.perl      ${prefix}/bin/perl
configure.args-append   --disable-rpath \
                        --without-libpq \
                        --without-gui \
                        --with-packager=snc \
                        --with-packager-version=${version}-${buildstamp} \
                        --with-packager-bug-reports=${maintainers}

set nif_compilers {macports-llvm-gcc-4.2 llvm-gcc-4.2}
if {[lsearch -exact ${nif_compilers} ${configure.compiler}] > -1} {
    configure.optflags-append -fno-inline-functions
}

build.target-append  html

test.run            yes
test.target         check
#test.env            TESTSUITEFLAGS='125 128 129 1007'

variant help requires gui description {Provide in-application help via yelp} {
    depends_run-append  port:yelp
}

variant postgres description {Enables reading of postgresql databases} {
    depends_lib-append  port:postgresql92
    configure.args-delete   --without-libpq
    configure.ldflags-append -L${prefix}/lib/postgresql92
    configure.env-append    PG_CONFIG=${prefix}/lib/postgresql92/bin/pg_config
}

variant gui description {Build PSPPIRE, the graphical interface} {
    depends_lib-append      port:atk \
                            port:gdk-pixbuf2 \
                            port:gtk2 \
                            port:gtksourceview2

    configure.args-delete   --without-gui
}

variant quartz requires gui {
    require_active_variants cairo quartz
    require_active_variants gtk2 quartz
    require_active_variants pango quartz
    require_active_variants gtksourceview2 quartz
}
variant x11 requires gui {
    require_active_variants cairo x11
    require_active_variants gtk2 x11
    require_active_variants pango x11
}

if {![variant_isset x11] && ![variant_isset quartz]} {
    default_variants +x11
}

# check for x11-poisoned dependencies
set x11 no
set depspecs {cairo gtk2 pango}
foreach depspec depspecs {
    if {![catch {set result [active_variants $depspec x11]}]} {
        if {$result} {
            $x11 yes
            break
         }
    }
}

# if x11 poison, depend on x11
if {[string is true -strict $x11]} {
    default_variants +x11
}

post-destroot {
    if {[variant_isset doc]} {
        xinstall -d -m 0755 ${destroot}${prefix}/share/doc/${name}
        foreach fl [glob -nocomplain -directory ${worksrcpath}/doc *.pdf *.html] {
            copy ${fl} ${destroot}${prefix}/share/doc/${name}
        }
    }
}

post-activate {
    system "${prefix}/bin/gtk-update-icon-cache --ignore-theme-index ${prefix}/share/icons/hicolor"

}

post-deactivate {
    system "${prefix}/bin/gtk-update-icon-cache --ignore-theme-index ${prefix}/share/icons/hicolor"
}

if {![variant_isset gui]} {
    app.create      no
}
app.name            PSPP
app.executable      ${worksrcpath}/PSPP
app.icon            ${filespath}/logo.png

livecheck.url               http://pspp.benpfaff.org/~blp/pspp-master/latest/i386/
livecheck.regex             <td>dist_version<\\/td><td>(.*)<\\/td>
livecheck.version           ${version}-${buildhash}
