# -*- 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
conflicts       gexpr coreutils-devel
set my_name     coreutils

version         9.5
revision        1

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  b61ac7d800501742f8188bbcdbf71d9994254a2f \
                sha256  cd328edeac92f6a665de9f323c93b712af1858bc2e0d88f3f7100469470a1b8a \
                size    6007136

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}
