# -*- 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 deprecated 1.0
PortGroup openssl 1.0

# Final release was on 2013-02-07
deprecated.eol_version yes

# building arm64 fails with unsupported option '-mthreads' and unsupported spinlock
supported_archs i386 ppc ppc64 x86_64

name            postgresql83
version         8.3.23
revision        7

categories      databases
maintainers     nomaintainer
license         Permissive
description     The most advanced open-source database available anywhere.
long_description PostgreSQL is Object-Relational Database Management System. \
                It supports almost all SQL constructs, including transactions, \
                subselects, and user-defined types and functions. Write-ahead \
                logging means increased performance while retaining data \
                integrity.

homepage        https://www.postgresql.org/
master_sites    http://ftp3.de.postgresql.org/pub/Mirrors/ftp.postgresql.org/source/v${version}/ \
                postgresql:source/v${version}/
distname        postgresql-${version}

checksums       rmd160  ac0ee6a829f04e7cdca0179a2c881244c54f31cd \
                sha256  17a46617ddbeb16f37d79b43f4e72301b051e6ef888a2eac960375bf579018d9

use_bzip2       yes

universal_variant   no

openssl.branch  1.0
depends_lib     port:readline port:zlib port:libxml2 port:libxslt port:ossp-uuid
depends_build   port:bison

worksrcdir      postgresql-${version}

patchfiles      src_pl_plpython_Makefile.patch

set libdir      ${prefix}/lib/${name}
configure.args  --sysconfdir=${prefix}/etc/${name} \
                --bindir=${libdir}/bin \
                --libdir=${libdir} \
                --includedir=${prefix}/include/${name} \
                --datadir=${prefix}/share/${name} \
                --mandir=${prefix}/share/man \
                --without-docdir \
                --with-includes=${prefix}/include \
                --with-libraries=${prefix}/lib \
                --with-openssl \
                --with-bonjour \
                --with-readline \
                --with-zlib \
                --with-libxml \
                --with-libxslt \
                --enable-thread-safety \
                --enable-integer-datetimes \
                --with-ossp-uuid
configure.cppflags-append   -I${prefix}/include/ossp

build.type      gnu
build.target

test.run        yes
test.target     check

livecheck.type  none

platform darwin {
    if {${os.major} >= 12} {
        patchfiles-append   postgresql-uuid-ossp.patch
    }
    if {${os.major} >= 13} {
        configure.args-replace  --with-bonjour --without-bonjour
    }
}

set contribs    "adminpack dblink fuzzystrmatch lo oid2name pageinspect pg_buffercache pg_freespacemap pg_standby pg_trgm pgcrypto pgrowlocks pgstattuple tablefunc uuid-ossp vacuumlo"

post-build {
    foreach contrib ${contribs} {
        system "cd ${worksrcpath}/contrib/${contrib}/ && ${build.cmd}"
    }
}

post-destroot {
    foreach contrib ${contribs} {
        system "echo contrib: \"${contrib}\""
        system "cd ${worksrcpath}/contrib/${contrib}/ && \
            ${destroot.cmd} install ${destroot.destdir} && touch DONE"
    }
    system "cd ${destroot}${prefix}/bin && ln -sf ${libdir}/bin/psql psql83"
    file delete -force ${destroot}${prefix}/share/doc/${name} \
        ${destroot}${prefix}/share/man
}

variant python requires python27 description {add support for python} {
}

variant python27 description {add support for python 2.7} {
    depends_lib-append      port:python27
    configure.args-append   --with-python
    configure.python        ${prefix}/bin/python2.7
}

variant krb5 description {add support for Kerberos 5 authentication} {
    configure.args-append   --with-krb5
}

variant perl description {add Perl support (requires perl with +shared)} {
    depends_lib-append      bin:perl:perl5
    configure.args-append   --with-perl
}

variant tcl description {add Tcl support} {
    depends_lib-append      port:tcl
    configure.args-append   --with-tcl --with-tclconfig=${prefix}/lib
    configure.env-append    TCLSH=${prefix}/bin/tclsh
}

notes "To use the postgresql server, install the postgresql83-server port\n\
NB! This is the last update to postgresql83,\n\
please upgrade to a later version!"
