# -*- 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
# $Id: Portfile 89695 2012-02-07 02:01:16Z ryandesign@macports.org $

PortSystem      1.0

name            arm-none-eabi-gdb
version         7.3
categories      cross devel
platforms       darwin
license         GPL-3+
maintainers     nomaintainer
description     GDB: The GNU Project Debugger for arm-none-eabi

long_description \
GDB, the GNU Project Debugger, for arm-none-eabi cross development.

homepage        http://www.gnu.org/software/gdb/
master_sites    gnu
distname        gdb-${version}
dist_subdir     gdb
use_bzip2       yes

checksums       sha1    fefd90275d6decdca00c5c29c533e2ef3d439664 \
                rmd160  3df9a15e2d276f4f7f30e5d2a7d86a8c63f30a34

set crossgdb-target     arm-none-eabi

if {${configure.compiler} == "clang"} {
    configure.compiler llvm-gcc-4.2
}

if {${configure.build_arch} == "ppc" || ${configure.build_arch} == "ppc64"} {
    notes "${name} does not support building on ${configure.build_arch}."
    pre-fetch {
        ui_error "${name} does not support building on ${configure.build_arch}."
        return -code error "Unsupported architecture."
    }
}

depends_build   port:${crossgdb-target}-gcc \
                port:gettext

post-patch {
        namespace eval crossgdb {}

        # Fix the info pages and related stuff.
        #
        # path: path to the doc directory (e.g. gas/doc/)
        # makefile: path to Makefile.in (e.g. gas/doc/Makefile.in)
        # name: name of the info page (e.g. as)
        # suffix: suffix of the source page (texinfo or texi)
        proc crossgdb::fixinfo { path makefile name suffix } {
                global crossgdb-target workpath version

                # Fix the source
                reinplace "s|setfilename ${name}.info|setfilename ${crossgdb-target}-${name}.info|g" \
                        ${workpath}/gdb-${version}/${path}/${name}.${suffix}
                reinplace "s|(${name})|(${crossgdb-target}-${name})|g" \
                        ${workpath}/gdb-${version}/${path}/${name}.${suffix}
                reinplace "s|@file{${name}}|@file{${crossgdb-target}-${name}}|g" \
                        ${workpath}/gdb-${version}/${path}/${name}.${suffix}

                # Fix the Makefile
                reinplace -E "s:^${name}\\.(info|pod|${suffix}):${crossgdb-target}-${name}.\\1:g" \
                        ${workpath}/gdb-${version}/${makefile}
                reinplace -E "s:(\[ /'`\])${name}\\.(info|pod|${suffix}):\\1${crossgdb-target}-${name}.\\2:g" \
                        ${workpath}/gdb-${version}/${makefile}

                # Rename the source
                file rename ${workpath}/gdb-${version}/${path}/${name}.${suffix} \
                        ${workpath}/gdb-${version}/${path}/${crossgdb-target}-${name}.${suffix}

                reinplace "s|--info-dir=\$(DESTDIR)\$(infodir)|--dir-file=\$(DESTDIR)\$(infodir)/${crossgdb-target}-gdb-dir|g" \
                        ${workpath}/gdb-${version}/${makefile}
        }

        crossgdb::fixinfo bfd/doc/ bfd/doc/Makefile.in bfd texinfo
        crossgdb::fixinfo etc/ etc/Makefile.in configure texi
        crossgdb::fixinfo etc/ etc/Makefile.in standards texi
        crossgdb::fixinfo gdb/doc/ gdb/doc/Makefile.in annotate texinfo
        crossgdb::fixinfo gdb/doc/ gdb/doc/Makefile.in gdb texinfo
        crossgdb::fixinfo gdb/doc/ gdb/doc/Makefile.in gdbint texinfo
        crossgdb::fixinfo gdb/doc/ gdb/doc/Makefile.in stabs texinfo
}

configure.args  --target=${crossgdb-target} \
                --infodir=${prefix}/share/info \
                --mandir=${prefix}/share/man \
                --with-docdir=${prefix}/share/doc \
                --with-gdb-datadir=${prefix}/share/${name} \
                --disable-nls \
                --enable-multilib

# specific to ARM
configure.args-append \
                --enable-interwork

post-destroot {
        # (host) libiberty
        file delete "${destroot}${prefix}/lib/${build_arch}/libiberty.a"

        # avoid conflicts with arm-none-eabi-binutils port
        file delete ${destroot}${prefix}/share/info/arm-none-eabi-bfd.info
}

livecheck.type  regex
livecheck.url   http://ftp.gnu.org/gnu/gdb/
livecheck.regex gdb-(\\d+(?:\\.\\d+)+)\\.tar
