# -*- 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
PortGroup           active_variants 1.1

github.setup        dlang phobos 2.088.0 v
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
categories          lang
license             Boost-1
maintainers         nomaintainer
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/

checksums           rmd160  2e346ef95a2264bbedd716e56741fbee93d42d76 \
                    sha256  66fd680871bf63cc7abbf271ee9952a2fd7e3c684bb0828f433e0131d6ca36aa \
                    size    2368456

depends_lib         port:druntime

patchfiles          patch-gzlib.c.diff \
                    patch-posix.mak.diff

use_configure       no

pre-configure {
    # dmd compiler can not handle universal files, so create thin versions of archive files from libdruntime.a
    set all_archs [get_canonical_archs]
    foreach arch ${all_archs} {
        file mkdir ${workpath}/druntime/${arch}
    }
    if {[active_variants port:druntime universal ""]} {
        # libdruntime.a is universal, so create a thin version
        foreach arch ${all_archs} {
            system \
                -W ${workpath}/druntime/${arch} \
                "/usr/bin/lipo -thin ${arch} ${prefix}/lib/libdruntime.a -output libdruntime.a"
        }
    } else {
        # libdruntime.a is NOT universal, so just copy it
        foreach arch ${all_archs} {
            file copy ${prefix}/lib/libdruntime.a ${workpath}/druntime/${arch}/libdruntime.a
        }
    }
}

build.args          -f posix.mak \
                    DMD_DIR=${prefix}/share/dmd \
                    DRUNTIME_PATH=${prefix}/include/druntime \
                    CC=${configure.cc} \
                    MACPORTS_CFLAGS=\"${configure.cflags}\" \
                    DMD=${prefix}/bin/dmd
build.target        ""

if {!(${universal_possible} && [variant_isset universal])} {
    if { ${build_arch} eq "x86_64" || ${build_arch} eq "ppc64" } {
        build.args-append MODEL=64 DRUNTIME=${workpath}/druntime/${build_arch}/libdruntime.a
    } else {
        build.args-append MODEL=32 DRUNTIME=${workpath}/druntime/${build_arch}/libdruntime.a
    }
} else {
    lappend merger_build_args(x86_64) MODEL=64 DRUNTIME=${workpath}/druntime/x86_64/libdruntime.a
    lappend merger_build_args(i386)   MODEL=32 DRUNTIME=${workpath}/druntime/i386/libdruntime.a
    lappend merger_build_args(ppc64)  MODEL=64 DRUNTIME=${workpath}/druntime/ppc64/libdruntime.a
    lappend merger_build_args(ppc)    MODEL=32 DRUNTIME=${workpath}/druntime/ppc/libdruntime.a
}

destroot {
	xinstall -m 644 {*}[glob ${worksrcpath}/generated/osx/release/*/*.a] ${destroot}${prefix}/lib
	xinstall -d -m 755 ${destroot}${prefix}/include/${name}
	xinstall -m 644 {*}[glob ${worksrcpath}/*.d] ${destroot}${prefix}/include/${name}
    foreach d {etc std} {
	    file copy ${worksrcpath}/${d} ${destroot}${prefix}/include/${name}
    }
}

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