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

name                x86_64-binutils
version             2.42
revision            0
maintainers         {@kamischi web.de:karl-michael.schindler} \
                    openmaintainer

if {$subport eq $name} {
    # Download sources and install docs for all subports
    crossbinutils.setup x86_64 ${version}
    depends_build
    depends_lib
    platforms           any
    supported_archs     noarch
    use_configure       no
    build               {}
    destroot            {}
}

foreach ostarget {linux dragonfly freebsd netbsd openbsd} {
    subport x86_64-${ostarget}-binutils {
        crossbinutils.setup     x86_64-${ostarget} ${version}
        # Depend on base package for installing the docs
        depends_lib             port:$name
        configure.args-append   --disable-werror
        if {${ostarget} eq "linux"} {
            depends_build-append    port:bison
        }
        # Delete docs since already installed by the base package
        # Resolves clash about identical docs from each subport
        post-destroot {
            delete ${destroot}${prefix}/share/doc/x86_64-binutils
        }
    }
}

subport x86_64-embedded-binutils {
    crossbinutils.setup x86_64-embedded ${version}
    configure.args-append \
        --target=x86_64-unknown-elf \
        --disable-werror

    post-destroot {
        # See comment above about deleting docs
        delete      ${destroot}${prefix}/share/doc/x86_64-binutils
        file rename ${destroot}${prefix}/x86_64-unknown-elf/bin \
                    ${destroot}${prefix}/x86_64-embedded
        file rename ${destroot}${prefix}/x86_64-unknown-elf/lib \
                    ${destroot}${prefix}/x86_64-embedded
        file delete ${destroot}${prefix}/x86_64-unknown-elf
    }
}
