# -*- 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            squid
version         6.4
categories      net
license         GPL-2+
maintainers     {jmr @jmroot} openmaintainer
description     advanced proxy caching server for http, https, ftp
long_description    Squid is a high-performance proxy caching server for \
                web clients, supporting FTP and HTTP data \
                objects. Squid keeps metadata and \
                especially hot objects cached in RAM, caches DNS \
                lookups, supports non-blocking DNS lookups, and \
                implements negative caching of failed requests. \
                Squid 6.x is the latest release series, and needs a \
                C++17 compiler to build.

homepage        http://www.squid-cache.org/
master_sites    https://mirror.aarnet.edu.au/pub/squid/squid/ \
                https://www.mirrorservice.org/sites/ftp.squid-cache.org/pub/squid/ \
                http://ftp.ring.gr.jp/archives/net/www/squid/ \
                ftp://ftp.is.co.za/pub/squid/ \
                ftp://ftp1.cl.squid-cache.org/pub/squid/ \
                http://www.squid-cache.org/Versions/v6/ \
                ftp://ftp.squid-cache.org/pub/squid/

use_xz          yes
checksums       md5 8031857fd54fad4a7b4f4db4d44aa761 \
                sha1 23733fc08ed7a76d7e19877a4e04c105222b6cec \
                rmd160 c4a0044df8b80538a954f4584811ab4369ee3231 \
                sha256 5ebbced99b3df21bfcf4d1ec39455dff775a5ff6b9215d9f0339958771a88589

patchfiles      patch-compat_types.h.diff \
                patch-basic_pam_auth.cc.diff \
                kerberos_ldap_group_Makefile.in.diff \
                ltdl-lib.patch

platform darwin {
    if {${os.major} == 10} {
        # ticket #37102, /usr/include/rpcsvc/yp_prot.h tries to redefine bool
        patchfiles-append snowleopard-bool.diff
    } elseif {${os.major} >= 11 && ${os.major} <= 16} {
        # symbols missing from libc++
        patchfiles-append bad_optional_access.patch
        if {${os.major} == 11} {
            # https://bugs.llvm.org/show_bug.cgi?id=10817
            patchfiles-append   getline-workaround.patch
        }
    }
}

depends_build   port:pkgconfig
depends_lib     port:expat port:libtool port:zlib

conflicts       squid2 squid3 squid5

compiler.cxx_standard   2017

configure.args  --mandir=${prefix}/share/man \
                --sysconfdir=${prefix}/etc/squid \
                --datadir=${prefix}/share/squid \
                --localstatedir=${prefix}/var/squid \
                --libexecdir=${prefix}/libexec/squid \
                --with-swapdir=${prefix}/var/squid/cache \
                --with-pidfile=${prefix}/var/run/squid/squid.pid \
                --with-ltdl-include=${prefix}/include \
                --with-ltdl-lib=${prefix}/lib \
                --disable-strict-error-checking \
                --disable-arch-native \
                --without-cppunit \
                --without-gnugss \
                --without-gnutls \
                --without-xml2 \
                --without-mit-krb5 \
                --without-heimdal-krb5 \
                --without-nettle \
                --without-openssl \
                --enable-delay-pools \
                --enable-follow-x-forwarded-for \
                --enable-zph-qos \
                --enable-removal-policies \
                --enable-storeio=ufs,aufs,diskd,rock \
                --enable-log-daemon-helpers \
                --with-default-user=squid \
                --enable-auth \
                --enable-auth-basic \
                --enable-auth-digest \
                --enable-auth-negotiate="wrapper" \
                --enable-auth-ntlm

platform darwin {
    # Doesn't work and just generates failure messages in the log
    configure.args-append   --disable-eui
}

post-configure {
    if {[variant_exists universal] && [variant_isset universal]} {
        system -W ${worksrcpath} "ed - include/autoconf.h < ${filespath}/include_autoconf.h.ed && touch include/stamp-h1"
    }
}

startupitem.create      yes
startupitem.name        Squid
startupitem.netchange   yes
startupitem.executable  ${prefix}/sbin/squid -s --foreground

add_users       squid group=squid home=${prefix}/var/squid

notes "Before starting $name for the first time, create the cache directories\
with:
    ${prefix}/sbin/squid -s -z --foreground"

post-destroot   {
    xinstall -o squid -g squid -m 755 -d \
        ${destroot}${prefix}/var/run/squid ${destroot}${prefix}/var/squid \
        ${destroot}${prefix}/var/squid/cache ${destroot}${prefix}/var/squid/logs
    file delete -force ${destroot}${prefix}/etc/squid/squid.conf \
                       ${destroot}${prefix}/etc/squid/mime.conf \
                       ${destroot}${prefix}/etc/squid/cachemgr.conf \
                       ${destroot}${prefix}/etc/squid/errorpage.css
}
destroot.keepdirs   ${destroot}${prefix}/var/run/squid \
                ${destroot}${prefix}/var/squid/cache \
                ${destroot}${prefix}/var/squid/logs

post-activate {
    # Make sure initial conf files are present and setup correctly
    foreach f { squid.conf mime.conf cachemgr.conf errorpage.css } {
        if {![file exists ${prefix}/etc/squid/${f}]} {
            file copy ${prefix}/etc/squid/${f}.default \
                ${prefix}/etc/squid/${f}
        }
    }
}

variant openssl conflicts gnutls description "Enable SSL/TLS support using OpenSSL" {
    depends_lib-append      path:lib/libssl.dylib:openssl
    configure.args-delete   --without-openssl
    configure.args-append   --with-openssl=${prefix}
}

if {![variant_isset gnutls]} {
    default_variants    +openssl
}

variant gnutls conflicts openssl description "Enable SSL/TLS support using GnuTLS (experimental)" {
    depends_lib-append      path:lib/pkgconfig/gnutls.pc:gnutls
    configure.args-delete   --without-gnutls
}

variant ipfw_transparent description "Enable transparent proxy support using IPFW" {
    configure.args-append   --enable-ipfw-transparent
}

variant kerberos description "Enable MIT kerberos support" {
    depends_lib-append port:kerberos5
    configure.args-delete --enable-auth-negotiate="wrapper" \
                          --without-mit-krb5
    configure.args-append --enable-auth-negotiate
}

variant ssl_crtd requires openssl description "Enable use of external certificate generator (for SSL-Bump)" {
    configure.args-append   --enable-ssl-crtd
}

livecheck.type  regexm
livecheck.url   ${homepage}Versions/
livecheck.regex {Latest Release[^\n]*\n?[^\n]*\n?[^\n]*<td>([0-9.]+)</td>}
