# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4
# $Id: Portfile 64746 2010-03-15 13:15:37Z nox@macports.org $

PortSystem          1.0
PortGroup           archcheck 1.0

name                postgis
version             1.5.1
categories          databases
platforms           darwin
maintainers         stromnov openmaintainer

description         PostGIS adds support for geographic objects to the PostgreSQL database

long_description \
    PostGIS adds support for geographic objects to the PostgreSQL \
    object-relational database.  In effect, PostGIS \"spatially enables\" \
    the PostgreSQL server, allowing it to be used as a backend spatial \
    database for geographic information systems (GIS), much like ESRI's \
    SDE or Oracle's Spatial extension.  PostGIS follows the OpenGIS \
    Simple Features Specification for SQL and will be submitted for \
    conformance testing at version 1.0.

homepage            http://postgis.refractions.net/
master_sites        ${homepage}download/

checksums           md5     8353b38c38282b2192f01693f71b8d28 \
                    sha1    9b7f2b6ce2cb1d23c88c0393f55f13ea9b172ff7 \
                    rmd160  7c8b600e60c751b0ddc6c76f6cbb41d5997366d6

depends_build \
    port:docbook-xsl \
    port:libxslt \
    port:ImageMagick

depends_lib \
    port:geos \
    port:proj \
    port:libiconv \
    port:libxml2

archcheck.files \
    lib/libgeos_c.dylib \
    lib/libiconv.dylib \
    lib/libproj.dylib \
    lib/libxml2.dylib

use_parallel_build  no

configure.args \
    --datadir=${prefix}/share/${name} \
    --with-projdir=${prefix} \
    --with-xsldir=${prefix}/share/xsl/docbook-xsl

configure.cflags-append \
    -Diconv=libiconv -Diconv_open=libiconv_open -Diconv_close=libiconv_close

build.target-append comments
build.args          ICONV_LDFLAGS='-L${prefix}/lib -liconv'

destroot.target-append docs-install comments-install

set pgsql_suffixes {82 83 84}

set pgsql_ports {}
foreach s ${pgsql_suffixes} {
    lappend pgsql_ports postgresql${s}
}

foreach s ${pgsql_suffixes} {
    set p postgresql${s}
    set v [string index ${s} 0].[string index ${s} 1]
    set i [lsearch -exact ${pgsql_ports} ${p}]
    set c [lreplace ${pgsql_ports} ${i} ${i}]
    eval [subst {
        variant ${p} description "Build with PostgreSQL ${v}" conflicts ${c} {
            post-patch {
                set args {
                     PGSQL_DOCDIR=${destroot}${prefix}/share/doc/${p}
                     PGSQL_MANDIR=${destroot}${prefix}/share/man
                     PGSQL_SHAREDIR=${destroot}${prefix}/share/${p}
                }

                reinplace -E "/doc .*install\\\$/s|\\\$| \[join \${args}\]|" ${worksrcpath}/GNUmakefile
            }
            depends_lib-append  port:${p}

            archcheck.files-append \
                lib/${p}/libpq.dylib

            configure.args-append   --libdir=${prefix}/lib/${p} \
                                    --with-pgconfig=${prefix}/lib/${p}/bin/pg_config

            build.args-append   PGSQL_DOCDIR=${destroot}${prefix}/share/doc/${p} \
                                PGSQL_MANDIR=${destroot}${prefix}/share/man
        }
    }]
}

proc has_pgsql_variant {} {
    global pgsql_ports
    foreach p ${pgsql_ports} {
        if {[variant_isset ${p}]} {
            return 1
        }
    }
    return 0
}

if {![has_pgsql_variant]} {
    set p [lindex ${pgsql_ports} end]
    default_variants +${p}

    if {![has_pgsql_variant]} {
        error "One of the following variants must be set: [join ${pgsql_ports}]"
    }
}

livecheck.type      regex
livecheck.url       ${master_sites}
livecheck.regex     ${name}-(\\d+(?:\\.\\d+)*)\\.tar
