# -*- 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
PortGroup           github 1.0

set dlang           D-Programming-Language
github.setup        ${dlang} phobos 2.059 v
categories          lang
platforms           darwin
license             Boost-1.0
maintainers         takeshi openmaintainer
description         Runtime library for the D programming language
long_description \
    Phobos is the standard runtime library that comes with the D language compiler.
homepage            http://dlang.org/
set dbranch         d862f1
distname            ${dlang}-${name}-v${version}-0-g${dbranch}
checksums           rmd160  9acbe4960c57ce6ba78d9594bb5451d6c7877da4 \
                    sha256  5571e610bd306540cc6e9574bde0479889c62c9d2d3eed742bd3a5362c1ac03c
depends_lib         port:druntime

worksrcdir          ${name}

post-patch {
    reinplace "s|gcc|${configure.cc}|" ${worksrcpath}/posix.mak
    reinplace "s|-m\$(MODEL)||" ${worksrcpath}/posix.mak
    reinplace "s|/import||" ${worksrcpath}/posix.mak
}

use_configure       no

if {${build_arch}=="x86_64"} {
    set model 64
} else {
    set model 32
}

build.args          -f posix.mak \
                    DRUNTIME_PATH=${prefix}/include/druntime \
                    DRUNTIME=${prefix}/lib/libdruntime.a \
                    CC=${configure.cc} \
                    CFLAGS=${configure.cflags} \
                    DMD=${prefix}/lib/dmd/bin/dmd \
                    MODEL=${model} \
                    BUILD=release
build.target-delete ${build.target}

destroot {
    xinstall -m 755 -d ${destroot}${prefix}/lib
    xinstall -m 644 ${worksrcpath}/generated/osx/release/${model}/lib${name}2.a \
        ${destroot}${prefix}/lib
    xinstall -d -m 755 ${destroot}${prefix}/include
    xinstall -d -m 755 ${destroot}${prefix}/include/${name}
    foreach f [glob ${worksrcpath}/*.d] {
        xinstall -m 644 ${f} ${destroot}${prefix}/include/${name}
    }
    xinstall -d -m 755 ${destroot}${prefix}/include/${name}/etc
    xinstall -d -m 755 ${destroot}${prefix}/include/${name}/etc/c
    foreach f [glob ${worksrcpath}/etc/c/*.d] {
        xinstall -m 644 ${f} ${destroot}${prefix}/include/${name}/etc/c
    }
    system "cd ${worksrcpath}; \
        cp -r std ${destroot}${prefix}/include/${name}
    "
}
