# Template file for 'mariadb'
pkgname=mariadb
version=11.1.2
revision=2
build_style=cmake
build_helper=qemu
configure_args="-DBUILD_CONFIG=mysql_release
 -DMYSQL_DATADIR=/var/lib/mysql -DMYSQL_UNIX_ADDR=/run/mysqld/mysqld.sock
 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
 -DENABLED_LOCAL_INFILE=ON -DINSTALL_INFODIR=share/mysql/docs
 -DINSTALL_MANDIR=share/man -DINSTALL_PLUGINDIR=lib/mysql/plugin
 -DINSTALL_SCRIPTDIR=bin -DINSTALL_INCLUDEDIR=include/mysql
 -DINSTALL_DOCREADMEDIR=share/mysql -DINSTALL_SUPPORTFILESDIR=share/mysql
 -DINSTALL_MYSQLSHAREDIR=share/mysql -DINSTALL_DOCDIR=share/mysql/docs
 -DINSTALL_SHAREDIR=share/mysql -DSTACK_DIRECTION=1
 -DWITH_ZLIB=system -DWITH_SSL=system  -DWITH_LIBARCHIVE=system
 -DWITH_EMBEDDED_SERVER=ON -DPLUGIN_TOKUDB=NO -DPLUGIN_BLACKHOLE=YES
 -DPLUGIN_PARTITION=YES -DWITH_EXTRA_CHARSETS=complex -DWITH_LIBWRAP=OFF
 -DWITH_READLINE=ON -DWITH_SYSTEMD=no -DWITH_PCRE=system"
hostmakedepends="bison perl flex pkg-config"
makedepends="ncurses-devel gnutls-devel libaio-devel boost-headers pam-devel zlib-devel
 pcre2-devel fmt-devel"
depends="perl"
checkdepends="perl"
short_desc="Fast SQL database server, drop-in replacement for MySQL"
maintainer="Orphaned <orphan@voidlinux.org>"
license="GPL-2.0-only"
homepage="https://mariadb.com"
distfiles="https://archive.mariadb.org/mariadb-${version}/source/mariadb-${version}.tar.gz"
checksum=19a9e980e57fa332931f643b48ad7390528c889ff6ea8b0e16fd306aa3088238
lib32disabled=yes
provides="mysql-${version}_${revision}"
replaces="mysql>=0"
system_accounts="mysql"
mysql_homedir="/var/lib/mysql"
make_dirs="/var/lib/mysql 0700 mysql mysql
 /usr/lib/mysql/plugin/auth_pam_tool_dir 0700 mysql root"
CFLAGS="-UNDEBUG -D_LARGEFILE64_SOURCE"
CXXFLAGS="-UNDEBUG -D_LARGEFILE64_SOURCE"

if [ "$XBPS_TARGET_LIBC" = "glibc" ]; then
	makedepends+=" libxcrypt-devel"
fi

if [ "$XBPS_CHECK_PKGS" ]; then
	configure_args+=" -DWITH_UNIT_TESTS=ON"
else
	configure_args+=" -DWITH_UNIT_TESTS=OFF"
fi

do_check() {
	cd build
	if [ "$XBPS_CHECK_PKGS" = full ]; then
		if [ ! "$CROSS_BUILD" ]; then
			mem="--mem"
		fi
		vtargetrun ${XBPS_CROSS_BASE}/usr/bin/perl mysql-test/mtr --parallel=${XBPS_MAKEJOBS} ${mem} --force --max-test-fail=40
	else
		ctest -E "(conc336|bulk1|performance|basic-t|fetch|charset|logs|cursor|errors|view|ps|ps_bugs|sp|result|connection|misc|ps_new|thread|features-10_2|async|test-connect)"
	fi
}

post_install() {
	# Remove unneeded stuff.
	rm -rf ${DESTDIR}/usr/{sql-bench,mariadb-test,data}
	rm -f ${DESTDIR}/usr/share/man/man1/mysql-test-run.pl.1
	rm -f ${DESTDIR}/usr/bin/mytop

	vmkdir usr/lib/security
	vmkdir etc/security
	mv ${DESTDIR}/usr/share/pam_user_map.so ${DESTDIR}/usr/lib/security/
	mv ${DESTDIR}/usr/share/user_map.conf ${DESTDIR}/etc/security/

	vsv mysqld
}

libmariadbclient_package() {
	short_desc+=" - client library"
	provides="libmysqlclient-${version}_${revision}"
	replaces="libmysqlclient>=0"
	pkg_install() {
		vmove "usr/lib/libmariadb*.so.*"
	}
}

libmariadbclient-devel_package() {
	depends="libmariadbclient>=${version}_${revision}"
	provides="libmysqlclient-devel-${version}_${revision}"
	replaces="libmysqlclient-devel>=0"
	short_desc+=" - client development files"
	pkg_install() {
		vmove usr/bin/mysql_config
		vmove usr/share/man/man1/mysql_config.1
		vmove usr/include
		vmove "usr/lib/*.a"
		vmove "usr/lib/*.so"
	}
}

mariadb-client_package() {
	metapackage=yes
	depends="mariadb"
	provides="mysql-client-${version}_${revision}"
	replaces="mysql-client>=0"
	short_desc+=" - client binaries (transitional dummy package)"
}

libmysqlclient_package() {
	metapackage=yes
	depends="libmariadbclient"
	short_desc="MySQL - (transitional dummy package)"
}

libmysqlclient-devel_package() {
	metapackage=yes
	depends="libmariadbclient-devel"
	short_desc="MySQL - (transitional dummy package)"
}

mysql-client_package() {
	metapackage=yes
	depends="mariadb"
	short_desc="MySQL - (transitional dummy package)"
}

mysql_package() {
	metapackage=yes
	depends="mariadb"
	short_desc="MySQL - (transitional dummy package)"
}
