
# $Id: Portfile 117569 2014-03-04 00:16:55Z takeshi@macports.org $

PortSystem          1.0
PortGroup           github 1.0

github.setup        D-Programming-Language dmd 2.065
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  6ed3b7e960341fd8e1a9ba81d029eb715401e60c \
                    sha256  622785f91547f71331ab207ef811411dda9c36085c573d7225a9f8585146bc5d
post-patch {
    reinplace "s|gcc|${configure.cc}|" ${worksrcpath}/src/link.c
    reinplace "s|/etc|${prefix}/etc/${name}|" ${worksrcpath}/src/posix.mak
    reinplace "s|/etc|${prefix}/etc/${name}|" ${worksrcpath}/docs/man/man1/${name}.1
    reinplace "s|/etc|${prefix}/etc/${name}|" ${worksrcpath}/docs/man/man5/${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/man5/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 }
