# -*- 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

PortSystem          1.0
PortGroup           github 1.0
PortGroup           muniversal 1.0

github.setup        dlang dmd 2.088.0 v
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
categories          lang
license             Boost-1
platforms           {darwin < 22}
maintainers         nomaintainer
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  70a61cd9aa8d8a4b33ab55f6fb54498b1948623c \
                    sha256  73a114c034077180799822aa809b404f760cf1233103b75f2e0b7d7e5e7b9032 \
                    size    3309925
post-patch {
    reinplace "s|/etc|${prefix}/etc/${name}|" ${worksrcpath}/docs/man/man5/${name}.conf.5
}

use_configure       no

patchfiles          patch-src-posix.mak.diff

depends_build-append          port:dmd-bootstrap
depends_skip_archcheck-append dmd-bootstrap

build.dir           ${worksrcpath}/src

post-extract {
    xinstall -m 0644 ${filespath}/makefile_macports_install ${build.dir}
}

# Use CFLAGS in the posix.make; some source needs special flags.
# Command-line arguments wipe the CFLAGS in posix.mak and
# extra flags cannot be added with +=.
# Another solution would be the use of override directive in posix.mak.
build.args          -f posix.mak all man \
                    HOST_CXX="${configure.cxx}" \
                    CC="${configure.cc}" \
                    LDFLAGS="${configure.ldflags} -framework CoreServices" \
                    ENVP="MACOSX_DEPLOYMENT_TARGET=${macosx_deployment_target}" \
                    SYSCONFDIR=${prefix}/etc/${name} \
                    HOST_DMD=${prefix}/libexec/dmd-bootstrap/bin/dmd

if {!${universal_possible} || ![variant_isset universal]} {
    if { ${configure.build_arch} in {arm64 ppc64 x86_64} } {
        build.args-append MODEL=64
        destroot.args-append MODEL=64
    } else {
        build.args-append MODEL=32
        destroot.args-append MODEL=32
    }
} else {
    lappend merger_build_args(arm64) MODEL=64
    lappend merger_build_args(x86_64) MODEL=64
    lappend merger_build_args(i386)   MODEL=32
    lappend merger_build_args(ppc64)  MODEL=64
    lappend merger_build_args(ppc)    MODEL=32
    lappend merger_destroot_args(arm64) MODEL=64
    lappend merger_destroot_args(x86_64) MODEL=64
    lappend merger_destroot_args(i386)   MODEL=32
    lappend merger_destroot_args(ppc64)  MODEL=64
    lappend merger_destroot_args(ppc)    MODEL=32
}

destroot.args-append \
    -f makefile_macports_install \
    PREFIX=${prefix}

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

github.livecheck.regex  {([^"-]+)}
