# $Id: Portfile 71533 2010-09-15 20:26:12Z ryandesign@macports.org $

PortSystem 1.0

name			spatialite-devel
version			2.1
categories		databases gis
platforms		darwin
maintainers		landonf openmaintainer
description		Spatial extensions for SQLite 3
long_description	SpatiaLite is a library for geographic information \
			systems (GIS) that implements the core OpenGIS \
			specification. It provides SQLite with basic support \
			for spatial data is intended for lightweight GIS \
			projects.

homepage		http://www.gaia-gis.it/spatialite-2.1/
master_sites		${homepage}

distfiles		spatialite-${version}.tar.gz \
			init_spatialite.sql.gz

extract.only		spatialite-${version}.tar.gz

worksrcdir		spatialite-${version}

checksums		spatialite-${version}.tar.gz \
				md5	145b4159603f2e514bb552cf02b4e8f7 \
				sha1	4177896a35ca27d3dc7a136008db7d1c543e5eb7 \
				rmd160	d1557fa30f13f5dad9c0f91e46d41cd49677f421 \
			init_spatialite.sql.gz \
				md5	b6695124dc7ae5ac08537c7f6b9ca049 \
				sha1	369ef30524ed5930ffd292906b53e4f6298ff733 \
				rmd160	8afc72a0d8fd5a7cc3b4d4b4990256e63618eefd

depends_lib		port:sqlite3 \
			port:geos \
			port:proj

configure.ldflags-append	-liconv -lintl -lcharset
configure.args		--enable-geos --enable-proj

post-patch {
	reinplace s|/usr/local|${prefix}|g \
		${worksrcpath}/src/Makefile.in \
		${worksrcpath}/src/shell/Makefile.in
}

post-destroot {
	# Set up the init SQL
	set sharedir ${destroot}${prefix}/share/spatialite
	file mkdir ${sharedir}
	system "gzip -cd ${distpath}/init_spatialite.sql.gz > ${sharedir}/init_spatialite.sql"

	# Create a template database
	system "${destroot}${prefix}/bin/spatialite ${sharedir}/spatialite.db < ${sharedir}/init_spatialite.sql"
}
