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

# Final release was on 2011-12-05
deprecated.upstream_support no

name			postgresql82
version			8.2.23
revision  5

categories		databases
platforms		darwin
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           md5     7ecc63c517a8e79b86cd680214ec14fc \
                    sha1    f51ac2051c4b1c95f5f58bf75bbafc50d2bc359b \
                    rmd160  5a1d45cae1e7a9d9caa8e902608404b281bac7ff

use_bzip2		yes

depends_lib		port:readline path:lib/libssl.dylib:openssl port:zlib port:libxml2 port:libxslt
depends_build		port:bison

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 \
				--enable-thread-safety \
				--enable-integer-datetimes

if {${universal_possible} && [variant_isset universal]} {
    post-patch {
        xinstall -m 755 ${filespath}/ldfat.sh ${workpath}
        reinplace s|@UNIVERSAL_ARCHS@|${universal_archs}| ${workpath}/ldfat.sh
    }
    configure.env-append LD=${workpath}/ldfat.sh
    post-configure {
        system "cd ${worksrcpath}/src/include \
                && ed - pg_config.h < ${filespath}/pg_config.h.ed \
                && touch stamp-h"
        system "cd ${worksrcpath}/src/interfaces/ecpg/include \
                && ed - ecpg_config.h < ${filespath}/ecpg_config.h.ed \
                && touch stamp-h"
    }
}

build.type		gnu
build.target

test.run		yes
test.target		check

livecheck.type	none

platform darwin {
    if {${os.major} >= 13} {
        configure.args-replace  --with-bonjour --without-bonjour
    }
}

set contribs	"adminpack dblink fuzzystrmatch lo pg_buffercache pg_trgm pgcrypto tsearch2 vacuumlo xml2"

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}/ && \
			${build.cmd} install ${destroot.destdir} && touch DONE"
	}
	system "cd ${destroot}${prefix}/bin && ln -sf ${libdir}/bin/psql psql82"
	file delete -force ${destroot}${prefix}/share/doc/${name} \
		${destroot}${prefix}/share/man
}

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

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

variant perl description {add Perl support} {
	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
}

post-install {
	ui_msg "\nTo use the postgresql server, install the postgresql82-server port"
}