# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
# $Id: Portfile 84550 2011-09-27 21:05:11Z snc@macports.org $

PortSystem 1.0

name             smlnj
version          110.72
categories       lang ml
maintainers      bfulgham
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}_${revision}

distfiles
checksums

# Files needed for basic distribution.
set srcs [list \
    config.tgz a7e205a9e0753908ee3174daa5164c320c7a411f \
    cm.tgz 0a85eaecc101c45c769e6beb8ace8a8bf0f4d32f \
    compiler.tgz cf80dfb2150de0705fbc2b2a01fc8eefda0e9c85 \
    runtime.tgz d9e3df41155ad9e969dd13c06f0f0fd3df177578 \
    system.tgz 72f73bbbc06d23ee3c4510bb5af2fb8dec431337 \
    MLRISC.tgz 9bb9eb169337533304c2e0e4eb9af263d38c398a \
    smlnj-lib.tgz 8ce9761a118569b8563f0336e010906c15943324 \
    ckit.tgz 0ebcdbd0a494eb051b4e6081f5e9312a0a54f03d \
    nlffi.tgz 63d043de413748fe124eb6e9f066935b4f1e96e0 \
    cml.tgz 9fd01c6d2d4a7cac22be75010891c1be5ab81f29 \
    eXene.tgz c8b502580a719b38528f100f21f11ac1f4c2b573 \
    ml-lex.tgz 3fb5dca13de3c51ddab1c8fb95b1dfaad58fb27c \
    ml-yacc.tgz f7b0f53c7f676e7bb2605211d4981948c538a551 \
    ml-burg.tgz 17afacafa25d1fc33d3cbe464be66f1a7f8714fa \
    ml-lpt.tgz 948735346b411ec5004f3294454c12bfb4176083 \
    pgraph.tgz 00919f8341fdcbe38ff7c908ef78fbbc4c37a5b6 \
    trace-debug-profile.tgz e80d8076d961a36e067b559c02279562856bb6ee \
    heap2asm.tgz 46845fc4bed21f1c3b46540fc088936d0502e12b \
    smlnj-c.tgz f4bf82d695be0fca01e0f3e4075ac4d81fe3c660 \
]

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 815447275d6321f85b6c97e84aa223f6d710b516
}
platform i386 {
	distfiles-append boot.x86-unix.tgz
	checksums-append boot.x86-unix.tgz sha1 799f02f3e880a829b48962994b563f7321385d87
}

post-patch {
	reinplace "s|__MACPORTS_CC__|${configure.cc}|" ${worksrcpath}/config/install.sh
}

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

### patch ###
patchfiles          patch-install.sh.diff \
                    patch-config-_arch-n-opsys.diff

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

	reinplace "s|#request|request|" ${worksrcpath}/config/targets
	reinplace "s|request ml-antlr|#request ml-antlr|" ${worksrcpath}/config/targets
	reinplace "s|request ml-lex-|#request ml-lex-|" ${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}"
		}
	}
}
