# MariaDB - a database server that offers drop-in replacement functionality for MySQL.
# http://mariadb.org/

[buildout]
extends =
  ../binutils/buildout.cfg
  ../bzip2/buildout.cfg
  ../cmake/buildout.cfg
  ../groonga/buildout.cfg
  ../jemalloc/buildout.cfg
  ../libaio/buildout.cfg
  ../libxml2/buildout.cfg
  ../lz4/buildout.cfg
  ../ncurses/buildout.cfg
  ../openssl/buildout.cfg
  ../patch/buildout.cfg
  ../pcre/buildout.cfg
  ../pkgconfig/buildout.cfg
  ../readline/buildout.cfg
  ../snappy/buildout.cfg
  ../xz-utils/buildout.cfg
  ../zlib/buildout.cfg
  ../unixodbc/buildout.cfg
  ../zstd/buildout.cfg

parts =
  mariadb

[mariadb]
recipe = slapos.recipe.cmmi
shared = true
url = https://archive.mariadb.org//mariadb-${:version}/source/mariadb-${:version}.tar.gz
version = 10.4.28
md5sum = d098e9af77a26260a6a6c21a7ed0daf6
pre-configure =
  set '\bSET(PLUGIN_AUTH_PAM YES CACHE BOOL "")' cmake/build_configurations/mysql_release.cmake
  grep -q "$@"
  sed -i "/$1/d" "$2"
configure-command = ${cmake:location}/bin/cmake
configure-options =
  -DCMAKE_INSTALL_PREFIX=@@LOCATION@@
  -DBUILD_CONFIG=mysql_release
  -DDEFAULT_CHARSET=utf8
  -DDEFAULT_COLLATION=utf8_unicode_ci
  -DWITH_SSL=system
  -DWITH_ZLIB=system
  -DWITH_READLINE=0
  -DWITH_PIC=1
  -DWITH_PCRE=system
  -DENABLE_DTRACE=0
  -DWITH_EXTRA_CHARSETS=complex
  -DWITH_EMBEDDED_SERVER=0
  -DWITH_JEMALLOC=yes
  -DWITH_INNODB_BZIP2=ON
  -DWITH_INNODB_LZ4=ON
  -DWITH_INNODB_LZMA=ON
  -DWITH_INNODB_SNAPPY=ON
  -DWITH_ROCKSDB_LZ4=ON
  -DWITH_ROCKSDB_snappy=ON
  -DWITH_ROCKSDB_ZSTD=ON
  -DWITH_SAFEMALLOC=OFF
# TokuDB is removed in 10.6
  -DWITHOUT_TOKUDB=true
  -DPLUGIN_DAEMON_EXAMPLE=NO
  -DPLUGIN_EXAMPLE=NO
  -DPLUGIN_MROONGA=NO
  -DCMAKE_C_FLAGS="${:CMAKE_CFLAGS}"
  -DCMAKE_CXX_FLAGS="${:CMAKE_CFLAGS}"
  -DCMAKE_INSTALL_RPATH=${:CMAKE_LIBRARY_PATH}
  -DCMAKE_INCLUDE_PATH=${unixodbc:location}/include
  -DCMAKE_LIBRARY_PATH=${unixodbc:location}/lib
# for RocksDB - see
#  https://lore.kernel.org/linux-btrfs/ed3642c2-682e-08a1-f18d-2d63409b7631@nexedi.com/T/
  -DWITH_FALLOCATE=NO
