# $Id: Portfile 40562 2008-10-06 21:17:27Z jmr@macports.org $

PortSystem 1.0
name		mercury-extras
version		0.13.1
categories	lang
maintainers	nomaintainer
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  465ef230ae2d7a58dd184adc4c6464ec

depends_run	port:mercury

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

use_configure	no

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

destroot	{
		  system "cd ${worksrcpath} && 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}"
		  }
		}

