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

# strnlen
legacysupport.newest_darwin_requires_legacy 10

github.setup        Genivia ugrep 7.8.4 v
revision            0
categories          textproc sysutils
license             BSD
maintainers         {reneeotten @reneeotten} openmaintainer

description         Ultra-fast grep with interactive query UI and fuzzy search
long_description    {*}${description}: search file systems, source code, text, \
                    binary files, archives (cpio/tar/pax/zip), compressed files \
                    (gz/Z/bz2/lzma/xz/lz4/zstd), documents and more.

checksums           rmd160  3fece2299829e463308b2af16c3a4ba4e9c9690b \
                    sha256  b16b3503e80890c78a5c845f8c141f239f3904359f1e41900ca566c86e120172 \
                    size    7224457
github.tarball_from archive

compiler.cxx_standard   2011

# Fix build failure on OS X 10.8–10.9:
# /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/list:227:9: error: field has incomplete type 'GrepWorker'
# see: https://github.com/Genivia/ugrep/issues/130
compiler.blacklist-append {clang < 700}

patch.pre_args-replace  -p0 -p1
patchfiles-append   0001-Add-AltiVec-VMX-SIMD-primitives-and-build-detection.patch \
                    0002-Add-AltiVec-nlcount-and-isutf8.patch \
                    0003-Add-AltiVec-needle-and-string-search.patch

depends_lib-append  port:bzip2 \
                    port:lz4 \
                    port:lzma \
                    port:pcre2 \
                    port:zlib \
                    port:zstd

configure.args      --disable-altivec \
                    --disable-avx2 \
                    --disable-neon \
                    --disable-silent-rules \
                    --disable-sse2 \
                    --with-bzlib=${prefix} \
                    --with-lz4=${prefix} \
                    --with-lzma=${prefix} \
                    --with-pcre2=${prefix} \
                    --with-zlib=${prefix} \
                    --with-zstd=${prefix} \
                    --without-boost-regex \
                    --without-brotli \
                    --without-bzip3

# Variant becomes meaningless where SIMD code is absent in ugrep:
if {${os.arch} in [list arm i386 powerpc]} {
    variant simd description "Enable CPU-specific optimizations" {
        use_autoreconf yes

        configure.args-delete \
                    --disable-altivec \
                    --disable-avx2 \
                    --disable-sse2 \
                    --disable-neon
    }
}

test.run            yes
