# $Id: Portfile,v 1.9 2006/03/16 20:14:51 toby Exp $

PortSystem 1.0
name             smlnj
version          110.58
categories       lang
maintainers      toby@opendarwin.org
description      Standard ML of New Jersey
long_description \
	Standard ML of New Jersey (abbreviated SML/NJ) is a \
	compiler for the Standard ML '97 programming language \
	with associated libraries, tools, and documentation. \
	SML/NJ is free, open source software.
homepage         http://www.smlnj.org/
platforms        darwin

master_sites     http://smlnj.cs.uchicago.edu/dist/working/${version}/
dist_subdir      ${name}/${version}

distfiles
checksums

# Files needed for basic distribution.
set srcs [list \
	MLRISC.tgz 48a0d1fd15891da59051aa114526336186d55beb \
	ckit.tgz cbb6cf78e9fe621d392cd99172abb0c3befe71e1 \
	cm.tgz 35a7d31b337101f666eb0f2d854dc6d3f64c127d \
	cml.tgz 8ca00e873127269453d5a475eea101546bcedec7 \
	compiler.tgz febcccee715009e8fa194cd092da071c7c55c5a1 \
	config.tgz 19a7be9d27eb9c49e1ade858a2e8407211d60c80 \
	eXene.tgz 6f5f22be6f0aee30dd6892556282dd5f62a505f5 \
	ml-burg.tgz 68354c40b9a64ed7df5b88a4a8eebfa3e7b1631b \
	lexgen.tgz e335e9e65388218bf8e3e68fae2790058d20159a \
	ml-lex.tgz 72c6dbfba99569613dd14f76b6c8a970b0174b73 \
	ml-yacc.tgz 26411e92e7d0e2da5d01ab14e69103a0575728cd \
	ml-nlffi-lib.tgz 020575b9726c90ac868dd4f045d950081a6940e4 \
	ml-nlffigen.tgz 8be690023cddc00c903fb60f0990e79355fc77ba \
	runtime.tgz ceb87f0c9b042752a6ca34e4d5f257caa709c0b8 \
	smlnj-c.tgz c0d6e5b1ade6a6bab7a2e2dea93111330bec3ebd \
	smlnj-lib.tgz cfd22e819eb7f18ae2eb0ce3ef1d08e8588c85b6 \
	system.tgz a8e6a22bf015d9d20fb99e49aee9de99a9918dfd \
	tools.tgz 1d893119072649a6ffce6583998f99e7aa27dac1 \
	heap2asm.tgz 73439414d1121d3c2f1ce7bf73d4214ab79b1b9e \
]

foreach {tarball checksum} $srcs {
	distfiles-append $tarball
	checksums-append $tarball sha1 $checksum
}

# Platform-specific boot code (omitted: sparc-unix, x86-win32)
platform powerpc {
	distfiles-append boot.ppc-unix.tgz
	checksums-append boot.ppc-unix.tgz sha1 327e3b6b7a323e9ab9f01b5242d9a1169875a9f2
}
platform i386 {
	distfiles-append boot.x86-unix.tgz
	checksums-append boot.x86-unix.tgz sha1 c788e868c06c040c143941b292ac4f35ff5719d2
}

### extract ###
pre-extract {
	file mkdir ${worksrcpath}
}
extract.dir          ${worksrcpath}
extract.only         config.tgz

### configure ###
configure {
	reinplace "s|SRCARCHIVEURL=.*|SRCARCHIVEURL=file://${distpath}|" \
		${worksrcpath}/config/srcarchiveurl

	reinplace "s|#request|request|" ${worksrcpath}/config/targets
}

### build ###
build.env            URLGETTER=curl
build.cmd            ${worksrcpath}/config/install.sh
build.target

### destroot ###
destroot {
	set smlnj_home ${prefix}/share/smlnj

	file mkdir ${destroot}${smlnj_home}
	file copy ${worksrcpath}/bin ${destroot}${smlnj_home}
	file copy ${worksrcpath}/lib ${destroot}${smlnj_home}

	xinstall -m 555 ${filespath}/sml.sh ${destroot}${prefix}/bin/sml
	reinplace "s|__SMLNJ_HOME__|${smlnj_home}|g" \
		${destroot}${prefix}/bin/sml

	foreach prog [glob -directory ${worksrcpath}/bin *] {
		set progname [file tail $prog]
		if {![string equal $progname sml]} {
			system "ln -s sml ${destroot}${prefix}/bin/${progname}"
		}
	}
}
