# -*- 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 107874 2013-07-08 06:16:14Z jeremyhu@macports.org $

PortSystem          1.0
PortGroup           github 1.0

github.setup        D-Programming-Language dmd 2.063 v
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/
checksums           rmd160  89e5dd539c60a4cefad4313464ab1e9dff827f31 \
                    sha256  62658a6125116a0f463d6cd59b0031503866f8c7e79311df75a00238cb45b13b
post-patch {
    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 \
                    -Iroot \
                    -D__pascal= \
                    -DMARS=1 \
                    -DTARGET_OSX=1 \
                    -DDM_TARGET_CPU_X86=1
configure.cxxflags-append \
                    -fno-exceptions -x c++

build.dir           ${worksrcpath}/src

build.args          -f posix.mak \
                    HOST_CC=${configure.cxx} \
                    CC=\"${configure.cxx}\" \
                    CFLAGS=\"${configure.cppflags} ${configure.cxxflags}\" \
                    MFLAGS=\"${configure.cppflags} -Ibackend -Itk ${configure.cxxflags}\" \
                    LDFLAGS=\"${configure.ldflags} -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 -m 755 -W ${destroot.dir} \
        dmd idgen impcnvgen optabgen \
        ${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
}

notes {
    In order to have a complete dmd runtime environment consider installing the following ports:
    druntime phobos dmd-tools }

livecheck.type      regex
livecheck.url       ${homepage}download.html
livecheck.regex     {\.([0-9]+\.[0-9]+)\.zip}
