# Description: A fast compressor/decompressor library
# URL: https://google.github.io/snappy/
# Maintainer: Tim Biermann, tbier at posteo dot de

name=snappy
version=1.2.0
release=1
source=(https://github.com/google/snappy/archive/$version/$name-$version.tar.gz
  snappy-thirdparty.patch
  snappy-do-not-disable-rtti.patch)

build() {
  patch -d $name-$version -p1 -i $SRC/snappy-thirdparty.patch
  patch -d $name-$version -p1 -i $SRC/snappy-do-not-disable-rtti.patch

  cmake -S $name-$version -B build -G Ninja \
    -D CMAKE_INSTALL_PREFIX=/usr \
    -D CMAKE_INSTALL_LIBDIR=lib \
    -D CMAKE_BUILD_TYPE=Release \
    -D CMAKE_CXX_FLAGS_RELEASE="$CXXFLAGS" \
    -D CMAKE_C_FLAGS_RELEASE="$CFLAGS" \
    -D BUILD_SHARED_LIBS=ON \
    -D SNAPPY_BUILD_TESTS=OFF \
    -D SNAPPY_BUILD_BENCHMARKS=OFF \
    -D HAVE_LIBZ=NO \
    -D HAVE_LIBLZO2=NO \
    -D HAVE_LIBLZ4=NO \
    -Wno-dev
  cmake --build build
  DESTDIR=$PKG cmake --install build

cat <<- EOF > snappy.pc
prefix=/usr
exec_prefix=\${prefix}
includedir=\${prefix}/include
libdir=\${exec_prefix}/lib

Name: ${name}
Description: A fast compression/decompression library
Version: ${version}
Cflags: -I\${includedir}
Libs: -L\${libdir} -lsnappy
EOF

  install -Dm644 snappy.pc $PKG/usr/lib/pkgconfig/snappy.pc
}
