# -*- 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                arm-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 arm ${version}
    depends_build
    depends_lib
    platforms           any
    supported_archs     noarch
    use_configure       no
    build               {}
    destroot            {}
}

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

subport arm-linux-androideabi-binutils {
    crossbinutils.setup arm-linux-androideabi ${version}
    depends_lib-append      port:$name
    configure.args-append \
        --target=armv7a-linux-androideabi \
        --disable-werror

    post-destroot {
        # See comment above about deleting docs
        delete      ${destroot}${prefix}/share/doc/arm-binutils
        file rename ${destroot}${prefix}/armv7a-linux-androideabi/bin \
                    ${destroot}${prefix}/arm-linux-androideabi
        file rename ${destroot}${prefix}/armv7a-linux-androideabi/lib \
                    ${destroot}${prefix}/arm-linux-androideabi
        file delete ${destroot}${prefix}/armv7a-linux-androideabi
    }
}

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

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

subport arm-freertos-binutils {
    crossbinutils.setup arm-freertos ${version}
    depends_lib-append      port:$name
    configure.args-append \
        --target=arm-stellaris-eabi \
        --disable-werror

    post-destroot {
        # See comment above about deleting docs
        delete      ${destroot}${prefix}/share/doc/arm-binutils
        file rename ${destroot}${prefix}/arm-stellaris-eabi/bin \
                    ${destroot}${prefix}/arm-freertos
        file rename ${destroot}${prefix}/arm-stellaris-eabi/lib \
                    ${destroot}${prefix}/arm-freertos
        file delete ${destroot}${prefix}/arm-stellaris-eabi
    }
}

subport arm-gba-binutils {
    crossbinutils.setup arm-gba ${version}
    depends_lib-append      port:$name
    configure.args-append \
        --target=arm-thumb-elf \
        --disable-werror

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

subport arm-linux-binutils {
    crossbinutils.setup arm-linux ${version}
    depends_lib-append      port:$name
    configure.args-append \
        --target=arm-linux-gnueabi \
        --disable-werror

    post-destroot {
        # See comment above about deleting docs
        delete      ${destroot}${prefix}/share/doc/arm-binutils
        file rename ${destroot}${prefix}/arm-linux-gnueabi/bin \
                    ${destroot}${prefix}/arm-linux
        file rename ${destroot}${prefix}/arm-linux-gnueabi/lib \
                    ${destroot}${prefix}/arm-linux
        file delete ${destroot}${prefix}/arm-linux-gnueabi
    }
}

subport arm-nds-binutils {
    crossbinutils.setup arm-nds ${version}
    depends_lib-append      port:$name
    configure.args-append \
        --target=arm-thumb-elf \
        --disable-werror

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

subport arm-netbsd-binutils {
    crossbinutils.setup arm-netbsd ${version}
    depends_lib-append      port:$name
    configure.args-append \
        --target=arm-netbsdelf-gnu \
        --disable-werror

    post-destroot {
        # See comment above about deleting docs
        delete      ${destroot}${prefix}/share/doc/arm-binutils
        file rename ${destroot}${prefix}/arm-netbsdelf-gnu/bin \
                    ${destroot}${prefix}/arm-netbsd
        file rename ${destroot}${prefix}/arm-netbsdelf-gnu/lib \
                    ${destroot}${prefix}/arm-netbsd
        file delete ${destroot}${prefix}/arm-netbsdelf-gnu
    }
}

subport arm-wince-binutils {
    crossbinutils.setup arm-wince ${version}
    depends_lib-append      port:$name
    configure.args-append \
        --target=arm-wince-pe \
        --disable-werror

    post-destroot {
        # See comment above about deleting docs
        delete      ${destroot}${prefix}/share/doc/arm-binutils
        file rename ${destroot}${prefix}/arm-wince-pe/bin \
                    ${destroot}${prefix}/arm-wince
        file rename ${destroot}${prefix}/arm-wince-pe/lib \
                    ${destroot}${prefix}/arm-wince
        file delete ${destroot}${prefix}/arm-wince-pe
    }
}
