# -*- 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               cmake 1.1
PortGroup               legacysupport 1.1
PortGroup               openssl 1.0

name                    clamav-legacy
set realname            clamav
conflicts               clamav
version                 0.104.4
revision                1
categories              sysutils
platforms               {darwin < 11}
maintainers             nomaintainer
description             ClamAV anti-virus software adapted to older MacOS
license                 {GPL-2 OpenSSLException}

long_description        Clam AntiVirus is a GPL anti-virus toolkit for UNIX. \
                        The main purpose of this software is the integration \
                        with mail servers (attachment scanning). This port supports \
                        old Macs with Mac OS X 10.4–10.6 (Tiger, Leopard, Snow Leopard).

homepage                https://www.clamav.net
master_sites            https://www.clamav.net/downloads/production
distname                ${realname}-${version}
checksums               rmd160  9158544048971e28c71ebf60ea39b42afcb8ce04 \
                        sha256  8ac32e910aa744cc7f921c5122ba523ef1ffbbbf94545f94fc4a976b502be74b \
                        size    12027448

# Disable tests to avoid extra dependencies
configure.args-append   -DENABLE_TESTS=OFF

depends_build-append    port:pkgconfig

depends_lib-append      port:bzip2 \
                        port:curl \
                        port:json-c \
                        port:libiconv \
                        port:libtool \
                        port:libxml2 \
                        port:ncurses \
                        port:pcre2 \
                        port:zlib

# older systems support
post-extract {
    platform darwin {
        # use linux version of openssl cert util on systems < 10.7 that don't support the macOS version
        # ./common/linux/cert_util_linux.c -> ./common/mac/cert_util_mac.m
        # passes all tests. See: https://trac.macports.org/ticket/59168

        ui_msg  "replacing mac security with linux security"
        delete  ${worksrcpath}/common/mac/cert_util_mac.m
        copy    ${worksrcpath}/common/linux/cert_util_linux.c \
                ${worksrcpath}/common/mac/cert_util_mac.m

        # remove two switchs not supported by the older gcc versions often used on these systems
        reinplace "s/-Wno-logical-op-parentheses//g" ${worksrcpath}/libclamunrar/CMakeLists.txt
        reinplace "s/-Wno-dangling-else//g" ${worksrcpath}/libclamunrar/CMakeLists.txt
    }
}

platform darwin 8 {
    configure.args-append   -DOPTIMIZE=OFF
}

variant clamav_milter description {Build with libmilter support} {
    depends_lib-append      port:libmilter
    configure.args-append   -DENABLE_MILTER=ON
}

pre-test {
    if {![variant_isset tests]} {
        ui_error "'tests' variant must be activated to enable test support"
        error "Please enable the 'tests' variant and try again"
    }
}

variant tests description {Enable running 'port test'} {
    ui_msg "Tests run using the installed version of this port."

    depends_test-append \
                    port:check \
                    port:py311-pytest

    configure.args-delete \
                    -DENABLE_TESTS=OFF
    configure.pre_args-replace \
                    -DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=ON \
                    -DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=OFF

    test.run        yes
    test.cmd        ctest
    test.target     --rerun-failed --output-on-failure
}

livecheck.type      regex
livecheck.url       https://www.clamav.net/downloads
livecheck.regex     ${name}-(\\d+.\\d+.\\d+)${extract.suffix}
