##
##  rocksdb.spec -- OpenPKG RPM Package Specification
##  Copyright (c) 2000-2025 OpenPKG Project <http://openpkg.org/>
##
##  Permission to use, copy, modify, and distribute this software for
##  any purpose with or without fee is hereby granted, provided that
##  the above copyright notice and this permission notice appear in all
##  copies.
##
##  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
##  SUCH DAMAGE.
##

#   package information
Name:         rocksdb
Summary:      Key-Value Store
URL:          http://rocksdb.org/
Vendor:       Facebook
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Database
License:      Apache/GPL
Version:      10.5.1
Release:      20250823

#   package options
%option       with_java  no

#   list of sources
Source0:      https://github.com/facebook/rocksdb/archive/v%{version}.tar.gz
Patch0:       rocksdb.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, make, gcc, gcc::with_cxx = yes
PreReq:       OpenPKG, openpkg >= 20160101
BuildPreReq:  snappy
PreReq:       snappy
%if "%{with_java}" == "yes"
BuildPreReq:  java, JAVA-JDK
PreReq:       java, JAVA-JDK
%endif

%description
    RocksDB is a fast embeddable key-value storage library. RocksDB is
    developed and maintained by Facebook Database Engineering Team. It
    is built on on earlier work on Google's LevelDB which in turn is is
    inspired by BigTable. RocksDB internally uses a Log-Structured-Merge
    (LSM) tree.

%track
    prog rocksdb = {
        version   = %{version}
        url       = https://github.com/facebook/rocksdb/releases
        regex     = tree/v(\d+\.\d+\.\d+)
    }

%prep
    %setup -q
    %patch -p0

%build
    export CC="%{l_cc}"
    export CXX="%{l_cxx}"
    export CFLAGS="-I`pwd`/include %{l_cflags -O} %{l_cppflags}"
    export CXXFLAGS="-I`pwd`/include %{l_cxxflags -O} -std=c++14 %{l_cppflags}"
    export LDFLAGS="%{l_ldflags}"
    export DEBUG_LEVEL=0
    export DISABLE_JEMALLOC=1
    export ROCKSDB_DISABLE_ZLIB=1
    export ROCKSDB_DISABLE_ZSTD=1
    export ROCKSDB_DISABLE_BZIP=1
    export ROCKSDB_DISABLE_LZ4=1
    export ROCKSDB_DISABLE_NUMA=1
    export ROCKSDB_DISABLE_TBB=1
    export ROCKSDB_DISABLE_JEMALLOC=1
    %{l_make} %{l_mflags -O}
%if "%{with_java}" == "yes"
    eval `JAVA_PLATFORM="sun-jdk" %{l_prefix}/bin/java-toolkit -e`
    CXXFLAGS="$CXXFLAGS -I$JAVA_HOME/include"
    CFLAGS="$CFLAGS -I$JAVA_HOME/include"
    %{l_make} %{l_mflags -O} rocksdbjavastaticrelease
%endif

%install
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/include/rocksdb \
        $RPM_BUILD_ROOT%{l_prefix}/lib
    cp -rp \
        include/rocksdb/* $RPM_BUILD_ROOT%{l_prefix}/include/rocksdb/
    %{l_shtool} install -c -m 644 \
        librocksdb.a $RPM_BUILD_ROOT%{l_prefix}/lib/
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std}

%files -f files

%clean

