# -*- 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 92950 2012-05-11 18:28:50Z vince@macports.org $

PortSystem          1.0
PortGroup           archcheck 1.0

name                postgis2
categories          databases gis
license             GPL
revision            9656
epoch				0
version             2.0.1-svn
platforms           darwin
maintainers         vince openmaintainer

description         PostGIS is the spatial extension to the\
                    PostGreSQL database.

long_description    PostGIS 2 adds geometrical, geographical and topological\
                    types, and functions operating thereon, to the PostGreSQL\
                    database. The 2.0 release also provides raster handling\
                    and basic 3D geometry capacities (TIN and polyhedra).

homepage            http://postgis.refractions.net/

master_sites        http://www.postgis.org/download

fetch.type          svn
svn.revision        ${revision}
svn.url             http://svn.osgeo.org/postgis/trunk

depends_build       port:autoconf \
                    port:automake \
                    port:libtool

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

worksrcdir          trunk

# PostGIS 2.0 is not compatible with PostGIS 1.5

conflicts           postgis

# Neither is PostGIS 2.0 compatible with PostGreSQL 8

variant postgresql90        description {Builds with postgresql 9.0} \
                            conflicts postgresql91 {
    depends_lib-append      port:postgresql90
    archcheck.files-append  lib/postgresql90/libpq.dylib
    configure.args-append   --libdir=${prefix}/lib/postgresql90\
                            --with-pgconfig=${prefix}/lib/postgresql90/bin/pg_config
    build.args-append       PGSQL_DOCDIR=${destroot}${prefix}/share/doc/postgresql90\
                            PGSQL_MANDIR=${destroot}${prefix}/share/man
}

variant postgresql91        description {Builds with postgresql 9.1} \
                            conflicts postgresql90 {
    depends_lib-append      port:postgresql91
    archcheck.files-append  lib/postgresql91/libpq.dylib
    configure.args-append   --libdir=${prefix}/lib/postgresql91\
                            --with-pgconfig=${prefix}/lib/postgresql91/bin/pg_config
    build.args-append       PGSQL_DOCDIR=${destroot}${prefix}/share/doc/postgresql91\
                            PGSQL_MANDIR=${destroot}${prefix}/share/man
}

variant raster              description {Build raster support} {

    depends_lib-append      port:gdal
    configure.args-append   --with-raster
}

variant topology            description {Build topology support} {

    configure.args-append   --with-topology
}

variant gui                 description {Build the GUI import tool} {

    depends_lib-append      port:gtk2
    configure.args-append   --with-gui
}

variant comments            description {Build comments -- ! broken } {

    ui_warn "The comments variant is currently broken. Use at your own risk."
    
    depends_build-append    port:docbook-xsl \
                            port:libxslt \
                            port:ImageMagick
    
    configure.args-append   --datadir=${prefix}/share/${name} \
                            --with-projdir=${prefix} \
                            --with-xsldir=${prefix}/share/xsl/docbook-xsl

    build.target-append     comments
    destroot.target-append  docs-install comments-install
}

default_variants            +raster +topology

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

# Port phases

pre-configure {
    if {[variant_isset postgresql90]} {
        set PGVERSION   postgresql90
    } elseif {[variant_isset postgresql91]} {
        set PGVERSION   postgresql91
    }
    
    system -W ${worksrcpath} "./autogen.sh"
}

configure.cflags-append \
    -Diconv=libiconv -Diconv_open=libiconv_open -Diconv_close=libiconv_close \
    -I${prefix}/include

post-configure {
    if {[variant_isset universal]} {
        # We must add universal flags to compile liblwgeom properly
        file copy ${filespath}/ed_command ${worksrcpath}/ed_command
        reinplace -E "s#XXX#${configure.universal_cflags}#" \
                    ${worksrcpath}/ed_command
        system -W ${worksrcpath}/liblwgeom \
                "ed Makefile < ${worksrcpath}/ed_command"
    }
}

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


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