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

name                pgAdmin3
version             1.22.2
revision            8

categories          aqua
maintainers         nomaintainer

description         An administration program to PostgreSQL
long_description    pgAdmin III is a powerful administration and development \
                    platform for the PostgreSQL database, free for any use. The \
                    application works on several platforms, e.g. GNU/Linux, FreeBSD, \
                    OS X and Windows 2000/XP. This port is for OS X.

platforms           macosx
supported_archs     i386 ppc ppc64 x86_64
license             Permissive
homepage            https://www.pgadmin.org

master_sites        https://developer.pgadmin.org/ftp/release/v${version}/src/ \
                    https://www.postgresql.org/ftp/pgadmin/pgadmin3/v${version}/src/ \
                    postgresql:pgadmin/pgadmin3/v${version}/src/

distname            pgadmin3-${version}

checksums           rmd160  48e732089cd1879f99d1894229a9cc23ed3c0c44 \
                    sha256  9b68b0e3d3f0a261344fb8196825967d1e7acaca1d8cc82c42e12368ca5844ac \
                    size    14788481

if {${os.platform} eq "darwin" && ${os.major} > 11} {
    wxWidgets.use   wxWidgets-3.0
} else {
    wxWidgets.use   wxGTK-3.0
}

# For unknown reasons pgAdmin3.app/Contents/MacOS/pgAdmin3 still links to
# libcrypto.dylib, so the openssl dependency is needed even if pgAdmin3
# is built with libgcrypt.
depends_lib         port:libgcrypt \
                    port:libxml2 \
                    port:libxslt \
                    path:lib/libssl.dylib:openssl \
                    port:${wxWidgets.port}

patchfiles          patch-configure.diff

configure.args      --enable-appbundle \
                    --with-arch-${configure.build_arch} \
                    --with-libgcrypt=${prefix} \
                    --with-libxml2=${prefix} \
                    --with-libxslt=${prefix} \
                    --with-openssl=no \
                    --with-wx=${wxWidgets.prefix} \
                    --with-wx-version=${wxWidgets.version}

universal_variant   no
# Despite universal being disabled in the port, the build still tries
# to force extra flags, so make sure it does not happen.
# gcc-4.2: -E, -S, -save-temps and -M options are not allowed with multiple -arch flags
configure.args-append \
                    am__universal=0

# mv: rename pgscript/utilities/m_apm/.deps/mapm_add.Tpo
# to pgscript/utilities/m_apm/.deps/mapm_add.Po: No such file or directory
use_parallel_build  no

build.target        all install

post-configure {
    system -W ${worksrcpath} "patch -p0 <${filespath}/patch-Makefile.diff"
    reinplace "s;wxrc;${wxWidgets.wxrc};" ${worksrcpath}/pgadmin/ui/embed-xrc
}

destroot.violate_mtree yes
destroot {
    xinstall -d -m 0755 ${destroot}${applications_dir}
    file copy ${worksrcpath}/${name}.app ${destroot}${applications_dir}/${name}.app
}

variant postgresql91 conflicts postgresql92 postgresql93 postgresql94 postgresql95 postgresql96\
    description {support for PostgreSQL 9.1.x} {
    depends_lib-append      port:postgresql91
    configure.args-append   --with-pgsql=${prefix}/lib/postgresql91
}

variant postgresql92 conflicts postgresql91 postgresql93 postgresql94 postgresql95 postgresql96\
    description {support for PostgreSQL 9.2.x} {
    depends_lib-append      port:postgresql92
    configure.args-append   --with-pgsql=${prefix}/lib/postgresql92
}

variant postgresql93 conflicts postgresql91 postgresql92 postgresql94 postgresql95 postgresql96\
    description {support for PostgreSQL 9.3.x} {
    depends_lib-append      port:postgresql93
    configure.args-append   --with-pgsql=${prefix}/lib/postgresql93
}

variant postgresql94 conflicts postgresql91 postgresql92 postgresql93 postgresql95 postgresql96\
    description {support for PostgreSQL 9.4.x} {
    depends_lib-append      port:postgresql94
    configure.args-append   --with-pgsql=${prefix}/lib/postgresql94
}

variant postgresql95 conflicts postgresql91 postgresql92 postgresql93 postgresql94 postgresql96 \
    description {support for PostgreSQL 9.5.x} {
    depends_lib-append      port:postgresql95
    configure.args-append   --with-pgsql=${prefix}/lib/postgresql95
}

variant postgresql96 conflicts postgresql91 postgresql92 postgresql93 postgresql94 postgresql95 \
    description {support for PostgreSQL 9.6.x} {
    depends_lib-append      port:postgresql96
    configure.args-append   --with-pgsql=${prefix}/lib/postgresql96
}

if {![variant_isset postgresql91] && ![variant_isset postgresql92]  && ![variant_isset postgresql93] && ![variant_isset postgresql94] && ![variant_isset postgresql95]} {
    default_variants        +postgresql96
}

variant debug description {provide a debug build in case of difficulties} {
    configure.args-append   --enable-debug
}

livecheck.type      regex
livecheck.url       https://www.pgadmin.org/download/source.php
livecheck.regex     pgAdmin v(1\\.\[0-9\]+\\.\[0-9\]+)
