PortSystem              1.0

name                    arm-elf-gdb
version                 7.1
revision                1
categories              cross devel
maintainers             nomaintainer
license                 GPL-3+
description             GDB for the ARM processors
long_description        arm-elf-gdb is a version of the GNU Debugger \
                        for the arm-elf toolchain.
homepage                https://www.gnu.org/software/gdb/gdb.html
platforms               darwin
master_sites            gnu:gdb
distname                gdb-${version}
dist_subdir             gdb
use_bzip2               yes
checksums               md5 21dce610476c054687b52770d2ddc657 \
                        sha1 417e2e637a296ea0e1cdddf56233311b8708fa19 \
                        rmd160 800d224496240a360c996e588490f2d87367c4e3

set crossgdb-target arm-elf

patchfiles              patch-armsupp.c.diff

# Build in a different directory, as advised in the README file.
pre-configure   {
        file mkdir "${workpath}/build"
}
configure.dir           ${workpath}/build
configure.cmd           ${workpath}/gdb-${version}/configure

configure.args          --mandir=${prefix}/share/man \
                        --infodir=${prefix}/share/info \
                        --target=${crossgdb-target} \
                        --enable-interwork \
                        --enable-multilib \
                        --disable-werror

build.dir               ${workpath}/build

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 souce page (texinfo or texi)
                proc crossgdb::fixinfo { path makefile name suffix } {
                        global crossgdb-target worksrcpath

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

                        # Fix the Makefile
                        reinplace "s| ${name}.info| ${crossgdb-target}-${name}.info|g" \
                                ${worksrcpath}/${makefile}
                        reinplace "s|/${name}.info|/${crossgdb-target}-${name}.info|g" \
                                ${worksrcpath}/${makefile}
                        reinplace "s|^${name}.info|${crossgdb-target}-${name}.info|g" \
                                ${worksrcpath}/${makefile}
                        reinplace "s| ${name}.pod| ${crossgdb-target}-${name}.pod|g" \
                                ${worksrcpath}/${makefile}
                        reinplace "s|/${name}.pod|/${crossgdb-target}-${name}.pod|g" \
                                ${worksrcpath}/${makefile}
                        reinplace "s|^${name}.pod|${crossgdb-target}-${name}.pod|g" \
                                ${worksrcpath}/${makefile}
                        reinplace "s| ${name}.${suffix}| ${crossgdb-target}-${name}.${suffix}|g" \
                                ${worksrcpath}/${makefile}
                        reinplace "s|/${name}.${suffix}|/${crossgdb-target}-${name}.${suffix}|g" \
                                ${worksrcpath}/${makefile}
                        reinplace "s|^${name}.${suffix}|${crossgdb-target}-${name}.${suffix}|g" \
                                ${worksrcpath}/${makefile}

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

                        # Fix install-info's dir.
                        # (note: this may be effectless if there was no info dir to be fixed)
                        reinplace "s|--info-dir=\$(DESTDIR)\$(infodir)|--dir-file=\$(DESTDIR)\$(infodir)/${crossgdb-target}-gdb-dir|g" \
                                "${worksrcpath}/${makefile}"
                }
        # etc/standards.info
        crossgdb::fixinfo etc/ etc/Makefile.in standards info

}

post-destroot {
        # Don't overwrite libiberty installed by gcc.
        file delete "${destroot}${prefix}/lib/${build_arch}/libiberty.a"
}