##
CMAKE_CFLAGS = -I${bzip2:location}/include -I${jemalloc:location}/include -I${libaio:location}/include -I${libxml2:location}/include -I${ncurses:location}/include -I${openssl:location}/include -I${pcre:location}/include -I${readline5:location}/include -I${xz-utils:location}/include -I${zlib:location}/include -I${unixodbc:location}/include -I${lz4:location}/include -I${snappy:location}/include -I${zstd:location}/include
CMAKE_LIBRARY_PATH = ${bzip2:location}/lib:${jemalloc:location}/lib:${libaio:location}/lib:${libxml2:location}/lib:${ncurses:location}/lib:${openssl:location}/lib:${pcre:location}/lib:${readline5:location}/lib:${xz-utils:location}/lib:${zlib:location}/lib:${unixodbc:location}/lib:${lz4:location}/lib:${snappy:location}/lib:${zstd:location}/lib
environment =
  CMAKE_PROGRAM_PATH=${cmake:location}/bin
  CMAKE_INCLUDE_PATH=${bzip2:location}/include:${libaio:location}/include:${libaio:location}/include:${libxml2:location}/include:${ncurses:location}/include:${openssl:location}/include:${pcre:location}/include:${readline5:location}/include:${xz-utils:location}/include:${zlib:location}/include:${unixodbc:location}/include:${lz4:location}/include:${snappy:location}/include:${zstd:location}/include
  CMAKE_LIBRARY_PATH=${:CMAKE_LIBRARY_PATH}
  LDFLAGS=-L${bzip2:location}/lib -L${jemalloc:location}/lib -L${libaio:location}/lib -L${pcre:location}/lib -L${xz-utils:location}/lib -L${zlib:location}/lib -L${unixodbc:location}/lib -L${lz4:location}/lib -L${snappy:location}/lib -L${zstd:location}/lib
  PATH=${patch:location}/bin:%(PATH)s
patch-options = -p1
patches =
  https://sources.debian.org/data/main/m/mariadb-10.3/1:10.3.34-0+deb10u1/debian/patches/0024-Revert-to-using-system-pcre-library.patch#1c6a0f2634f5a56122299674b77b1131
post-install =
  ldd=`ldd %(location)s/lib/plugin/ha_rocksdb.so`
  for x in ${lz4:location} ${snappy:location} ${zstd:location}
  do echo "$ldd" |grep -qF " $x/lib/"
  done
  set -- wsrep-lib/wsrep-API/*/wsrep_api.h
  install -DpT $1 %(location)s/$1
  cp -a wsrep-lib/include %(location)s/wsrep-lib

[mroonga-mariadb]
# mroonga - a storage engine for MySQL. It provides fast fulltext search feature to all MySQL users.
# https://mroonga.org/
#
# To use mroonga, configure mariadb instance to use ${mroonga-mariadb:plugin-dir}
# as plugin-dir ( https://mariadb.com/kb/en/server-system-variables/#plugin_dir )
recipe = slapos.recipe.cmmi
shared = true
url = https://packages.groonga.org/source/mroonga/mroonga-13.01.tar.gz
md5sum = 062d9575fbf8759b529fdc46b077a9c1
pre-configure =
  rm -rf fake_mariadb_source
  mkdir -p fake_mariadb_source
  cd fake_mariadb_source
  ln -s ${mariadb:location}/wsrep-lib
  cp -a ${mariadb:location}/include/mysql/server include
  chmod -R u+w include  # so that buildout can delete this compile-dir after install
  mv include/private sql
  mkdir -p ${:plugin-dir}
configure-options =
  --with-mysql-source=fake_mariadb_source
  --with-mysql-config=${mariadb:location}/bin/mysql_config
  --disable-static
  --disable-document
post-install =
  cp -rs ${mariadb:location}/lib/plugin/* ${:plugin-dir}
plugin-dir = @@LOCATION@@/lib/plugin
install-sql = @@LOCATION@@/share/mroonga/install.sql
make-targets = plugindir=${:plugin-dir} install
patch-options = -p1
patches =
  ${:_profile_base_location_}/mroonga_boolean.patch#c818568fe35ca6a4298f18e575d962a0
environment =
  PATH=${binutils:location}/bin:${groonga:location}/bin:${patch:location}/bin:${pkgconfig:location}/bin:%(PATH)s
  CPPFLAGS=-I${groonga:location}/include/groonga -I${pcre:location}/include
  LDFLAGS=-L${groonga:location}/lib
  PKG_CONFIG_PATH=${groonga:location}/lib/pkgconfig:${groonga-normalizer-mysql:location}/lib/pkgconfig

