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

github.setup        util-linux util-linux 2.41.2 v
github.tarball_from archive
revision            0
checksums           rmd160  20b154ae8e6d6d615dda90d896f303deb342082f \
                    sha256  6062a1d89b571a61932e6fc0211f36060c4183568b81ee866cf363bce9f6583e \
                    size    9612488

set branch          [join [lrange [split ${version} .] 0 1] .]
categories          devel
maintainers         {khindenburg @kurthindenburg} openmaintainer
license             BSD GPL-2+ public-domain

description         Linux utility programs

long_description    ${name} contains miscellaneous utility programs \
                    to handle file systems, consoles, partitions, \
                    and messages. This port contains ONLY those parts \
                    of ${name} that run on Darwin.

# master_sites        https://www.kernel.org/pub/linux/utils/util-linux/v${branch}/
# The above site redirects permanently (301) to mirrors.edge.kernel.org
master_sites        https://mirrors.edge.kernel.org/pub/linux/utils/util-linux/v${branch}/

# mirrors.edge.kernel.org doesn't work with some earlier Apple root CAs,
# so we need to disable the certificate check.  This isn't much of a risk,
# since the distfile has to pass the checksum/size checks, anyway.
#
# When updating the port to a new version, some extra manual checking
# of the distfile would be desirable, by performing a certificate-validated
# check and/or checking the PGP signature.  Note that the .sign file
# applies to the uncompressed tarball in this case.
fetch.ignore_sslcert    yes

use_xz              yes

if { ${os.platform} eq "darwin" && ${os.major} < 9 } {
    configure.cppflags-append -D__DARWIN_UNIX03

    # disable strict POSIX on Tiger as it blocks certain functions
    # https://trac.macports.org/ticket/65582
    patchfiles-append patch-util-linux-disable-posix-tiger.diff
}

depends_lib-append  port:gettext \
                    port:ncurses

# --disable-all-programs doesn't work as there's no way to enable what we want
configure.args      --disable-agetty \
                    --disable-cramfs \
                    --disable-eject \
                    --disable-fallocate \
                    --disable-fsck \
                    --disable-kill \
                    --disable-libblkid \
                    --disable-liblastlog2 \
                    --disable-libmount \
                    --disable-libuuid \
                    --disable-login \
                    --disable-losetup \
                    --disable-mount \
                    --disable-mountpoint \
                    --disable-partx \
                    --disable-pg \
                    --disable-pg-bell \
                    --disable-pivot_root \
                    --disable-schedutils \
                    --disable-silent-rules \
                    --disable-su \
                    --disable-sulogin \
                    --disable-switch_root \
                    --disable-unshare \
                    --disable-uuidd \
                    --disable-wall \
                    --enable-shared=no \
                    --without-audit \
                    --without-python

# The build procedure now includes checking related to the Y2038 problem, which
# fails on 32-bit builds (due to the 32-bit time_t).  This check can be disabled
# with the --disable-year2038 configure option.  Although it's probably OK
# to set this option unconditionally, for maximum safety we only set it when
# needed, i.e. when there's a 32-bit target.  This needs to take into account
# all target archs in universal builds.
#
if {[variant_isset universal]} {
    set target_archs ${configure.universal_archs}
} else {
    set target_archs ${configure.build_arch}
}
set have_32bit no
foreach arch ${target_archs} {
    if {${arch} in [list arm i386 ppc]} {
        set have_32bit yes
    }
}
if {${have_32bit}} {
    configure.args-append --disable-year2038
}

# https://trac.macports.org/wiki/WimplicitFunctionDeclaration#strchr
configure.checks.implicit_function_declaration.whitelist-append strchr

# When adding new programs, check the .c file for license
build.target        colcrt column getopt hardlink look rename rev scriptreplay setsid

destroot {
    foreach path {
            text-utils/colcrt
            text-utils/column
            misc-utils/getopt
            misc-utils/hardlink
            misc-utils/look
            misc-utils/rename
            text-utils/rev
            term-utils/scriptreplay
            sys-utils/setsid
        } {
        set file [lindex [split ${path} /] 1]
        xinstall -m 755 ${worksrcpath}/${file} ${destroot}${prefix}/bin
        xinstall -m 644 ${worksrcpath}/${path}.1 ${destroot}${prefix}/share/man/man1
    }

    set bash.d ${prefix}/etc/bash_completion.d
    xinstall -m 755 -d ${destroot}${bash.d}

    build.target-delete hardlink
    foreach _target "${build.target}" {
        xinstall -m 644 ${worksrcpath}/bash-completion/${_target} \
                        ${destroot}${bash.d}
    }

    set docdir ${prefix}/share/doc/${name}
    xinstall -m 755 -d ${destroot}${docdir}
    xinstall -m 644 -W ${worksrcpath} README NEWS ChangeLog COPYING AUTHORS ABOUT-NLS \
                       ${destroot}${docdir}
}

github.livecheck.regex  {([0-9.]+)}
