# -*- 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 116974 2014-02-11 17:58:09Z snc@macports.org $

PortSystem          1.0
PortGroup           python 1.0

name                py-psycopg2
version             2.5.2
python.versions     25 26 27 33 34
python.default_version  27
categories-append   databases
maintainers         snc openmaintainer
license             LGPL-3+
platforms           darwin freebsd

description         A python DBAPI-2.0-compliant database adapter for postgresql

long_description    Psycopg2 is a postgresql database adapter for python. \
                    It's fully compliant to python's DBAPI-2.0. psycopg is \
                    designed for heavily multi-threaded applications \
                    featuring connection pooling.

homepage            http://initd.org/psycopg/

set branch          [join [lrange [split ${version} .] 0 1] -]
master_sites        http://www.psycopg.org/psycopg/tarballs/PSYCOPG-${branch}/
distname            psycopg2-${version}

checksums           md5     53d81793fbab8fee6e732a0425d50047 \
                    rmd160  f804790b37d0e57d4d3a48ca7674f26aab550ca3 \
                    sha256  50382d8703a16c3c615f328c2676f002787095925c99f0afb125a59962a5bd2e

if {${name} ne ${subport}} {
    depends_lib-append  port:openssl

    patchfiles      patch-setup.cfg.diff

    post-patch {

        if {[variant_isset postgresql84]} {
            reinplace \
                s|@PG_CONFIG@|${prefix}/lib/postgresql84/bin/pg_config|g \
                ${worksrcpath}/setup.cfg
        }

        if {[variant_isset postgresql90]} {
            reinplace \
                s|@PG_CONFIG@|${prefix}/lib/postgresql90/bin/pg_config|g \
                ${worksrcpath}/setup.cfg
        }

        if {[variant_isset postgresql91]} {
            reinplace \
                s|@PG_CONFIG@|${prefix}/lib/postgresql91/bin/pg_config|g \
                ${worksrcpath}/setup.cfg
        }

        if {[variant_isset postgresql92]} {
            reinplace \
                s|@PG_CONFIG@|${prefix}/lib/postgresql92/bin/pg_config|g \
                ${worksrcpath}/setup.cfg
        }

        if {[variant_isset postgresql93]} {
            reinplace \
                s|@PG_CONFIG@|${prefix}/lib/postgresql93/bin/pg_config|g \
                ${worksrcpath}/setup.cfg
        }
    }

    variant postgresql84 conflicts postgresql90 postgresql91 postgresql92 postgresql93 description "Build using postgresql v8.4" {
        depends_lib-append  port:postgresql84
    }

    variant postgresql90 conflicts postgresql84 postgresql91 postgresql92 postgresql93 description "Build using postgresql v9.0" {
        depends_lib-append  port:postgresql90
    }

    variant postgresql91 conflicts postgresql84 postgresql90 postgresql92 postgresql93 description "Build using postgresql v9.1" {
        depends_lib-append  port:postgresql91
    }

    variant postgresql92 conflicts postgresql84 postgresql90 postgresql91 postgresql93 description "Build using postgresql v9.2" {
        depends_lib-append  port:postgresql92
    }

    variant postgresql93 conflicts postgresql84 postgresql90 postgresql91 postgresql92 description "Build using postgresql v9.3" {
        depends_lib-append  port:postgresql93
    }

    if {![variant_isset postgresql84] && ![variant_isset postgresql90] && ![variant_isset postgresql91] && ![variant_isset postgresql92] && ![variant_isset postgresql93]} {
        default_variants    +postgresql93
    }

    livecheck.type      none
} else {
    livecheck.url       ${master_sites}
    livecheck.regex     psycopg2-(\\d+(\\.\\d+)+)${extract.suffix}
}
