# Contributor: A. Wilcox <awilfox@adelielinux.org>
# Maintainer: A. Wilcox <awilfox@adelielinux.org>
pkgname=mariadb
pkgver=10.3.12
pkgrel=0
pkgdesc="Open source database server"
url="https://mariadb.org/"
arch="all"
options="!checkroot"  # Tests must be run as normal user.
license="GPL-2.0-only"
pkgusers="mysql"
pkggroups="mysql"
depends="$pkgname-common"
depends_dev="openssl-dev zlib-dev"
makedepends="$depends_dev byacc cmake curl-dev libarchive-dev libedit-dev
	libevent-dev libxml2-dev ncurses-dev pcre-dev xz-dev"
install="$pkgname.pre-install"
subpackages="$pkgname-doc $pkgname-openrc"
source="https://downloads.mariadb.org/interstitial/mariadb-$pkgver/source/mariadb-$pkgver.tar.gz
	mariadb.initd
	"

build() {
	cd "$builddir"
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_CXX_FLAGS="$CXXFLAGS -DNDEBUG" \
		-DCMAKE_C_FLAGS="$CFLAGS -DNDEBUG" \
		-DMYSQL_DATADIR="/var/lib/mysql" \
		-DSYSCONFDIR="/etc/mysql" \
		-DINSTALL_BINDIR=bin \
		-DINSTALL_DOCDIR=share/doc/$pkgname-$pkgver \
		-DINSTALL_DOCREADMEDIR=share/doc/$pkgname-$pkgver \
		-DINSTALL_INCLUDEDIR=include/mysql \
		-DINSTALL_LIBDIR=lib \
		-DINSTALL_MANDIR=share/man \
		-DINSTALL_MYSQLSHAREDIR=share/mariadb \
		-DINSTALL_PLUGINDIR=lib/mariadb/plugin \
		-DINSTALL_SCRIPTDIR=share/mariadb/scripts \
		-DINSTALL_MYSQLDATADIR="/var/lib/mysql" \
		-DINSTALL_SBINDIR=sbin \
		-DINSTALL_SUPPORTFILESDIR="/usr/share/mariadb" \
		-DWITH_COMMENT="${DISTRO_NAME:-Adélie Linux}" \
		-DWITH_UNIT_TESTS=ON \
		-DWITH_LIBEDIT=1 \
		-DWITH_ZLIB=system \
		-DWITHOUT_LIBWRAP=1 \
		-DENABLED_LOCAL_INFILE=1 \
		-DMYSQL_UNIX_ADDR="/var/run/mysqld/mysqld.sock" \
		-DINSTALL_UNIX_ADDRDIR="/var/run/mysqld/mysqld.sock" \
		-DWITH_DEFAULT_COMPILER_OPTIONS=0 \
		-DWITH_DEFAULT_FEATURE_SET=0 \
		-DPKG_CONFIG_EXECUTABLE="/usr/bin/pkgconf" \
		-DPLUGIN_AUTH_GSSAPI=NO \
		-DAUTH_GSSAPI_PLUGIN_TYPE=OFF \
		-DCONC_WITH_EXTERNAL_ZLIB=YES \
		-DWITH_EXTERNAL_ZLIB=YES \
		-DSUFFIX_INSTALL_DIR="" \
		-DWITH_UNITTEST=OFF \
		-DCONNECT_WITH_MYSQL=ON \
		-DCONNECT_WITH_LIBXML2=system \
		-DCONNECT_WITH_ODBC=NO \
		-DCONNECT_WITH_JDBC=NO \
		-DPLUGIN_ARCHIVE=YES \
		-DPLUGIN_ARIA=YES \
		-DPLUGIN_BLACKHOLE=YES \
		-DPLUGIN_CASSANDRA=NO \
		-DPLUGIN_CSV=YES \
		-DPLUGIN_MYISAM=YES \
		-DWITH_ASAN=OFF \
		-DWITH_EMBEDDED_SERVER=ON \
		-DWITH_INNODB_BZIP2=OFF \
		-DWITH_INNODB_LZ4=OFF \
		-DWITH_INNODB_LZMA=ON \
		-DWITH_INNODB_LZO=OFF \
		-DWITH_INNODB_SNAPPY=OFF \
		-DWITH_JEMALLOC=NO \
		-DWITH_LIBARCHIVE=system \
		-DWITH_LIBNUMA=NO \
		-DWITH_LIBWRAP=OFF \
		-DWITH_LIBWSEP=OFF \
		-DWITH_MARIABACKUP=ON \
		-DWITH_PCRE=system \
		-DWITH_SYSTEMD=no \
		-DWITH_SSL=system \
		-DWITH_VALGRIND=OFF \
		-DWITH_ZLIB=system \
		-DSKIP_TESTS=ON
		${CMAKE_CROSSOPTS}
	make
}

check() {
	cd "$builddir"
	CTEST_OUTPUT_ON_FAILURE=TRUE ctest
}

package() {
	cd "$builddir"
	make DESTDIR="$pkgdir" install
	install -m644 -D "$srcdir"/mariadb.initd "$pkgdir"/etc/init.d/mariadb
	rm -r "$pkgdir"/usr/mysql-test
}

sha512sums="9dd2939684c4591db306be6afb34663626dfaae133f88dd31125c759dce16b9e9d767a9254e30d9ee5fa2ea027e223dd4799effba8a8b0e4638d5de9e2512003  mariadb-10.3.12.tar.gz
06751768cb00d2e433655635c38d267ef25084a5830ff40e719ac579223c7192dc34b43f919ab6faf480094632327511cbd22456064dde2d04dc15648b9e3b9f  mariadb.initd"