# -*- coding: utf-8; mode: tcl; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=2:ts=2:sts=2
# $Id: Portfile 60454 2009-11-12 23:35:31Z ryandesign@macports.org $

PortSystem						1.0

name									gdal-grass
categories						gis
version								1.4.3
maintainers						vince
description						This plugin allows GDAL to read GRASS files
long_description					This plugin allows GDAL to read GRASS files

homepage							http://grass.osgeo.org/

platforms							darwin

depends_lib						port:gdal \
											port:grass

master_sites					http://download.osgeo.org/gdal/

checksums							md5     2bfb7640e03b4d9d012f1a5d62c0351d \
											sha1    63b87ad1688cc365dc6bd6c3ccc854d0e6aa637a \
											rmd160  60e3866a44d595cbf41368adb1b968387c7852b4


use_configure					yes

configure.args-append	--with-gdal=${prefix}/bin/gdal-config
configure.args-append --with-grass=${prefix}


										
# Select Grass version

variant grass64 description "Builds against grass64" {
	depends_lib-delete		port:grass
	depends_lib-append		port:grass64
	
	configure.args-delete	--with-grass=${prefix}/lib
	
	if {[file exists ${applications_dir}/GRASS-6.4.app]} {
		configure.args-append	\
			--with-grass=${applications_dir}/GRASS-6.4.app/Contents/MacOS/
	} else {
		configure.args-append --with-grass=${prefix}
	}
}

post-configure {
	if {[variant_isset universal]} {
		# Enforce universal flags
		reinplace -E "s|^(CXXFLAGS.*)|\\1 ${configure.universal_cxxflags}|" \
			${worksrcpath}/Makefile
		reinplace -E "s|^(LD_SHARED.*)|\\1 ${configure.universal_cxxflags}|" \
			${worksrcpath}/Makefile
			
		# Fixes destroot issues
		reinplace -E "s|^(GRASSTABLES_DIR\[^/]*)(.*)|\\1${destroot}\\2|" \
			${worksrcpath}/Makefile
		reinplace -E "s|^(AUTOLOAD_DIR\[^/]*)(.*)|\\1${destroot}\\2|" \
			${worksrcpath}/Makefile
		reinplace "s|mkdir|mkdir -p|" ${worksrcpath}/Makefile
	}
}

build.target	
