# -*- 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 92833 2012-05-08 23:46:29Z ryandesign@macports.org $

PortSystem          1.0

set realname        tools
name                dmd-${realname}
version             2.059
categories          lang
platforms           darwin
license             DMD
maintainers         takeshi openmaintainer
description         Ancilliary tools for the D programming language compiler
long_description \
    D is a language with C-like syntax and static typing. \
    It pragmatically combines efficiency, control, \
    and modeling power, with safety and programmer productivity.
homepage            http://dlang.org/
set dlang           D-Programming-Language
set site            d-programming-language.org
master_sites        https://github.com/${dlang}/${realname}/tarball/v${version}:src \
                    https://github.com/${dlang}/${site}/tarball/v${version}:doc
set dbranch-src     940730
set dbranch-doc     948c9b
distname            ${dlang}-${realname}-v${version}-0-g${dbranch-src}
set src             ${distname}${extract.suffix}
set doc             ${dlang}-${site}-v${version}-0-g${dbranch-doc}${extract.suffix}
distfiles           ${src}:src \
                    ${doc}:doc
checksums           ${src} \
                    rmd160  14b939b7e2eb02b874c7994af9c57cb29f20e951 \
                    sha256  d978c9fffd4cdd6731973e5a8d04683d6cfc8ad94cb66c3d5a9712f2dd0955ec \
                    ${doc} \
                    rmd160  9307a7b95442353843796fd0b4ba39305d3659bc \
                    sha256  a49cc52b5e2c0f0c0a641f054fec71cdecfca248c6bcfcfccadb0b331f9cae4e

depends_lib         port:phobos
worksrcdir          ${dlang}-${realname}-42d349f/

use_configure       no

set bin "catdoc ddemangle detab findtags rdmd tolf"
set dmd ${prefix}/lib/dmd/bin/dmd
set dflags "-O -d"
set ddocflags " -c -o- -Df"
set ddoc "macros.ddoc doc.ddoc"
build {
    system "mv ${workpath}/${dlang}-${site}-* ${workpath}/doc; 
        cd ${workpath}/doc;
        ${dmd} ${ddocflags}expression.html ${ddoc} expression.dd
        ${dmd} ${ddocflags}statement.html ${ddoc} statement.dd
        cd ${worksrcpath};
        for f in ${bin}; do
            ${dmd} ${dflags} \$f.d
        done
        ./findtags ../doc/expression.html > expression.tag
        ./findtags ../doc/statement.html > statement.tag
        ${dmd} ${dflags} -J. dman.d
    "
}

destroot {
    xinstall -d -m 755 ${destroot}${prefix}/lib/${name}
    xinstall -d -m 755 ${destroot}${prefix}/lib/${name}/bin
    foreach f "${bin} dman" {
        xinstall -m 755 ${worksrcpath}/${f} \
            ${destroot}${prefix}/lib/${name}/bin
    }
    ln -s ${prefix}/lib/${name}/bin/rdmd ${destroot}${prefix}/bin
}
