# -*- 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} dmd 2.059 v
revision            2
categories          lang
platforms           darwin
supported_archs     i386 x86_64
license             {GPL-1 Artistic DMD}
maintainers         takeshi openmaintainer
description         dmd Digital Mars D 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 dbranch         3987c7
distname            ${dlang}-${name}-v${version}-0-g${dbranch}
checksums           rmd160  04e7f0cfa07e94e9ca567d5276d3c633d614f08c \
                    sha256  ea6aa0f5f5428a9e36b18569a6948a85cfec8295b2a1947637f8449835a82eff

worksrcdir          ${name}

post-patch {
    reinplace "s|gcc|${configure.cc}|" ${worksrcpath}/src/posix.mak
    reinplace "s|gcc|${configure.cc}|" ${worksrcpath}/src/link.c
    reinplace "s|-m\$(MODEL)||" ${worksrcpath}/src/posix.mak
    reinplace "s|/etc|${prefix}/etc/${name}|" ${worksrcpath}/src/inifile.c
    reinplace "s|/etc|${prefix}/etc/${name}|" ${worksrcpath}/docs/man/man1/${name}.1
    reinplace "s|/etc|${prefix}/etc/${name}|" ${worksrcpath}/docs/man/man1/${name}.conf.5
}

use_configure       no

configure.cppflags-append \
                    -Wno-deprecated -Wstrict-aliasing
configure.cxxflags-append \
                    -Iroot -fno-exceptions -x c++\
                    -D__pascal= -DMARS=1 -DTARGET_OSX=1

build.dir           ${worksrcpath}/src

build.args          -f posix.mak \
                    HOST_CC=${configure.cxx} \
                    CC=\"${configure.cxx}\" \
                    CFLAGS=\"${configure.cxxflags}\" \
                    MFLAGS=\"${configure.cxxflags} -Ibackend -Itk\" \
                    LDFLAGS=\"${configure.ldflags} -lstdc++ -framework CoreServices\" \
                    ENVP=\"MACOSX_DEPLOYMENT_TARGET=${macosx_deployment_target}\"

destroot {
# man
    xinstall -m 644 -W ${worksrcpath}/docs/man/man1 \
        dmd.1 dumpobj.1 obj2asm.1 rdmd.1 \
        ${destroot}${prefix}/share/man/man1
    xinstall -m 644 ${worksrcpath}/docs/man/man1/dmd.conf.5 \
        ${destroot}${prefix}/share/man/man5
# bin
    xinstall -d -m 755 ${destroot}${prefix}/lib/${name}/bin
    xinstall -m 755 -W ${destroot.dir} \
        dmd idgen impcnvgen optabgen \
        ${destroot}${prefix}/lib/${name}/bin
    ln -s ${prefix}/lib/${name}/bin/dmd ${destroot}${prefix}/bin
# samples
    xinstall -d -m 755 ${destroot}${prefix}/share/${name}/samples
    eval xinstall -m 644 [glob ${worksrcpath}/samples/*.d] ${destroot}${prefix}/share/${name}/samples
# conf
    xinstall -d -m 755 ${destroot}${prefix}/etc/${name}
    set conf [open ${destroot}${prefix}/etc/${name}/${name}.conf w]
    puts $conf "\[Environment\]
DFLAGS=-I${prefix}/include/druntime -I${prefix}/include/phobos -L-L${prefix}/lib"
    close $conf
}
