# -*- 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

PortSystem              1.0
PortGroup               app 1.0
PortGroup               active_variants 1.1

name                    pspp
version                 1.6.2
revision                1

categories              math
license                 GPL-3+
maintainers             {snc @nerdling}
conflicts               pspp-devel
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                https://www.gnu.org/software/pspp/
master_sites            gnu

checksums           rmd160  56bc0b078e2bae6283df80ad270bfdb195d245ff \
                    sha256  73294ca2f5b2f7fc41bbf8b78c5888c8075f43c6097fd482abb04f85ab0847b6 \
                    size    9249366

depends_lib-append  path:lib/pkgconfig/cairo.pc:cairo \
                    port:appstream-glib \
                    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:spread-sheet-widget \
                    port:zlib

depends_build-append    port:gettext \
                        path:bin/pkg-config:pkgconfig \
                        port:texinfo

depends_build-append    port:python310
configure.python        ${prefix}/bin/python3.10
configure.env-append    PYTHON3=${configure.python}

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

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

configure.args-append   --disable-rpath \
                    --without-libpq \
                    --without-gui \
                    --without-perl-module \
                    --with-packager=snc \
                    --with-packager-version=${version} \
                    --with-packager-bug-reports=[lindex ${maintainers} 0 0]

# matrix.c:465: error: redefinition of typedef ‘matrix_proto_d_dd’
# matrix.c:714: error: unknown field ‘subs’ specified in initializer
compiler.blacklist-append \
                        *gcc-4.0 *gcc-4.2

test.run                yes
test.target             check

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

variant doc description {Build documentation} {
    build.target-append  html
}

variant reloc requires quartz description {Enable relocation build for app bundle} {
    configure.args-append --enable-relocatable
}

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 \
                            path:lib/pkgconfig/gdk-pixbuf-2.0.pc:gdk-pixbuf2 \
                            port:gtksourceview3
    depends_run-append      port:adwaita-icon-theme

    configure.args-delete   --without-gui
}

variant quartz requires gui {
    require_active_variants gtk3 quartz
    require_active_variants gtksourceview3 quartz
}

variant x11 requires gui {
    require_active_variants gtk3 x11
    depends_lib-append  port:xorg-libX11 \
                        port:xorg-libXau \
                        port:xorg-libXcomposite \
                        port:xorg-libXcursor \
                        port:xorg-libXdamage \
                        port:xorg-libXdmcp \
                        port:xorg-libXext \
                        port:xorg-libXfixes \
                        port:xorg-libXi \
                        port:xorg-libXinerama \
                        port:xorg-libXrandr \
                        port:xorg-libxcb \
                        port:xrender
}

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

# check for x11-poisoned dependencies
set x11 no
set depspecs {gtk3}
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
