SUMMARY="MySQL database development files"
DESCRIPTION="C connector for MySQL. MySQL is a fast, stable and true multi-user, \
multi-threaded SQL database server. SQL (Structured Query Language) is the \
most popular database query language in the world. The main goals of MySQL \
are speed, robustness and ease of use."
HOMEPAGE="https://dev.mysql.com/downloads/connector/c/"
COPYRIGHT="1997-2015 Oracle and/or its affiliates"
LICENSE="GNU GPL v2"
REVISION="3"
SOURCE_URI="http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-6.1.6-src.tar.gz"
CHECKSUM_SHA256="2222433012c415871958b61bc4f3683e1ebe77e3389f698b267058c12533ea78"
SOURCE_DIR="mysql-connector-c-6.1.6-src"
PATCHES="libmysqlclient-6.1.6.patchset"

ARCHITECTURES="all !x86_gcc2"
SECONDARY_ARCHITECTURES="x86"

libVersion="18.3.0"
libVersionCompat="$libVersion compat >= ${libVersion%.*}"

PROVIDES="
	libmysqlclient$secondaryArchSuffix = $portVersion
	lib:libmysqlclient$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

PROVIDES_devel="
	libmysqlclient${secondaryArchSuffix}_devel = $portVersion
	cmd:mysql_config$secondaryArchSuffix
	devel:libmysqlclient$secondaryArchSuffix = $libVersionCompat
	devel:libmysqlclient_r$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	libmysqlclient$secondaryArchSuffix == $portVersion base
	"

PROVIDES_tools="
	libmysqlclient${secondaryArchSuffix}_tools = $portVersion
	cmd:my_print_defaults$secondaryArchSuffix
	cmd:perror$secondaryArchSuffix
	"
REQUIRES_tools="
	haiku$secondaryArchSuffix
	libmysqlclient$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:make
	"

defineDebugInfoPackage libmysqlclient$secondaryArchSuffix \
	$libDir/libmysqlclient.so.$libVersion \
	"$(getPackagePrefix tools)/$relativeBinDir"/perror \
	"$(getPackagePrefix tools)/$relativeBinDir"/my_print_defaults

BUILD()
{
	cmake . -DCMAKE_INSTALL_PREFIX=$prefix -DINSTALL_BINDIR=$relativeBinDir \
		-DINSTALL_INCLUDEDIR=$relativeIncludeDir -DINSTALL_LIBDIR=$relativeLibDir \
		-DINSTALL_MANDIR=$relativeManDir -DINSTALL_SHAREDIR=$relativeDataDir \
		-DINSTALL_MYSQLDATADIR=$relativeDataDir -DINSTALL_MYSQLSHAREDIR=$relativeDataDir \
		-DWITH_EXTRA_CHARSETS=all -DCOMPILATION_COMMENT="Haiku" \
		-DSYSTEM_TYPE="Haiku"
	make $jobArgs
}

INSTALL()
{
	make install
	mkdir -p $developLibDir
	mv $libDir/libmysqlclient_r.a $developLibDir

	prepareInstalledDevelLibs libmysqlclient libmysqlclient_r

	packageEntries devel $developDir \
		$binDir/mysql_config

	packageEntries tools \
		$binDir/my_print_defaults \
		$binDir/perror

	rm $prefix/COPYING
	rm $prefix/README
	rm -rf $prefix/docs
}
