# -*- 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 102584 2013-02-05 04:25:13Z larryv@macports.org $

PortSystem          1.0
PortGroup           python 1.0

name                py-psycopg2
version             2.4.6
python.versions     25 26 27 31 32 33
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://www.initd.org/software/initd/psycopg/

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

checksums           rmd160  aed3763e0c5e0e8e3adc32331cc8767d6ab2002a \
                    sha256  4edcb40b0a039b4b559a6bc887b2155db8b6c53d0f55b00af8338c77b725621f

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

    patchfiles      patch-setup.cfg.diff

    post-patch {

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

        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
        }
    }

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


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

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

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

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

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

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