# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4

PortSystem      1.0
PortGroup       gnulib 1.0

name            coreutils-devel
conflicts       gexpr coreutils
set my_name     coreutils

version         9.10
revision        0

categories      sysutils
license         GPL-3+
maintainers     {mascguy @mascguy} openmaintainer

description     GNU File, Shell, and Text utilities
long_description \
    The GNU Core Utilities are the basic file, shell, and text \
    manipulation utilities of the GNU operating system. These are the \
    core utilities which are expected to exist on every operating \
    system. Previously these utilities were offered as three individual \
    sets of GNU utilities, fileutils, shellutils, and textutils. Those \
    three have been combined into a single set of utilities called the \
    coreutils.
homepage        https://www.gnu.org/software/${my_name}/

master_sites    gnu:${my_name}
distname        ${my_name}-${version}
dist_subdir     ${my_name}
use_xz          yes

installs_libs   no

checksums       rmd160  28c26e45157a50942319eab9be2e3743f846cefd \
                sha256  16535a9adf0b10037364e2d612aad3d9f4eca3a344949ced74d12faf4bd51d25 \
                size    6507600

depends_build-append \
                port:gettext

depends_lib-append \
                port:gettext-runtime \
                port:gmp \
                port:libiconv

# Fix issues with older Clang releases
compiler.blacklist-append \
                {clang < 900}

configure.args-append \
                --disable-silent-rules \
                --program-prefix=g \
                --with-openssl=no

# Bypass year 2038 awareness code, which causes failures for 32-bit/universal.
configure.args-append \
                --disable-year2038

# Whether deliberately or not, some users run MacPorts as root without privilege dropping.
configure.env-append \
                FORCE_UNSAFE_CONFIGURE=1

configure.checks.implicit_function_declaration.whitelist-append strchr

post-destroot {
    if {[file exists ${destroot}${prefix}/share/info/dir]} {
        delete ${destroot}${prefix}/share/info/dir
    }

    if {[file exists ${destroot}${prefix}/lib/charset.alias]} {
        delete ${destroot}${prefix}/lib/charset.alias
    }

    set docdir ${prefix}/share/doc/${my_name}
    xinstall -d ${destroot}${docdir}
    xinstall -m 0644 -W ${worksrcpath} AUTHORS COPYING ChangeLog NEWS README \
        THANKS THANKS-to-translators TODO ${destroot}${docdir}

    # Prevent conflict with gegl
    # See https://trac.macports.org/ticket/55327
    move ${destroot}${prefix}/bin/gcut ${destroot}${prefix}/bin/gnucut

    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]
    }

    # Fix symlink to gnu cut
    move ${destroot}${prefix}/libexec/gnubin/nucut ${destroot}${prefix}/libexec/gnubin/cut

    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
    }

    # Fix manpage for gnucut
    move ${destroot}${prefix}/share/man/man1/gcut.1 ${destroot}${prefix}/share/man/man1/gnucut.1
    delete ${destroot}${prefix}/libexec/gnubin/man/man1/cut.1.gz
    ln -s ${prefix}/share/man/man1/gnucut.1.gz ${destroot}${prefix}/libexec/gnubin/man/man1/cut.1.gz

}

# Set the RUN_EXPENSIVE_TESTS environment variable to 'yes' to run more
# expensive tests.  Set the RUN_VERY_EXPENSIVE_TESTS environment variable
# to 'yes' to run even more expensive tests.
test.run        yes
test.target     check

notes "
    The tools provided by GNU coreutils are prefixed with the character 'g' by default to distinguish them from the BSD commands.
    For example, cp becomes gcp and ls becomes gls.

    If you want to use the GNU tools by default, add this directory to the front of your PATH environment variable:
        ${prefix}/libexec/gnubin/
"

livecheck.name  ${my_name}
