# Description: Indexing and searching library
# URL: https://www.sourceforge.net/projects/clucene
# Maintainer: Tim Biermann, tbier at posteo dot de
# Depends on: cmake
# Optional: log4cxx bzip2 exiv2 boost

name=clucene
version=2.3.3.4
release=2
source=(https://downloads.sourceforge.net/project/clucene/clucene-core-unstable/2.3/$name-core-$version.tar.gz
  fix_zlib_detections.diff clucene-core-2.3.3.4-install_contribs_lib.patch clucene-narrowing-conversions.patch
  clucene-warnings.patch clucene-debug.patch clucene-gcc-atomics.patch clucene-multimap-put.patch
  clucene-2.3.3.4-contribs_lib-1.patch cmake.patch contribs-lib-makefile.patch
  0001-Fix-missing-include-time.h.patch)

build() {
  patch -Np1 -d $name-core-$version -i $SRC/cmake.patch
  patch -Np1 -d $name-core-$version -i $SRC/clucene-2.3.3.4-contribs_lib-1.patch
  patch -Np1 -d $name-core-$version -i $SRC/fix_zlib_detections.diff
  # LibreOffice patches http://cgit.freedesktop.org/libreoffice/core/tree/clucene/patches
  patch -Np0 -d $name-core-$version -i $SRC/clucene-warnings.patch
  patch -Np0 -d $name-core-$version -i $SRC/clucene-gcc-atomics.patch
  patch -Np0 -d $name-core-$version -i $SRC/clucene-debug.patch
  patch -Np0 -d $name-core-$version -i $SRC/clucene-narrowing-conversions.patch
  patch -Np0 -d $name-core-$version -i $SRC/clucene-multimap-put.patch
  patch -Np1 -d $name-core-$version -i $SRC/0001-Fix-missing-include-time.h.patch

  cmake -S $name-core-$version -B build -G Ninja $PKGMK_CLUCENE \
    -D CMAKE_INSTALL_PREFIX=/usr \
    -D CMAKE_BUILD_TYPE=Release \
    -D CMAKE_CXX_FLAGS_RELEASE="$CXXFLAGS" \
    -D CMAKE_C_FLAGS_RELEASE="$CFLAGS" \
    -D BUILD_CONTRIBS_LIB=ON \
    -D ENABLE_ASCII_MODE=OFF \
    -D ENABLE_PACKAGING=OFF \
    -D DISABLE_MULTITHREADING=OFF \
    -Wno-dev
  cmake --build build
  DESTDIR=$PKG cmake --install build
}
