# -*- 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										pgRouting
version									1.03
license									GPL
categories							gis
maintainers							vince
description							Routing algorithms for PostGIS
long_description				\
												pgRouting adds the following algorithms to PostGRES: \
												Dijkstra: shortest path, A*: boosted dijkstra, \
												Isochrones computation, TSP and shooting star, \
												an algorithm to compute shortest path on real \
												road networks.
platforms								darwin
homepage								http://pgrouting.postlbs.org/
master_sites						http://files.postlbs.org/pgrouting/source
distname								${name}-${version}

extract.suffix					.tgz

checksums								md5			ee700d18a984b8fd78c1a739ca078683 \
												sha1		012d4e8655774aa1a170ef404cc34f3606f9b245 \
												rmd160	1ff5eae093b69775ea98a04e1015268623e5b914

depends_lib							port:cmake
depends_lib-append			port:geos \
												port:gaul-devel \
												port:cgal \
												port:postgresql84
												
worksrcdir							pgrouting
												
configure.cmd						cmake .

# Locate postgres

set	PGLIB								${prefix}/lib/postgresql84
set	PGINC								${prefix}/include/postgresql84

variant postgresql83 {
	set	PGLIB							${prefix}/lib/postgresql83
	set	PGINC							${prefix}/include/postgresql83
}

variant postgresql82 {
	set	PGLIB							${prefix}/lib/postgresql82
	set	PGINC							${prefix}/include/postgresql82
}


patchfiles							patch-astar_c.diff patch-dijkstra_c.diff \
												patch-shooting_star_c.diff

# Configuration
# Start with no configure arguments: override defaults
configure.pre_args
configure.args
configure.universal_args
configure.cflags
configure.cxxflags

configure.env-append		PATH=$env(PATH):${PGLIB}/bin

configure.args-append		-DCMAKE_INSTALL_PREFIX=${prefix}
configure.args-append		-DPOSTGRESQL_INCLUDE_DIR=${PGINC}/server
configure.args-append		-DPOSTGRESQL_LIBRARIES=${PGLIB}
configure.args-append		-DCMAKE_C_COMPILER=${configure.cc}
configure.args-append		-DCMAKE_CXX_COMPILER=${configure.cxx}
configure.args-append		-DWITH_TSP=TRUE

variant universal {
	set archs 						"-DCMAKE_OSX_ARCHITECTURES=\""

	foreach arch ${configure.universal_archs} {
		append archs ${arch} ";"
	}
	configure.args-append "${archs}\""
	set sysroot						[lindex [exec ls /Developer/SDKs] end]
	configure.args-append "-DCMAKE_OSX_SYSROOT=/Developer/SDKs/${sysroot}"
}

post-configure {
	reinplace -E "s|-dynamiclib|-bundle|" \
		${worksrcpath}/core/src/CMakeFiles/routing.dir/link.txt
	reinplace -E "s|-dynamiclib|-bundle|" \
		${worksrcpath}/extra/tsp/src/CMakeFiles/routing_tsp.dir/link.txt

	reinplace -E \
		"s|-install_name \[^ ]+|-bundle_loader ${PGLIB}/bin/postgres|" \
		${worksrcpath}/core/src/CMakeFiles/routing.dir/link.txt
	reinplace -E \
		"s|-install_name \[^ ]+|-bundle_loader ${PGLIB}/bin/postgres|" \
		${worksrcpath}/extra/tsp/src/CMakeFiles/routing_tsp.dir/link.txt
		
	reinplace -E "s|librouting\.dylib|librouting\\.so|" \
		${worksrcpath}/core/src/CMakeFiles/routing.dir/link.txt
	reinplace -E "s|librouting_tsp\.dylib|librouting_tsp\\.so|" \
		${worksrcpath}/extra/tsp/src/CMakeFiles/routing_tsp.dir/link.txt
		
	reinplace -E "s|librouting\.dylib|librouting\\.so|" \
		${worksrcpath}/core/src/cmake_install.cmake
	reinplace -E "s|librouting_tsp\.dylib|librouting_tsp\\.so|" \
		${worksrcpath}/extra/tsp/src/cmake_install.cmake
		
	reinplace -E "s|/usr/share|${prefix}/share|" \
		${worksrcpath}/core/sql/cmake_install.cmake
	reinplace -E "s|/usr/share|${prefix}/share|" \
		${worksrcpath}/extra/tsp/sql/cmake_install.cmake
}
