require "mkmf"

dir_config('rocksdb')
RbConfig::CONFIG["CPP"] = "g++ -E -std=gnu++17"

DEBUG_BUILD = have_library('rocksdb_debug') || ENV["DEBUG_LEVEL"]

if have_header('rocksdb/db.h') and (have_library('rocksdb') or have_library('rocksdb_debug'))
  $CPPFLAGS << " -std=gnu++17"

  if DEBUG_BUILD
    CONFIG["optflags"] = "-O0"
  end

  create_makefile("RocksDB/RocksDB")
else
  abort "can't find header or library of rocksdb"
end

require "mkmf"

dir_config('rocksdb')
cxx = RbConfig::CONFIG["CXX"]
RbConfig::CONFIG["CPP"] = "#{cxx} -E -std=gnu++17"
RbConfig::CONFIG["CC"] = "#{cxx} -std=gnu++17"

DEBUG_BUILD = have_library('rocksdb_debug') || ENV["DEBUG_LEVEL"]

if have_header('rocksdb/db.h') and (have_library('rocksdb') or have_library('rocksdb_debug'))
  $CPPFLAGS << " -std=gnu++17"

  if DEBUG_BUILD
    CONFIG["optflags"] = "-O0"
  end

  create_makefile("RocksDB/RocksDB")
else
  abort "can't find header or library of rocksdb"
end

Fix build for MacOS on Ruby 3.1
Fix build for MacOS on Ruby 3.1

Between Ruby 3.0 and 3.1 the behaviour of `have_library` has changed.
Now it does not use `RbConfig::CONFIG['CPP']`, but
`RbConfig::CONFIG['CC']`. To allow the extension to compile on MacOS,
the latter needs to be adjusted as well.

This also uses `RbConfig::CONFIG['CXX']` instead of hard-coded `g++`, as
using `g++` caused me some troubles with unknown flags on MacOS as well
(I have `gcc` installed along clang for _reasons_).
