# -*- 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

name            gdb-apple
version         1824
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.

homepage        http://opensource.apple.com/source/gdb
platforms       darwin
supported_archs x86_64 i386

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

distname        gdb-${version}
master_sites    http://opensource.apple.com/tarballs/gdb

checksums       rmd160  90290c3950dd06c1691a477b9ee302c00b681ed1 \
                sha256  d25b056a826015e1e0ea338b9b8f03e40dce3ff4696faf95df259ae1a42698da

depends_build   port:gettext port:zlib port:flex port:texinfo

depends_lib     port:libiconv port:ncurses port:sqlite3

patchfiles	patch-macosx-nat.c.diff

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
}

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

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

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

post-destroot {
    system "chgrp procmod ${destroot}${prefix}/bin/*-apple"
    system "chmod g+s ${destroot}${prefix}/bin/*-apple"

    foreach info [glob -tails -directory ${destroot}${prefix}/share/info g*] {
        move ${destroot}${prefix}/share/info/${info} ${destroot}${prefix}/share/info/apple-${info}
    }

    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/info/{annotate,bfd,stabs}.info]
    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