app=mariadb
version=10.6.7
build=1sml
homepage="http://mariadb.org/"
download="https://archive.mariadb.org/mariadb-10.6.7/source/mariadb-10.6.7.tar.gz"
desc="Drop-in replacement for the MySQL Database Server"
requires="libxml2 zstd bzip2 cmake openssl zlib libaio netbsd-curses gcc-libs"

build() {
  mkandenterbuilddir
  rm -rf $app-$version

  tar xf $srcdir/$app-$version.tar.?z*
  cd $app-$version 
  fixbuilddirpermissions

  unset CFLAGS CXXFLAGS

  mkdir -p smbuild && cd smbuild
  cmake .. \
    -DCMAKE_BUILD_TYPE=MinSizeRel \
    -DCMAKE_INSTALL_PREFIX="/" \
    -DINSTALL_SBINDIR=bin \
    -DINSTALL_MANDIR=share/man \
    -DINSTALL_LAYOUT=STANDALONE \
    -DINSTALL_INCLUDEDIR=include/mysql \
    -DINSTALL_MYSQLSHAREDIR=share/mysql \
    -DINSTALL_PLUGINDIR=lib/mysql/plugin \
    -DINSTALL_SCRIPTDIR=bin \
    -DINSTALL_SUPPORTFILESDIR=share/mysql \
    -DINSTALL_MYSQLDATADIR=/var/lib/mysql \
    -DMYSQL_DATADIR="/var/lib/mysql" \
    -DMYSQL_UNIX_ADDR="/var/run/mysql/mysql.sock" \
    -DENABLED_LOCAL_INFILE=ON \
    -DWITH_SSL=system \
    -DWITH_ZLIB=system \
    -DWITH_EXTERNAL_ZLIB=ON \
    -DWITH_JEMALLOC=NO \
    -DSKIP_TESTS=ON \
    -DPLUGIN_MROONGA=NO \
    -DPLUGIN_AUTH_PAM=NO \
    -DPLUGIN_ROCKSDB=NO \
    -DWITH_WSREP=NO \
    -DWITH_READLINE=ON \
    -DWITH_INNODB_LZ4=OFF \
    -DDEFAULT_CHARSET=utf8mb4 \
    -DDEFAULT_COLLATION=utf8mb4_general_ci \
    -DWITH_LIBARCHIVE=system \
    -DWITH_PCRE=system \
    -DWITH_INNOBASE_STORAGE_ENGINE=1 \
    -DTMPDIR=/var/tmp \
    -DCONNECT_WITH_MYSQL=ON \
    -DCONNECT_WITH_LIBXML2=system \
    -DPLUGIN_ARCHIVE=YES \
    -DPLUGIN_CSV=YES \
    -DWITH_SYSTEMD=no 


  # Am sure there must be a better way to do it, but for now it works
  sed -i 's@-lcurses@-lcurses -lterminfo@g' client/CMakeFiles/mariadb.dir/link.txt

  make
  make install DESTDIR=$pkg 

  mv $pkg/COPYING $pkgdocs/
  rm $pkg/{README-wsrep,CREDITS,README.md,INSTALL-BINARY,THIRDPARTY}

  cd ..

  install -Dm 644 support-files/rpm/my.cnf $pkg/etc/my.cnf.new
  for i in client mysql-clients server ; do
    install -Dm 644 support-files/rpm/$i.cnf $pkg/etc/my.cnf.d/$i.cnf.new
  done

  install -Dm 644 support-files/rpm/client.cnf $pkg/etc/my.cnf.d/client.cnf.new

  # Remove sql-bench and mysql-tests
  rm -rf $pkg/{sql-bench,mysql-test}

  # This is the directory where databases are stored
  mkdir -p $pkg/var/lib/mysql 
  chown mysql.mysql $pkg/var/lib/mysql
  chmod 0750 $pkg/var/lib/mysql

  # This is where the socket is stored 
  mkdir -p $pkg/var/run/mysql
  chown mysql.mysql $pkg/var/run/mysql
  chmod 0755 $pkg/var/run/mysql

  # Add the init script
  install -Dm 0755 $srcdir/rc.mysqld $pkg/etc/rc.d/rc.mysqld.new

  # Install mysqlaccess.conf
  install -m 644 scripts/mysqlaccess.conf $pkg/etc/mysqlaccess.conf.new

  mkfinalpkg
}

sha512sums="
2d26f56ea5f39b800a6f279c8411d4091b4f4d3acbf3ea1864068328d34a1437e7c46c08d3772009357fd89602e58f214266038e177c0a4fac914a5e5d01e3e6  mariadb-10.6.7.tar.gz
"
