# -*- 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 55455 2009-08-11 02:58:43Z snc@macports.org $

PortSystem              1.0

name                    pspp
revision                2
version                 0.6.1
categories              math
#license                 GPLv3+
maintainers             snc
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            gnu

checksums               md5 b871739200938820d8db898cd200ed06 \
                        sha1 22f335053a3e1d3861bfc2d87536b9a6fc5a1ae7 \
                        rmd160 930fc58b77ff50819cd7449147dab5906e872850

use_parallel_build      yes

depends_build           path:bin/perl:perl5 \
                        port:pkgconfig
configure.perl          ${prefix}/bin/perl

depends_lib		        port:gsl \
                        port:libiconv \
                        port:zlib \
                        port:libxml2 \
                        port:readline

configure.args          --disable-rpath \
                        --without-gui \
                        --without-libplot \
                        --without-libpq \
                        --enable-debug \
                        --without-libncurses

patchfiles              patch-config.h.in.diff

variant ncurses description {Enable terminal resizing} {
    depends_lib-append  port:ncursesw
    configure.args-delete   --without-libncurses
}

variant doc description {Build documentation} {
    depends_lib-append   port:texinfo
    build.target-append  pdf html
    post-destroot {
        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}
        }
    }
}

variant postgres description {Enables reading of postgresql databases} {
    depends_lib-append  port:postgresql83
    configure.args-delete   --without-libpq
    configure.ldflags-append -L${prefix}/lib/postgresql83
}

variant graph description {Enable graphing features (default)} {
    depends_lib-append  port:plotutils
    configure.args-delete   --without-libplot
}

variant gui description {Enable PSPPIRE, the graphical interface (default)} {
    depends_lib-append      port:pkgconfig \
                            port:gtk2 \
                            port:libglade2
    configure.args-delete   --without-gui
}

default_variants        +graph +gui

post-destroot {
    delete ${destroot}${prefix}/lib/charset.alias

    xinstall -d ${destroot}${prefix}/libexec/${name}

    move ${destroot}${prefix}/bin/pspp ${destroot}${prefix}/libexec/${name}/pspp

    xinstall -m 755 ${filespath}/pspp.in ${destroot}${prefix}/bin/pspp
    reinplace s|@PREFIX@|${prefix}|g ${destroot}${prefix}/bin/pspp
    reinplace s|@NAME@|${name}|g ${destroot}${prefix}/bin/pspp

    if {[variant_isset gui]} {
        ln -s ${prefix}/lib/pspp/libpsppire.dylib \
            ${destroot}${prefix}/lib/pspp/libpsppire.so
        ln -s ${prefix}/lib/pspp/libpsppwidgets.dylib \
            ${destroot}${prefix}/lib/pspp/libpsppwidgets.so

        move ${destroot}${prefix}/bin/psppire \
			${destroot}${prefix}/libexec/${name}/psppire

        xinstall -m 755 ${filespath}/psppire.in ${destroot}${prefix}/bin/psppire
        reinplace s|@PREFIX@|${prefix}|g ${destroot}${prefix}/bin/psppire
        reinplace s|@NAME@|${name}|g ${destroot}${prefix}/bin/psppire

	    xinstall -d ${destroot}${applications_dir}/PSPP.app/Contents/MacOS
	    xinstall -m 644 ${filespath}/PSPP.app/Contents/Info.plist \
		    ${destroot}${applications_dir}/PSPP.app/Contents
        reinplace s|@VERSION@|${version}|g \
            ${destroot}${applications_dir}/PSPP.app/Contents/Info.plist
        reinplace s|@NAME@|${name}|g \
            ${destroot}${applications_dir}/PSPP.app/Contents/Info.plist
	    copy ${destroot}${prefix}/bin/psppire \
		    ${destroot}${applications_dir}/PSPP.app/Contents/MacOS
	    reinplace "s|psppire|psppire \\&|g" \
	     	${destroot}${applications_dir}/PSPP.app/Contents/MacOS/psppire
	    xinstall -m 644 ${filespath}/PSPP.app/Contents/PkgInfo \
	     	${destroot}${applications_dir}/PSPP.app/Contents
    }
}
