# -*- 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
# $Id: Portfile 118485 2014-04-03 08:36:53Z ryandesign@macports.org $

PortSystem 1.0

name                file
version             5.18
revision            1
categories          sysutils
license             BSD
maintainers         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            http://www.darwinsys.com/file/
platforms           darwin
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}/

checksums           rmd160  c344ed01498fbd57e5840d81378de155ad2d8876 \
                    sha256  6519fb706d583231c2419592ebecdbb21d33c62eaf7a1a0b24ddfcb80c08bf07

patchfiles          patch-post-518.diff \
                    patch-magic-Makefile.am.diff \
                    patch-getline.diff

configure.args      --disable-silent-rules \
                    --enable-fsect-man5

depends_lib         port:zlib

use_autoreconf      yes
autoreconf.args     -fvi

if {${name} eq ${subport}} {
    depends_lib-append port:libmagic
    
    destroot {
        xinstall -W ${worksrcpath}/src/.libs file ${destroot}${prefix}/bin
        xinstall -m 644 -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 {
    post-destroot {
        delete ${destroot}${prefix}/bin/file ${destroot}${prefix}/share/man/man1/file.1
    }
    
    pre-activate {
        # file @5.14_0 and earlier installed some files now provided by libmagic
        if {![catch {set installed [lindex [registry_active file] 0]}]} {
            set file_version [lindex ${installed} 1]
            set file_revision [lindex ${installed} 2]
            if {[vercmp ${file_version} 5.14] < 0 || ([vercmp ${file_version} 5.14] == 0 && ${file_revision} < 1)} {
                registry_deactivate_composite file "" [list ports_nodepcheck 1]
            }
        }
    }
}
