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

name                        diffutils
version                     3.11
revision                    0

categories                  sysutils textproc devel
license                     GPL-3+

maintainers                 nomaintainer

description                 GNU diff utilities
long_description            diffutils contains the GNU diff, diff3, sdiff, and cmp \
                            utilities.  Their features are a superset of the Unix \
                            features and they are significantly faster.

homepage                    https://www.gnu.org/software/diffutils/
master_sites                gnu

checksums                   rmd160  2d5564520263d4a958df299b8cad423fafa6c37f \
                            sha256  a73ef05fe37dd585f7d87068e4a0639760419f810138bd75c61ddaa1f9e2131e \
                            size    1926052

use_xz                      yes

#------------------------------------------------------------------------------
# Avoid older Xcode Clang versions, which fail with errors like the following:
#
# cmp.c:119:3: error: type name requires a specifier or qualifier
#   die (EXIT_TROUBLE, 0,
#   ^
# [...]
# cmp.c:119:3: error: expected member name or ';' after declaration specifiers
#   die (EXIT_TROUBLE, 0,
#   ^~~~~~~~~~~~~~~~~~~~~
# [...]
# cmp.c:119:3: error: expected ';' at end of declaration list
#   die (EXIT_TROUBLE, 0,
#   ^
# [...]
# cmp.c:156:5: error: type name requires a specifier or qualifier
#   die (EXIT_TROUBLE, 0, "%s", _("write failed"));
#   ^
# [...]
# cmp.c:156:5: error: expected member name or ';' after declaration specifiers
#   die (EXIT_TROUBLE, 0, "%s", _("write failed"));
#   ^
#------------------------------------------------------------------------------
compiler.blacklist-append   { clang < 900 }

depends_build-append        port:gettext

depends_lib-append          port:gettext-runtime

configure.args-append       --program-prefix=g \
                            --infodir=${prefix}/share/info \
                            --mandir=${prefix}/share/man \
                            --disable-silent-rules \
                            --disable-year2038

platform darwin 8 {
    post-patch {
        # use older register names in 10.4 SDK https://trac.macports.org/ticket/66482
        foreach reg {cr ctr eax ebp ebx ecx edi edx eip esi esp lr mq r0 r1 r10 r11 r12 r13 r14 r15 r16 r17 r18 r19 r2 r20 r21 r22 r23 r24 r25 r26 r27 r28 r29 r3 r30 r31 r4 r5 r6 r7 r8 r9 rax rbp rbx rcx rdi rdx rip rsi rsp ss sp srr0 srr1 vrsave xer} {
            reinplace -q "s|__${reg}|${reg}|g" ${worksrcpath}/lib/sigsegv.c
        }
    }
}

platform darwin 10 {
# This is a fix for Rosetta
    if {${build_arch} eq "ppc"} {
        configure.args-append --build=powerpc-apple-darwin10
    }
}

set docdir                  ${prefix}/share/doc/${name}

post-destroot {
    xinstall -m 0755 -d ${destroot}${docdir}
    xinstall -m 0644 -W ${worksrcpath} ABOUT-NLS AUTHORS ChangeLog COPYING NEWS README THANKS \
        ${destroot}${docdir}

    xinstall -m 755 -d ${destroot}${prefix}/libexec/gnubin
    foreach binary [glob -tails -directory ${destroot}${prefix}/bin g*] {
        ln -s ${prefix}/bin/${binary} ${destroot}${prefix}/libexec/gnubin/[string range $binary 1 end]
    }
    xinstall -m 755 -d ${destroot}${prefix}/libexec/gnubin/man/man1
    foreach manpage [glob -tails -directory ${destroot}${prefix}/share/man/man1 g*] {
        ln -s ${prefix}/share/man/man1/${manpage}.gz ${destroot}${prefix}/libexec/gnubin/man/man1/[string range $manpage 1 end].gz
    }
}

test.run                    yes
test.target                 check

livecheck.type              regex
livecheck.url               https://ftp.gnu.org/gnu/${name}/?C=M&O=D
livecheck.regex             ${name}-(\\d+(?:\\.\\d+)*)