# $Id: Portfile,v 1.2 2006/02/17 23:56:23 gwright Exp $

PortSystem 1.0
name		mercury-extras
version		0.12.2
categories	lang
maintainers	gwright@opendarwin.org
platforms	darwin
description	Extra packages for the Mercury Programming Language
long_description	\
		Mercury is a new logic/functional programming	\
		language, which combines the clarity and	\
		expressiveness of declarative programming with	\
		advanced static analysis and error detection	\
		features. Its highly optimized execution	\
		algorithm delivers efficiency far in excess of	\
		existing logic programming systems, and close	\
		to conventional programming systems. Mercury	\
		addresses the problems of large-scale program	\
		development, allowing modularity, separate	\
		compilation, and numerous optimization/time	\
		trade-offs.

homepage	http://www.cs.mu.oz.au/research/mercury/
master_sites	http://www.cs.mu.oz.au/mercury/download/files/

distfiles	${name}-${version}${extract.suffix}

checksums	${name}-${version}${extract.suffix} md5  31101288778657de8bf063abe970bb70

depends_run	port:mercury

patchfiles	patch-references-Mmakefile	\
		patch-lex-Mmakefile

use_configure	no

build		{ cd ${worksrcpath}
		  system "mmake depend && mmake INSTALL_PREFIX=${destroot}${prefix}"
		}

destroot	{ cd ${worksrcpath}
		  system "mmake INSTALL_PREFIX=${destroot}${prefix} install"
		}

#
# Remove the redundant symbolic links (already installed by the
# mercury port). Put back the one non-redundant link too.
#
post-destroot	{
		  system "find ${destroot}${prefix}/lib/mercury -type l | xargs rm -f"
		  file mkdir ${destroot}${prefix}/lib/mercury/ints/Mercury
		  system "cd ${destroot}${prefix}/lib/mercury/ints/Mercury && \
			  ln -s .. ints0"

		  set bad_dylibs [ exec find ${destroot}${prefix}/lib -name "\*.dylib" | xargs otool -D | grep ${destroot} ]
		  foreach bad_dylib ${bad_dylibs} {
			regsub ":$" ${bad_dylib} "" bad_dylib_path
			regsub ${destroot} ${bad_dylib_path} "" good_dylib_path
			system "install_name_tool -id ${good_dylib_path} ${bad_dylib_path}"
		  }
		}

