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

name                file
version             5.48
checksums           rmd160  86faf8eeb05e9a1853c059aca41ea1600a1c158e \
                    sha256  ed14656883b23a364b4057c05595d93252da9bc473d30106519519d0da141283 \
                    size    2693209

categories          sysutils
license             BSD
maintainers         {ryandesign @ryandesign} openmaintainer

description         File - determine file type
long_description \
    File tests each argument in an attempt to classify it. There are three  \
    sets of tests, performed in this order: filesystem tests, magic number  \
    tests, and language tests. The first test that succeeds causes the file \
    type to be printed. \
    For information on Mach-O binaries, it is suggested that one uses the command \
    `otool -fv`.

homepage            https://www.darwinsys.com/file/
master_sites        freebsd \
                    gentoo \
                    ftp://ftp.fu-berlin.de/unix/tools/${name}/ \
                    ftp://ftp.astron.com/pub/${name}/ \
                    ftp://ftp.gw.com/mirrors/pub/unix/${name}/ \
                    https://astron.com/pub/${name}/

patchfiles          patch-magic-Makefile.am.diff

configure.args      --disable-libseccomp \
                    --disable-lzlib \
                    --disable-silent-rules \
                    --enable-bzlib \
                    --enable-shared \
                    --enable-static \
                    --enable-fsect-man5 \
                    --enable-xzlib \
                    --enable-zlib \
                    --enable-zstdlib

depends_lib         port:bzip2 \
                    port:xz \
                    port:zlib \
                    port:zstd

# We patch Makefile.am files.
use_autoreconf      yes
autoreconf.args     -fvi
# alignof is C23, not necessary to build
configure.checks.implicit_function_declaration.whitelist-append strchr alignof
configure.checks.implicit_int   no

if {${name} eq ${subport}} {
    revision            0

    depends_lib-append port:libmagic

    destroot {
        xinstall -W ${worksrcpath}/src/.libs file ${destroot}${prefix}/bin
        xinstall -m 0644 -W ${worksrcpath}/doc file.1 ${destroot}${prefix}/share/man/man1
    }

    livecheck.type      regex
    livecheck.url       ftp://ftp.astron.com/pub/${name}/
    livecheck.regex     ${name}-(\\d+(?:\\.\\d+)*)${extract.suffix}
} else {
    livecheck.type      none
}

subport libmagic {
    revision            0

    post-destroot {
        delete ${destroot}${prefix}/bin/file ${destroot}${prefix}/share/man/man1/file.1
    }
}
