# -*- 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                3
set branch              [join [lrange [split ${version} .] 0 1] .]
categories              devel
platforms               darwin
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

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
    if {${build_arch} eq {arm64} && ${os.platform} eq "darwin"} {
        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}
