# $NetBSD: Makefile.common,v 1.7 2015/06/22 15:16:24 jperkin Exp $
#
# used by databases/mysql-cluster/Makefile

DISTNAME=	mysql-cluster-gpl-7.4.6
CATEGORIES=	databases
MASTER_SITES=	${MASTER_SITE_MYSQL:=MySQL-Cluster-7.4/}

MAINTAINER?=	pkgsrc-users@NetBSD.org
HOMEPAGE=	http://www.mysql.com/products/cluster/
LICENSE=	gnu-gpl-v2

USE_CMAKE=		yes
USE_LANGUAGES=		c c++
USE_TOOLS+=		bash gmake perl:run python:run

.include "../../mk/bsd.prefs.mk"

.include "options.mk"

# MYSQL_USER		username of the database administrator
# MYSQL_GROUP		group of the database administrator
# MYSQL_DATADIR		home directory (location of the databases)
# MYSQL_PIDFILE		process ID file
# MYSQL_CHARSET		default character set
# MYSQL_EXTRA_CHARSET	additional character set to be compiled in
MYSQL_USER?=		mysql
MYSQL_GROUP?=		mysql
MYSQL_DATADIR?=		${VARBASE}/mysql
MYSQL_PIDFILE?=		${MYSQL_DATADIR}/${HOST}.pid
MYSQL_CHARSET?=		latin1
MYSQL_COLLATION?=	latin1_swedish_ci
MYSQL_EXTRA_CHARSET?=	all

PKG_USERS_VARS+=	MYSQL_USER
PKG_GROUPS_VARS+=	MYSQL_GROUP

CONFIG_SHELL=		${TOOLS_PATH.bash}

.if ${OPSYS} == "IRIX"
CFLAGS+=		-DIRIX5 -DNEEDS_BSTRING_H
.endif

BUILD_DEFS+=		VARBASE

# paths
CMAKE_ARGS+=		-DINSTALL_DOCDIR="share/doc/mysql"
CMAKE_ARGS+=		-DINSTALL_DOCREADMEDIR="share/doc/mysql"
CMAKE_ARGS+=		-DINSTALL_INCLUDEDIR="include/mysql"
CMAKE_ARGS+=		-DINSTALL_INFODIR="info"
CMAKE_ARGS+=		-DINSTALL_MANDIR="${PKGMANDIR}"
CMAKE_ARGS+=		-DINSTALL_MYSQLSHAREDIR="share/mysql"
CMAKE_ARGS+=		-DINSTALL_MYSQLTESTDIR="share/mysql/test"
CMAKE_ARGS+=		-DINSTALL_PLUGINDIR="lib/mysql/plugin"
CMAKE_ARGS+=		-DINSTALL_SBINDIR="sbin"
CMAKE_ARGS+=		-DINSTALL_SCRIPTDIR="bin"
CMAKE_ARGS+=		-DINSTALL_SQLBENCHDIR="share/mysql/sql-bench"
CMAKE_ARGS+=		-DINSTALL_SUPPORTFILESDIR="share/mysql"
CMAKE_ARGS+=		-DMYSQL_DATADIR=${MYSQL_DATADIR}

CMAKE_ARGS+=		-DWITH_LIBEVENT="system"
CMAKE_ARGS+=		-DWITH_BUNDLED_LIBEVENT=OFF
CMAKE_ARGS+=		-DWITH_ZLIB="system"
CMAKE_ARGS+=		-DDEFAULT_CHARSET=${MYSQL_CHARSET:Q}
CMAKE_ARGS+=		-DDEFAULT_COLLATION=${MYSQL_COLLATION:Q}
CMAKE_ARGS+=		-DWITH_EXTRA_CHARSETS=${MYSQL_EXTRA_CHARSET:Q}
CMAKE_ARGS+=		-DWITH_NDB_JAVA=OFF

# MySQL 5 depends on builtin functions enabled with i486 and later with GCC.
.if ${OPSYS} == "NetBSD" && !empty(MACHINE_ARCH:Mi386)
GNU_ARCH.i386=		i486
CFLAGS+=		-march=i486
.endif

# Ensure the correct DTrace ABI is used.
.if !empty(ABI)
CMAKE_ARGS+=		-DDTRACE_FLAGS="-${ABI}"
.endif

CPPFLAGS+=		-Dunix
CFLAGS+=		-D__STDC_FORMAT_MACROS=1 # always defined too late

.if ${OPSYS} != "Interix"
CFLAGS+=		-fPIC -DPIC
CXXFLAGS+=		-fPIC -DPIC
.endif

# force HAVE_CURSES_H on Solaris since the configure script is broken
# and does not properly detect this, breaking the build later on.  Also
# explicitly disable epoll support as it is Linux-specific.
.if ${OPSYS} == "SunOS"
CMAKE_ARGS+=		-DHAVE_SYS_EPOLL_H=NO -DHAVE_EPOLL_CREATE=NO
CFLAGS+=		-DHAVE_CURSES_H
CXXFLAGS+=		-DHAVE_CURSES_H
.endif

.include "../../mk/pthread.buildlink3.mk"

.if defined(PTHREAD_TYPE) && (${PTHREAD_TYPE} == "pth")
CFLAGS+=		-DSIGNALS_DONT_BREAK_READ
CXXFLAGS+=		-DSIGNALS_DONT_BREAK_READ
.endif

LDFLAGS+=		${COMPILER_RPATH_FLAG}${PREFIX}/lib/mysql

SUBST_CLASSES+=		scr
SUBST_STAGE.scr=	pre-configure
SUBST_FILES.scr=	scripts/mysql_install_db.sh scripts/mysqld_safe.sh \
			scripts/mysql_secure_installation.sh \
			support-files/mysql.server.sh
SUBST_SED.scr=		-e "s,chown,${CHOWN},g"
SUBST_SED.scr+=		-e "s,/bin/sh,${RCD_SCRIPTS_SHELL},g"
SUBST_MESSAGE.scr=	Fixing scripts.

SUBST_CLASSES+=		vars
SUBST_STAGE.vars=	pre-configure
SUBST_FILES.vars=	scripts/mysql_install_db.pl.in
SUBST_VARS.vars=	PKG_SYSCONFDIR

SUBST_CLASSES+=		fixpaths
SUBST_STAGE.fixpaths=	post-install
SUBST_FILES.fixpaths=	${DESTDIR}${PREFIX}/bin/mysqlbug
SUBST_FILES.fixpaths+=	${DESTDIR}${PREFIX}/share/doc/mysql/INFO_BIN
SUBST_SED.fixpaths=	-e "s,${WRAPPER_BINDIR}/gcc,${CCPATH},g"
SUBST_SED.fixpaths+=	-e "s,${WRAPPER_BINDIR}/g++,${CXXPATH},g"

.if ${_OPSYS_SHLIB_TYPE} == "dylib"
SOEXT="dylib"
.else
SOEXT="so"
.endif

CMAKE_ARGS+=	-DWITH_EDITLINE=system
CMAKE_ARGS+=	-DEDITLINE_LIBRARY=${BUILDLINK_PREFIX.editline}/lib/libedit.${SOEXT}
CMAKE_ARGS+=	-DEDITLINE_INCLUDE_DIR=${BUILDLINK_PREFIX.editline}/include/readline

.include "../../devel/editline/buildlink3.mk"
.include "../../devel/libevent/buildlink3.mk"
.include "../../devel/zlib/buildlink3.mk"
