# -*- 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               conflicts_build 1.0
PortGroup               muniversal 1.0

name                    clucene
version                 2.3.3.4
revision                5
set branch              [join [lrange [split ${version} .] 0 1] .]
categories              devel
maintainers             free.fr:dinh.viet.hoa openmaintainer
license                 {Apache-2 LGPL}
description             Clucene is a C++ port of Lucene: the high-performance, \
                        full-featured text search engine written in Java.
long_description        {*}${description}

distname                ${name}-core-${version}
homepage                http://clucene.sourceforge.net/
master_sites            sourceforge:project/clucene/clucene-core-unstable/${branch}

checksums               rmd160  5acfc9c8acd167b3684cfc731a60fd9c5465cc9b \
                        sha256  ddfdc433dd8ad31b5c5819cc4404a8d2127472a3b720d3e744e8c51d79732eab \
                        size 2241498

depends_lib             port:zlib

patch.pre_args-replace  -p0 -p1
# Patch corrects a problem when linking applications using clucene because
# the .pc file is missing clucene-shared library.
# http://sourceforge.net/tracker/?func=detail&aid=3461512&group_id=80013&atid=558446
patchfiles              0001-Fix-.pc-file-by-adding-clucene-shared-library.patch

patchfiles-append       patch-src-shared-CLucene-LuceneThreads.h.diff \
                        patch-src-shared-CLucene-config-repl_tchar.h.diff \
                        patch-${name}-contribs-lib.diff

# The "fix" added by MacPorts breaks the build: https://github.com/macports/macports-ports/commit/ae66ef97aafa5f576bf39d5bd7e2a2e983602f6f
if {[string match *clang* ${configure.compiler}]} {
    patchfiles-append   patch-fix-binary-function.diff \
                        patch-fix-clang.diff
}

# The port builds fine with Apple gcc; however if it gets built with modern gcc, ensure C++ ABI is set correctly.
if {![string match *gcc-4.* ${configure.compiler}]} {
    compiler.cxx_standard   2011
}

post-patch {
    # Patch out installing bundled Boost headers
    reinplace "/ADD_SUBDIRECTORY (src\\/ext)/d" CMakeLists.txt
    system "rm -rf src/ext"

    # It detects fstat64 and stat64 on arm64 which doesn't exist.
    # Also avoid those on 32-bit and ppc64, which leaves out x86_64.
    if {${os.platform} eq "darwin" && ${configure.build_arch} ne "x86_64"} {
        reinplace "s|fstati64;_fstati64;fstat64;fstat;_fstat|fstat;_fstat|" ${worksrcpath}/src/shared/CMakeLists.txt
        reinplace "s|stati64;_stati64;stat64;stat;_stat|stat;_stat|" ${worksrcpath}/src/shared/CMakeLists.txt
    }
}

configure.args-append   -DBUILD_CONTRIBS_LIB=ON \
                        -DLIB_DESTINATION=${destroot}/lib

conflicts_build         ${name}

livecheck.regex         ${name}-core-(\[0-9.\]+)${extract.suffix}
