# -*- 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                m68k-binutils
version             2.46.0
revision            0
maintainers         {@kamischi web.de:karl-michael.schindler} \
                    openmaintainer

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

# tried, but not working targets: amigaos atari openbsd
# freepascal probably needs palm binutils from here:
# https://github.com/chainq/prc-tools-remix
foreach ostarget {linux freebsd netbsd} {
    subport m68k-${ostarget}-binutils {
        crossbinutils.setup     m68k-${ostarget} ${version}
        # Depend on base package for installing the docs
        depends_lib-append      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/m68k-binutils
        }
    }
}

subport m68k-embedded-binutils {
    crossbinutils.setup     m68k-embedded ${version}
    depends_lib-append      port:$name
    configure.args-append \
        --target=m68k-unknown-elf \
        --disable-werror

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