# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0

name                pcre
if {${subport} eq ${name}} {
    version         8.45
    revision        0
    platform darwin 20 {
        revision    0
    }
}
subport pcre2 {
    version         10.37
    revision        0
}
categories          devel
license             BSD
platforms           darwin freebsd
maintainers         {larryv @larryv}

description         Perl Compatible Regular Expressions
long_description    The PCRE library is a set of functions that \
                    implement regular expression pattern matching \
                    using the same syntax and semantics as Perl 5. \
                    PCRE has its own native API, as well as a set of \
                    wrapper functions that correspond to the POSIX \
                    regular expression API.
homepage            https://www.pcre.org

depends_lib         port:bzip2 \
                    port:libedit \
                    port:zlib

master_sites        sourceforge:project/pcre/${subport}/${version} \
                    https://ftp.pcre.org/pub/pcre \
                    ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre \
                    ftp://ftp.fu-berlin.de/unix/misc/pcre \
                    ftp://ftp.tin.org/pub/libs/pcre
distname            ${subport}-${version}
use_bzip2           yes

set rmd160(pcre)    9792fbed380a39be36674e74839b9a2a6a4ce65a
set sha256(pcre)    4dae6fdcd2bb0bb6c37b5f97c33c2be954da743985369cddac3546e3218bffb8
set size(pcre)      1578809
set rmd160(pcre2)   260daa9d31e76ecc428e84ab3f2ed3ba41b7ee37
set sha256(pcre2)   4d95a96e8b80529893b4562be12648d798b957b1ba1aae39606bbc2ab956d270
set size(pcre2)     1729384
checksums           rmd160  $rmd160(${subport}) \
                    sha256  $sha256(${subport}) \
                    size    $size(${subport})

patchfiles          no-darwin-pthread-flag.patch

configure.args      --disable-silent-rules \
                    --docdir=${prefix}/share/doc/${subport} \
                    --enable-[regsub {\d$} ${subport} &-]16 \
                    --enable-[regsub {\d$} ${subport} &-]32 \
                    --enable-${subport}grep-libbz2 \
                    --enable-${subport}grep-libz \
                    --enable-${subport}test-libedit

# PCRE's JIT is not Apple Silicon compatible yet.
# https://bugs.exim.org/show_bug.cgi?id=2618
# The pkg-config files vary depending on whether or not JIT is enabled
# so we have to disable it for all archs if arm64 is among the archs.
variant universal {}
if {"arm64" in [get_canonical_archs]} {
    configure.args-append --disable-jit
} else {
    configure.args-append --enable-jit
}

subport pcre {
    PortGroup clang_dependency 1.0
    configure.args-append --enable-unicode-properties
}

platform darwin 8 {
    # ticket #18448
    if {[variant_isset universal]} {
        configure.ldflags-append -lncurses
    }
}

test.run            yes
test.target         check

livecheck.distname  ${subport}
