# -*- 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       muniversal 1.0
PortGroup       github 1.0

github.setup    apple-oss-distributions gdb 2831 gdb-
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
name            gdb-apple
revision        1
categories      devel
license         GPL-2+
maintainers     {jeremyhu @jeremyhu} openmaintainer
description     GDB: The GNU Project Debugger with Apple Modifications (based on 6.3.50)

long_description \
GDB, the GNU Project debugger, allows you to see what is going on 'inside' \
another program while it executes -- or what another program was doing at the \
moment it crashed.  GDB can do four main kinds of things (plus other things \
in support of these) to help you catch bugs in the act: \
    a) start your program, specifying anything that might affect its behavior, \
    b) make your program stop on specified conditions, \
    c) examine what has happened, when your program has stopped, \
    d) change things in your program, so you can experiment with correcting \
       the effects of one bug and go on to learn about another. \
The program being debugged can be written in Ada, C, C++, Objective-C, \
Pascal (and many other languages). Those programs might be executing on \
the same machine as GDB (native) or on another machine (remote). GDB \
can run on most popular UNIX and Microsoft Windows variants.

supported_archs x86_64 i386 ppc

# xm.h can be created out of order
use_parallel_build no

checksums       rmd160  086f823e5eb3cdfed0d72c48679913e5bc73a832 \
                sha256  38006f9bf50df23dd1b76231b362d5e7af800c44c0f9216a7ceb5eb121c5f432 \
                size    17960818

depends_build   port:gettext port:zlib port:flex

depends_lib     port:libiconv port:ncurses port:sqlite3

patchfiles      patch-gdb-headers.diff \
                patch-macosx-nat.c.diff \
                patch-macosx-tdep.c.diff

if {${os.platform} eq "darwin" && ${os.major} < 10} {
    patchfiles-append \
                patch-gdb-backtrace.diff \
                patch-macosx-nat-threads.c.diff

    if {${os.major} == 8} {
        depends_build-append port:libmacho-headers
        patchfiles-append \
                patch-macosx-nat-info.c.diff \
                patch-include-libiberty.h.diff

        post-patch {
            # https://trac.macports.org/ticket/67370
            reinplace "s/.__dr/.dr/" \
                ${worksrcpath}/gdb/macosx/i386-macosx-nat-exec.c
        }
    }
}

worksrcdir	${worksrcdir}/src

post-patch {
    # https://trac.macports.org/ticket/37790
    reinplace "s/-mmacosx-version-min=10.7//" \
        ${worksrcpath}/gdb/config/i386/macosx.mh \
        ${worksrcpath}/libiberty/config/mh-macosx \
        ${worksrcpath}/bfd/configure.host

    # https://trac.macports.org/ticket/63153
    reinplace "s|\$(SDKROOT)/usr/bin/mig|/usr/bin/mig|" \
        ${worksrcpath}/gdb/config/i386/macosx.mh \
        ${worksrcpath}/gdb/config/powerpc/macosx.mh
}

configure.args \
    --infodir=${prefix}/share/info \
    --mandir=${prefix}/share/man \
    --with-docdir=${prefix}/share/doc \
    --program-suffix=-apple \
    --disable-werror

platform darwin 10 powerpc {
    # Need to force the buildsystem use correct settings in Rosetta.
    configure.args-append \
        --build=powerpc-apple-darwin${os.major} \
        --enable-serial-build-configure
}

build.args \
    MAKEINFO="/usr/bin/true" \
    LEXLIB="${prefix}/lib/libfl.a"

destroot.args \
    MAKEINFO="/usr/bin/true" \
    LEXLIB="${prefix}/lib/libfl.a"

post-destroot {
    if { ${os.arch} ne "powerpc" } {
        system "chgrp procmod ${destroot}${prefix}/bin/*-apple"
        system "chmod g+s ${destroot}${prefix}/bin/*-apple"
    }

    delete {*}[glob ${destroot}${prefix}/lib/*.{,l}a]
    delete {*}[glob ${destroot}${prefix}/bin/{addr2line,ar,c*filt,nm,objcopy,objdump,ranlib,readelf,size,strings,strip}-apple]
    delete {*}[glob ${destroot}${prefix}/*darwin*]
    delete {*}[glob ${destroot}${prefix}/include/*.h]
    delete {*}[glob ${destroot}${prefix}/share/locale/*/LC_MESSAGES/{bfd,binutils,opcodes}.mo]
}

if {${os.platform} eq "darwin" && ${os.major} >= 12} {
    notes "
You will need to make sure /System/Library/LaunchDaemons/com.apple.taskgated.plist\
has the '-p' option, e.g.
            <key>ProgramArguments</key>
            <array>
                    <string>/usr/libexec/taskgated</string>
                    <string>-sp</string>
            </array>
"
}

livecheck.type          none
