From b91c26a0b8a75a113096d71933dd0cdb7fcee373 Mon Sep 17 00:00:00 2001
From: geos_one <geos_one@6952d904-891a-0410-993b-d76249ca496b>
Date: Wed, 23 Dec 2009 16:15:48 +0000
Subject: [PATCH] updated eclass for storage handling

git-svn-id: https://svn.disconnected-by-peer.at/svn/linamh/trunk/mysql@1729 6952d904-891a-0410-993b-d76249ca496b
---
 eclass/mysql.eclass    | 361 +++++++++++++++++++++++++++++++----------
 eclass/mysql_fx.eclass | 211 ------------------------
 2 files changed, 272 insertions(+), 300 deletions(-)
 delete mode 100644 eclass/mysql_fx.eclass

diff --git a/eclass/mysql.eclass b/eclass/mysql.eclass
index 4578684..436e29a 100644
--- a/eclass/mysql.eclass
+++ b/eclass/mysql.eclass
@@ -1,17 +1,47 @@
-# Copyright 1999-2007 Gentoo Foundation
+# Copyright 1999-2009 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo-x86/eclass/mysql.eclass,v 1.109 2009/02/28 10:51:57 robbat2 Exp $
+# $Header: /var/cvsroot/gentoo-x86/eclass/mysql.eclass,v 1.121 2009/12/09 18:54:05 robbat2 Exp $
 
+# @ECLASS: mysql.eclass
+# @MAINTAINER:
 # Author: Francesco Riosa (Retired) <vivo@gentoo.org>
-# Maintainer: MySQL Team <mysql-bugs@gentoo.org>
+# Maintainers: MySQL Team <mysql-bugs@gentoo.org>
 #		- Luca Longinotti <chtekk@gentoo.org>
 #		- Robin H. Johnson <robbat2@gentoo.org>
+# @BLURB: This eclass provides most of the functions for mysql ebuilds
+# @DESCRIPTION:
+# The mysql.eclass provides almost all the code to build the mysql ebuilds
+# including the src_unpack, src_prepare, src_configure, src_compile,
+# scr_install, pkg_preinst, pkg_postinst, pkg_config and pkg_postrm
+# phase hooks.
 
 WANT_AUTOCONF="latest"
 WANT_AUTOMAKE="latest"
 
 inherit eutils flag-o-matic gnuconfig autotools mysql_fx versionator
 
+case "${EAPI:-0}" in
+	2)
+		EXPORT_FUNCTIONS pkg_setup \
+					src_unpack src_prepare \
+					src_configure src_compile \
+					src_install \
+					pkg_preinst pkg_postinst \
+					pkg_config pkg_postrm
+		IUSE_DEFAULT_ON='+'
+		;;
+	0 | 1)
+		EXPORT_FUNCTIONS pkg_setup \
+					src_unpack \
+					src_compile \
+					src_install \
+					pkg_preinst pkg_postinst \
+					pkg_config pkg_postrm
+		;;
+	*)
+		die "Unsupported EAPI: ${EAPI}" ;;
+esac
+
 # Shorten the path because the socket path length must be shorter than 107 chars
 # and we will run a mysql server during test phase
 S="${WORKDIR}/mysql"
@@ -19,10 +49,12 @@ S="${WORKDIR}/mysql"
 [[ "${MY_EXTRAS_VER}" == "latest" ]] && MY_EXTRAS_VER="20090228-0714Z"
 if [[ "${MY_EXTRAS_VER}" == "live" ]]; then
 	EGIT_PROJECT=mysql-extras
-	EGIT_REPO_URI="git://git.mars.arge.at/mysql-extras.git"
+	EGIT_REPO_URI="git://git.overlays.gentoo.org/proj/mysql-extras.git"
 	inherit git
 fi
 
+# @ECLASS-VARIABLE: MYSQL_VERSION_ID
+# @DESCRIPTION:
 # MYSQL_VERSION_ID will be:
 # major * 10e6 + minor * 10e4 + micro * 10e2 + gentoo revision number, all [0..99]
 # This is an important part, because many of the choices the MySQL ebuild will do
@@ -41,6 +73,34 @@ done
 # strip leading "0" (otherwise it's considered an octal number by BASH)
 MYSQL_VERSION_ID=${MYSQL_VERSION_ID##"0"}
 
+# @ECLASS-VARIABLE: MYSQL_COMMUNITY_FEATURES
+# @DESCRIPTION:
+# Specifiy if community features are available. Possible values are 1 (yes)
+# and 0 (no).
+# Community features are available in mysql-community
+# AND in the re-merged mysql-5.0.82 and newer
+if [ "${PN}" == "mysql-community" ]; then
+	MYSQL_COMMUNITY_FEATURES=1
+elif [ "${PV#5.0}" != "${PV}" ] && mysql_version_is_at_least "5.0.82"; then
+	MYSQL_COMMUNITY_FEATURES=1
+elif [ "${PV#5.1}" != "${PV}" ] && mysql_version_is_at_least "5.1.28"; then
+	MYSQL_COMMUNITY_FEATURES=1
+elif [ "${PV#5.4}" != "${PV}" ]; then
+	MYSQL_COMMUNITY_FEATURES=1
+else
+	MYSQL_COMMUNITY_FEATURES=0
+fi
+
+# @ECLASS-VARIABLE: XTRADB_VER
+# @DESCRIPTION:
+# Version of the XTRADB storage engine
+XTRADB_VER="${XTRADB_VER}"
+
+# @ECLASS-VARIABLE: PERCONA_VER
+# @DESCRIPTION:
+# Designation by PERCONA for a MySQL version to apply an XTRADB release
+PERCONA_VER="${PERCONA_VER}"
+
 # Be warned, *DEPEND are version-dependant
 # These are used for both runtime and compiletime
 DEPEND="ssl? ( >=dev-libs/openssl-0.9.6d )
@@ -51,7 +111,7 @@ DEPEND="ssl? ( >=dev-libs/openssl-0.9.6d )
 		>=sys-libs/zlib-1.2.3"
 
 # Having different flavours at the same time is not a good idea
-for i in "" "-community" "-mariadb" ; do
+for i in "" "-community" ; do
 	[[ "${i}" == ${PN#mysql} ]] ||
 	DEPEND="${DEPEND} !dev-db/mysql${i}"
 done
@@ -77,23 +137,22 @@ PDEPEND="${PDEPEND} =virtual/mysql-$(get_version_component_range 1-2 ${PV})"
 # Work out the default SERVER_URI correctly
 if [ -z "${SERVER_URI}" ]; then
 	# The community build is on the mirrors
-	if [ "${PN}" == "mysql" ]; then
+	if [ "${MYSQL_COMMUNITY_FEATURES}" == "1" ]; then
 		SERVER_URI="mirror://mysql/Downloads/MySQL-${PV%.*}/mysql-${PV//_/-}.tar.gz"
-	elif [ "${PN}" == "mysql-community" ]; then
-		SERVER_URI="mirror://mysql/Downloads/MySQL-${PV%.*}/mysql-${PV//_/-}.tar.gz"
-	# The maria source is on launchpad
-	elif [ "${PN}" == "mysql-mariadb" ]; then
-		SERVER_URI="http://launchpad.net/maria/${PV%.*}/ongoing/+download/mysql-${PV//_/-maria-}.tar.gz"
+	# The (old) enterprise source is on the primary site only
+	elif [ "${PN}" == "mysql" ]; then
+		SERVER_URI="ftp://ftp.mysql.com/pub/mysql/src/mysql-${PV//_/-}.tar.gz"
 	fi
 fi
 
 # Define correct SRC_URIs
 SRC_URI="${SERVER_URI}"
 
-[[ ${MY_EXTRAS_VER} != live ]] && SRC_URI="${SRC_URI}
+# Gentoo patches to MySQL
+[[ ${MY_EXTRAS_VER} != live ]] \
+&& SRC_URI="${SRC_URI}
 		mirror://gentoo/mysql-extras-${MY_EXTRAS_VER}.tar.bz2
-		http://g3nt8.org/patches/mysql-extras-${MY_EXTRAS_VER}.tar.bz2
-		http://ftp.mars.arge.at/mysql/mysql-extras-${MY_EXTRAS_VER}.tar.bz2"
+		http://g3nt8.org/patches/mysql-extras-${MY_EXTRAS_VER}.tar.bz2"
 
 for str in ${MYSQL_STORAGE} ; do
 	STORAGE_USE="${str/-*/}"
@@ -101,12 +160,11 @@ for str in ${MYSQL_STORAGE} ; do
 	STORAGE_IUSE="${STORAGE_IUSE} ${STORAGE_USE}"
 done
 
-
 DESCRIPTION="A fast, multi-threaded, multi-user SQL database server."
 HOMEPAGE="http://www.mysql.com/"
 LICENSE="GPL-2"
 SLOT="0"
-IUSE="big-tables debug embedded minimal perl selinux ssl static"
+IUSE="big-tables debug embedded minimal ${IUSE_DEFAULT_ON}perl selinux ssl static"
 
 mysql_version_is_at_least "4.1" \
 && IUSE="${IUSE} latin1"
@@ -123,20 +181,21 @@ mysql_version_is_at_least "5.0.18" \
 mysql_version_is_at_least "5.1" \
 || IUSE="${IUSE} berkdb"
 
-mysql_version_is_at_least "5.1.30" \
-&& IUSE="${IUSE} -static_mysqld -fast-mutexes"
+mysql_version_is_at_least "5.1.26" \
+|| IUSE="${IUSE} innodb xtradb"
 
-mysql_version_is_at_least "5.2" \
-&& IUSE="${IUSE} falcon"
+[ "${MYSQL_COMMUNITY_FEATURES}" == "1" ] \
+&& IUSE="${IUSE} ${IUSE_DEFAULT_ON}community profiling"
 
 IUSE="${IUSE} ${STORAGE_IUSE}"
-EXPORT_FUNCTIONS pkg_setup src_unpack src_compile src_install pkg_preinst \
-				pkg_postinst pkg_config pkg_postrm
 
 #
 # HELPER FUNCTIONS:
 #
 
+# @FUNCTION: mysql_disable_test
+# @DESCRIPTION:
+# Helper function to disable specific tests.
 mysql_disable_test() {
 	local testname="${1}" ; shift
 	local reason="${@}"
@@ -145,11 +204,11 @@ mysql_disable_test() {
 	ewarn "test '${testname}' disabled: '${reason}'"
 }
 
+# @FUNCTION: mysql_init_vars
+# @DESCRIPTION:
 # void mysql_init_vars()
-#
 # Initialize global variables
 # 2005-11-19 <vivo@gentoo.org>
-
 mysql_init_vars() {
 	MY_SHAREDSTATEDIR=${MY_SHAREDSTATEDIR="/usr/share/mysql"}
 	MY_SYSCONFDIR=${MY_SYSCONFDIR="/etc/mysql"}
@@ -187,6 +246,20 @@ mysql_init_vars() {
 			fi
 			export PREVIOUS_DATADIR
 		fi
+	else
+		if [[ ${EBUILD_PHASE} == "config" ]]; then
+			local new_MY_DATADIR
+			new_MY_DATADIR=`"my_print_defaults" mysqld 2>/dev/null \
+				| sed -ne '/datadir/s|^--datadir=||p' \
+				| tail -n1`
+
+			if [[ ( -n "${new_MY_DATADIR}" ) && ( "${new_MY_DATADIR}" != "${MY_DATADIR}" ) ]]; then
+				ewarn "MySQL MY_DATADIR has changed"
+				ewarn "from ${MY_DATADIR}"
+				ewarn "to ${new_MY_DATADIR}"
+				MY_DATADIR="${new_MY_DATADIR}"
+			fi
+		fi
 	fi
 
 	MY_SOURCEDIR=${SERVER_URI##*/}
@@ -341,8 +414,13 @@ configure_40_41_50() {
 		fi
 	fi
 
-	if [ "${PN}" == "mysql-community" ]; then
-		myconf="${myconf} --enable-community-features"
+	if [ "${MYSQL_COMMUNITY_FEATURES}" == "1" ]; then
+		myconf="${myconf} `use_enable community community-features`"
+		if use community; then
+			myconf="${myconf} `use_enable profiling`"
+		else
+			myconf="${myconf} --disable-profiling"
+		fi
 	fi
 
 	mysql_version_is_at_least "5.0.18" \
@@ -355,70 +433,62 @@ configure_51() {
 	# the failure depend upon config/ac-macros/readline.m4 checking into
 	# readline.h instead of history.h
 	myconf="${myconf} $(use_with ssl)"
-	myconf="${myconf} $(use_with fast-mutexes)"
 	myconf="${myconf} --enable-assembler"
 	myconf="${myconf} --with-geometry"
 	myconf="${myconf} --with-readline"
-	# myconf="${myconf} --with-row-based-replication"
+	myconf="${myconf} --with-row-based-replication"
 	myconf="${myconf} --with-zlib-dir=/usr"
 	myconf="${myconf} --without-pstack"
-	# myconf="${myconf} --with-innodb"
 	use max-idx-128 && myconf="${myconf} --with-max-indexes=128"
 
-	if ! use static && use static_mysqld ; then
-		# This causes seg11 crashes if LDAP is used for groups in /etc/nsswitch.conf
-		# so it is disabled by default although, according to MySQL, it brings >10%
-		# performance gain if enabled. See #299382.
-		myconf="${myconf} --with-mysqld-ldflags=-all-static"
-	fi
-
-	# 5.1 introduces a new way to manage storage engines (plugins)
+	# 5.1 introduces a new way to manage storage engines (#plugins)
 	# like configuration=none
 	local plugins="csv,myisam,myisammrg,heap"
 	if use extraengine ; then
 		# like configuration=max-no-ndb, archive and example removed in 5.1.11
-		[[ -d storage/archive ]] && plugins="${plugins},archive"
-		[[ -d storage/blackhole ]] && plugins="${plugins},blackhole"
-		[[ -d storage/example ]] && plugins="${plugins},example"
-		[[ -d storage/federated ]] && plugins="${plugins},federated"
-		[[ -d storage/partition ]] && plugins="${plugins},partition"
+		plugins="${plugins},archive,blackhole,example,federated,partition"
 
 		elog "Before using the Federated storage engine, please be sure to read"
 		elog "http://dev.mysql.com/doc/refman/5.1/en/federated-limitations.html"
 	fi
 
+	# Upstream specifically requests that InnoDB always be built.
 	plugins="${plugins},innobase"
 
 	# like configuration=max-no-ndb
 	if use cluster ; then
-		if use pbxt ; then
-			eerror "USE pbxt and cluster can't be activated at the same time"
-		else
-			[[ -d storage/ndb ]] && plugins="${plugins},ndb"
-			[[ ! -d storage/ndb ]] && eerror "use cluster but no ndb plugin"
-			# myconf="${myconf} --with-ndb-binlog"
-		fi
+		plugins="${plugins},ndbcluster"
+		myconf="${myconf} --with-ndb-binlog"
+	fi
+
+	if mysql_version_is_at_least "5.2" ; then
+		plugins="${plugins},falcon"
 	fi
 
 	for str in ${STORAGE_IUSE} ; do
-		#[[ ${str} = "xtradb" ]] && str="innobase"
 		if use ${str} ; then
+			# dotn confuse autoconf by specifiing the plugins to or more times
 			[[ -d storage/${str} ]] && plugins="${plugins},${str}"
+			# suppres error message
+			[[ ${str} = "innodb" ]] && str="innobase"
+			[[ ${str} = "xtradb" ]] && str="innobase"
 			[[ ! -d storage/${str} ]] && eerror "use ${str} but no ${str} plugin"
 		fi
 	done
 
-	if use falcon ; then
-		[[ -d storage/falcon ]] && plugins="${plugins},falcon"
-		[[ ! -d storage/falcon ]] && eerror "use falcon but no Falcon plugin"
-	fi
-
 	myconf="${myconf} --with-plugins=${plugins}"
 }
 
 #
 # EBUILD FUNCTIONS
 #
+# @FUNCTION: mysql_pkg_setup
+# @DESCRIPTION:
+# Perform some basic tests and tasks during pkg_setup phase:
+#   die if FEATURES="test", USE="-minimal" and not using FEATURES="userpriv"
+#   check for conflicting use flags
+#   create new user and group for mysql
+#   warn about deprecated features
 mysql_pkg_setup() {
 	if hasq test ${FEATURES} ; then
 		if ! use minimal ; then
@@ -458,18 +528,46 @@ mysql_pkg_setup() {
 	&& elog "Berkeley DB support is deprecated and will be removed in future versions!"
 }
 
+# @FUNCTION: mysql_src_unpack
+# @DESCRIPTION:
+# Unpack the source code and call mysql_src_prepare for EAPI < 2.
 mysql_src_unpack() {
 	# Initialize the proper variables first
 	mysql_init_vars
 
-	ln -sf "${MY_SOURCEDIR}" "${WORKDIR}/mysql-storage"
 	unpack ${A}
-	rm -f "${WORKDIR}/mysql-storage"
+
+	for str in ${MYSQL_STORAGE} ; do
+		storage_name="${str/-*/}"
+		if use ${storage_name} ; then
+			einfo "Moving ${str/-/ Storage Engine Version } in place"
+			pushd "${WORKDIR}/${MY_SOURCEDIR}"/storage
+			i="${WORKDIR}/mysql-storage-${str}"
+			o="${storage_name}"
+			# Have we been here already ? or are we updating the included engine !
+			[ -h "${o}" ] && rm -f "${o}"
+			# Or maybe we haven't
+			[ -d "${i}" -a ! -d "${o}" ] && cp -R  "${i}"/* "${WORKDIR}/${MY_SOURCEDIR}"
+			popd
+		fi
+	done
+
 	# Grab the patches
 	[[ "${MY_EXTRAS_VER}" == "live" ]] && S="${WORKDIR}/mysql-extras" git_src_unpack
-	
+
 	mv -f "${WORKDIR}/${MY_SOURCEDIR}" "${S}"
 
+	# Be backwards compatible for now
+	case ${EAPI:-0} in
+        	2) : ;;
+        	0 | 1) mysql_src_prepare ;;
+	esac
+}
+
+# @FUNCTION: mysql_src_prepare
+# @DESCRIPTION:
+# Apply patches to the source code and remove unneeded bundled libs.
+mysql_src_prepare() {
 	cd "${S}"
 
 	# Apply the patches for this MySQL version
@@ -487,26 +585,13 @@ mysql_src_unpack() {
 	sed -i -e "s/zlib\/Makefile dnl/dnl zlib\/Makefile/" "${S}/configure.in"
 	rm -f "scripts/mysqlbug"
 
-	 if use xtradb ; then
-		# xtradb and innobase & innodb_plugin can't exist at buildtime side by side
-		rm -rf "${S}/storage/innobase"
-		rm -rf "${S}/storage/innodb_plugin"
-		mv -f "${S}/storage/xtradb" "${S}/storage/innobase"
-	fi
-
-	 if use innodb ; then
-		# innodb and innobase & innodb_plugin can't exist at buildtime side by side
-		rm -rf "${S}/storage/innobase"
-		rm -rf "${S}/storage/innodb_plugin"
-		mv -f "${S}/storage/innodb" "${S}/storage/innobase"
-	fi
-
 	# Make charsets install in the right place
 	find . -name 'Makefile.am' \
 		-exec sed --in-place -e 's!$(pkgdatadir)!'${MY_SHAREDSTATEDIR}'!g' {} \;
 
 	if mysql_version_is_at_least "4.1" ; then
 		# Remove what needs to be recreated, so we're sure it's actually done
+		einfo "Cleaning up old buildscript files"
 		find . -name Makefile \
 			-o -name Makefile.in \
 			-o -name configure \
@@ -517,7 +602,52 @@ mysql_src_unpack() {
 
 	local rebuilddirlist d
 
+
+
+	if mysql_version_is_at_least "5.1.26" && use xtradb && use innodb ; then
+		eerror "Percona XtraDB and Innobase innoDB can not be insalled at the same time."
+	elif mysql_version_is_at_least "5.1.26" && use xtradb && ! use innodb ; then
+		einfo "Replacing InnoDB with Percona XtraDB"
+		einfo "Removing InnoDB Plugin Storage Engine"
+		pushd "${S}"/storage
+		# the innodb_plugin is a reason for compile errors if we replace innobase
+		i="innodb_plugin"
+		o="${WORKDIR}/storage-${i}.mysql-upstream"
+		# Have we been here already?
+		[ -h "${i}" ] && rm -f "${i}"
+		# Or maybe we haven't
+		[ -d "${i}" -a ! -d "${o}" ] && mv "${i}" "${o}"
+		i="innobase"
+		o="${WORKDIR}/storage-${i}.mysql-upstream"
+		# Have we been here already?
+		[ -h "${i}" ] && rm -f "${i}"
+		# Or maybe we haven't
+		[ -d "${i}" -a ! -d "${o}" ] && mv "${i}" "${o}"
+		mv -f "xtradb" "${i}"
+		popd
+	elif mysql_version_is_at_least "5.1.26" && use innodb && ! use xtradb ; then
+		einfo "Replacing InnoDB with Innobase innoDB"
+		einfo "Removing InnoDB Plugin Storage Engine"
+		pushd "${S}"/storage
+		# the innodb_plugin is a reason for compile errors if we replace innobase
+		i="innodb_plugin"
+		o="${WORKDIR}/storage-${i}.mysql-upstream"
+		# Have we been here already?
+		[ -h "${i}" ] && rm -f "${i}"
+		# Or maybe we haven't
+		[ -d "${i}" -a ! -d "${o}" ] && mv "${i}" "${o}"
+		i="innobase"
+		o="${WORKDIR}/storage-${i}.mysql-upstream"
+		# Have we been here already?
+		[ -h "${i}" ] && rm -f "${i}"
+		# Or maybe we haven't
+		[ -d "${i}" -a ! -d "${o}" ] && mv "${i}" "${o}"
+		mv -f "innodb" "${i}"
+		popd
+	fi
+
 	if mysql_version_is_at_least "5.1.12" ; then
+		einfo "Updating innobase cmake"
 		rebuilddirlist="."
 		# TODO: check this with a cmake expert
 		cmake \
@@ -537,6 +667,7 @@ mysql_src_unpack() {
 
 	if mysql_check_version_range "4.1 to 5.0.99.99" \
 	&& use berkdb ; then
+		einfo "Fixing up berkdb buildsystem"
 		[[ -w "bdb/dist/ltmain.sh" ]] && cp -f "ltmain.sh" "bdb/dist/ltmain.sh"
 		cp -f "/usr/share/aclocal/libtool.m4" "bdb/dist/aclocal/libtool.ac" \
 		|| die "Could not copy libtool.m4 to bdb/dist/"
@@ -554,7 +685,10 @@ mysql_src_unpack() {
 	fi
 }
 
-mysql_src_compile() {
+# @FUNCTION: mysql_src_configure
+# @DESCRIPTION:
+# Configure mysql to build the code for Gentoo respecting the use flags.
+mysql_src_configure() {
 	# Make sure the vars are correctly initialized
 	mysql_init_vars
 
@@ -588,15 +722,10 @@ mysql_src_compile() {
 	CXXFLAGS="${CXXFLAGS} -felide-constructors -fno-rtti"
 	mysql_version_is_at_least "5.0" \
 	&& CXXFLAGS="${CXXFLAGS} -fno-implicit-templates"
-	mysql_version_is_at_least "5.1.32" \
-	&& CXXFLAGS="${CXXFLAGS} -DBIG_JOINS=1"
-	# Force pic on amd64
-	if use amd64 ; then
-		CFLAGS="${CFLAGS} -fPIC"
-		CXXFLAGS="${CXXFLAGS} -fPIC"
-		myconf="${myconf} --with-pic --with-lib-ccflags=-fPIC"
-	fi
-	export CFLAGS CXXFLAGS
+	export CXXFLAGS
+
+	# bug #283926, with GCC4.4, this is required to get correct behavior.
+	append-flags -fno-strict-aliasing
 
 	econf \
 		--libexecdir="/usr/sbin" \
@@ -616,11 +745,24 @@ mysql_src_compile() {
 	find . -type f -name Makefile -print0 \
 	| xargs -0 -n100 sed -i \
 	-e 's|^pkglibdir *= *$(libdir)/mysql|pkglibdir = $(libdir)|;s|^pkgincludedir *= *$(includedir)/mysql|pkgincludedir = $(includedir)|'
-
-	emake || die "emake failed"
-
 }
 
+# @FUNCTION: mysql_src_compile
+# @DESCRIPTION:
+# Compile the mysql code.
+mysql_src_compile() {
+	# Be backwards compatible for now
+        case ${EAPI:-0} in
+                2) : ;;
+                0 | 1) mysql_src_configure ;;
+        esac
+
+	emake || die "emake failed"
+}
+
+# @FUNCTION: mysql_src_install
+# @DESCRIPTION:
+# Install mysql.
 mysql_src_install() {
 	# Make sure the vars are correctly initialized
 	mysql_init_vars
@@ -714,11 +856,22 @@ mysql_src_install() {
 	mysql_lib_symlinks "${D}"
 }
 
+# @FUNCTION: mysql_pkg_preinst
+# @DESCRIPTION:
+# Create the user and groups for mysql - die if that fails.
 mysql_pkg_preinst() {
 	enewgroup mysql 60 || die "problem adding 'mysql' group"
 	enewuser mysql 60 -1 /dev/null mysql || die "problem adding 'mysql' user"
 }
 
+# @FUNCTION: mysql_pkg_postinst
+# @DESCRIPTION:
+# Run post-installation tasks:
+#   create the dir for logfiles if non-existant
+#   touch the logfiles and secure them
+#   install scripts
+#   issue required steps for optional features
+#   issue deprecation warnings
 mysql_pkg_postinst() {
 	# Make sure the vars are correctly initialized
 	mysql_init_vars
@@ -759,7 +912,12 @@ mysql_pkg_postinst() {
 	&& elog "Berkeley DB support is deprecated and will be removed in future versions!"
 }
 
+# @FUNCTION: mysql_pkg_config
+# @DESCRIPTION:
+# Configure mysql environment.
 mysql_pkg_config() {
+	local old_MY_DATADIR="${MY_DATADIR}"
+
 	# Make sure the vars are correctly initialized
 	mysql_init_vars
 
@@ -769,6 +927,30 @@ mysql_pkg_config() {
 		die "Minimal builds do NOT include the MySQL server"
 	fi
 
+	if [[ ( -n "${MY_DATADIR}" ) && ( "${MY_DATADIR}" != "${old_MY_DATADIR}" ) ]]; then
+		local MY_DATADIR_s="$(strip_duplicate_slashes ${ROOT}/${MY_DATADIR})"
+		local old_MY_DATADIR_s="$(strip_duplicate_slashes ${ROOT}/${old_MY_DATADIR})"
+
+		if [[ -d "${old_MY_DATADIR_s}" ]]; then
+			if [[ -d "${MY_DATADIR_s}" ]]; then
+				ewarn "Both ${old_MY_DATADIR_s} and ${MY_DATADIR_s} exist"
+				ewarn "Attempting to use ${MY_DATADIR_s} and preserving ${old_MY_DATADIR_s}"
+			else
+				elog "Moving MY_DATADIR from ${old_MY_DATADIR_s} to ${MY_DATADIR_s}"
+				mv --strip-trailing-slashes -T "${old_MY_DATADIR_s}" "${MY_DATADIR_s}" \
+				|| die "Moving MY_DATADIR failed"
+			fi
+		else
+			ewarn "Previous MY_DATADIR (${old_MY_DATADIR_s}) does not exist"
+			if [[ -d "${MY_DATADIR_s}" ]]; then
+				ewarn "Attempting to use ${MY_DATADIR_s}"
+			else
+				eerror "New MY_DATADIR (${MY_DATADIR_s}) does not exist"
+				die "Configuration Failed!  Please reinstall ${CATEGORY}/${PN}"
+			fi
+		fi
+	fi
+
 	local pwd1="a"
 	local pwd2="b"
 	local maxtry=5
@@ -820,7 +1002,7 @@ mysql_pkg_config() {
 	chmod 0750 "${ROOT}/${MY_DATADIR}" 2>/dev/null
 
 	if mysql_version_is_at_least "4.1.3" ; then
-		use cluster && options="${options} --skip-ndbcluster"
+		options="--skip-ndbcluster"
 
 		# Filling timezones, see
 		# http://dev.mysql.com/doc/mysql/en/time-zone-support.html
@@ -830,9 +1012,6 @@ mysql_pkg_config() {
 			cat "${help_tables}" >> "${sqltmp}"
 		fi
 	fi
-	if mysql_check_version_range "4.1 to 5.0.99.99" && use berkdb ; then
-		options="${options} --skip-bdb"
-	fi
 
 	local socket="${ROOT}/var/run/mysqld/mysqld${RANDOM}.sock"
 	local pidfile="${ROOT}/var/run/mysqld/mysqld${RANDOM}.pid"
@@ -843,6 +1022,7 @@ mysql_pkg_config() {
 		--basedir=${ROOT}/usr \
 		--datadir=${ROOT}/${MY_DATADIR} \
 		--skip-innodb \
+		--skip-bdb \
 		--skip-networking \
 		--max_allowed_packet=8M \
 		--net_buffer_length=16K \
@@ -879,6 +1059,9 @@ mysql_pkg_config() {
 	einfo "Done"
 }
 
+# @FUNCTION: mysql_pkg_postrm
+# @DESCRIPTION:
+# Remove mysql symlinks.
 mysql_pkg_postrm() {
 	: # mysql_lib_symlinks "${D}"
 }
diff --git a/eclass/mysql_fx.eclass b/eclass/mysql_fx.eclass
deleted file mode 100644
index 2ee1100..0000000
--- a/eclass/mysql_fx.eclass
+++ /dev/null
@@ -1,211 +0,0 @@
-# Copyright 1999-2007 Gentoo Foundation
-# Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo-x86/eclass/mysql_fx.eclass,v 1.22 2009/02/12 05:05:14 robbat2 Exp $
-
-# Author: Francesco Riosa (Retired) <vivo@gentoo.org>
-# Maintainer: Luca Longinotti <chtekk@gentoo.org>
-
-inherit multilib
-
-#
-# Helper function, version (integer) may have sections separated by dots
-# for readability.
-#
-stripdots() {
-	local dotver=${1:-"0"}
-	local v=""
-	local ret=0
-	if [[ "${dotver/./}" != "${dotver}" ]] ; then
-		# dotted version number
-		for i in 1000000 10000 100 1 ; do
-			v=${dotver%%\.*}
-			# remove leading zeroes
-			while [[ ${#v} -gt 1 ]] && [[ ${v:0:1} == "0" ]] ; do v=${v#0} ; done
-			# increment integer version number
-			ret=$(( ${v} * ${i} + ${ret} ))
-			if [[ "${dotver}" == "${dotver/\.}" ]] ; then
-				dotver=0
-			else
-				dotver=${dotver#*\.}
-			fi
-		done
-		echo "${ret}"
-	else
-		# already an integer
-		v=${dotver}
-		while [[ ${#v} -gt 1 ]] && [[ ${v:0:1} == "0" ]] ; do v=${v#0} ; done
-		echo "${v}"
-	fi
-}
-
-#
-# Check if a version number falls inside a given range.
-# The range includes the extremes and must be specified as
-# "low_version to high_version" i.e. "4.1.2 to 5.1.99.99".
-# Returns true if inside the range.
-#
-mysql_check_version_range() {
-	local lbound="${1%% to *}" ; lbound=$(stripdots "${lbound}")
-	local rbound="${1#* to }"  ; rbound=$(stripdots "${rbound}")
-	local my_ver="${2:-"${MYSQL_VERSION_ID}"}"
-	[[ ${lbound} -le ${my_ver} ]] && [[ ${my_ver} -le ${rbound} ]] && return 0
-	return 1
-}
-
-#
-# True if at least one applicable range is found for the patch.
-#
-_mysql_test_patch_ver_pn() {
-	local allelements=", version, package name"
-	# So that it fails the directory test if none of them exist
-	local filesdir="/dev/null"
-	for d in "${WORKDIR}/mysql-extras-${MY_EXTRAS_VER}" \
-		"${WORKDIR}/mysql-extras" ; do
-		if [ -d "${d}" ]; then
-			filesdir="${d}"
-			break
-		fi
-	done
-
-	[[ -d "${filesdir}" ]] || die "Source dir must be a directory"
-	local flags=$1 pname=$2
-	if [[ $(( $flags & $(( 1 + 4 + 16 )) )) -eq 21 ]] ; then
-		einfo "using '${pname}'"
-		ln -sf "${filesdir}/${pname}" "${EPATCH_SOURCE}" || die "Couldn't move ${pname}"
-		return 0
-	fi
-
-	[[ $(( $flags & $(( 2 + 4 )) )) -gt 0 ]] \
-	&& allelements="${allelements//", version"}"
-
-	[[ $(( $flags & $(( 8 + 16 )) )) -gt 0 ]] \
-	&& allelements="${allelements//", package name"}"
-
-	[[ -n "${allelements}" ]] && [[ "${flags}" -gt 0 ]] \
-	&& ewarn "QA notice: ${allelements} missing in ${pname} patch"
-
-	return 1
-}
-
-#
-# Parse a "index_file" looking for patches to apply to the
-# current MySQL version.
-# If the patch applies, print its description.
-#
-mysql_mv_patches() {
-	# So that it fails the directory test if none of them exist
-	local filesdir="/dev/null"
-	if [[ -z "${1}" ]]; then
-		for d in "${WORKDIR}/mysql-extras-${MY_EXTRAS_VER}" \
-			"${WORKDIR}/mysql-extras" ; do
-			if [ -d "${d}" ]; then
-				filesdir="${d}"
-				break
-			fi
-		done
-		[[ -d "${filesdir}" ]] || die "No patches directory found!"
-	fi
-
-	for i in "$1" "${filesdir}/0000_index.txt" "${filesdir}/000_index.txt" ; do
-		if [ -n "$i" -a -f "$i" ]; then
-			local index_file="$i"
-			break
-		fi
-	done
-
-	local my_ver="${2:-"${MYSQL_VERSION_ID}"}"
-	local my_test_fx=${3:-"_mysql_test_patch_ver_pn"}
-	_mysql_mv_patches "${index_file}" "${my_ver}" "${my_test_fx}"
-}
-
-_mysql_mv_patches() {
-	local index_file="${1}"
-	local my_ver="${2}"
-	local my_test_fx="${3}"
-	local dsc ndsc=0 i
-	dsc=( )
-
-	# Values for flags are (2^x):
-	#  1 - one patch found
-	#  2 - at least one version range is wrong
-	#  4 - at least one version range is ok
-	#  8 - at least one ${PN} did not match
-	#  16 - at least one ${PN} has been matched
-	local flags=0 pname=""
-	while read row ; do
-		case "${row}" in
-			@patch\ *)
-				[[ -n "${pname}" ]] \
-				&& ${my_test_fx} ${flags} "${pname}" \
-				&& for (( i=0 ; $i < $ndsc ; i++ )) ; do einfo ">    ${dsc[$i]}" ; done
-				flags=1 ; ndsc=0 ; dsc=( )
-				pname=${row#"@patch "}
-				;;
-			@ver\ *)
-				if mysql_check_version_range "${row#"@ver "}" "${my_ver}" ; then
-					flags=$(( ${flags} | 4 ))
-				else
-					flags=$(( ${flags} | 2 ))
-				fi
-				;;
-			@pn\ *)
-				if [[ ${row#"@pn "} == "${PN}" ]] ; then
-					flags=$(( ${flags} | 16 ))
-				else
-					flags=$(( ${flags} | 8 ))
-				fi
-				;;
-			# @use\ *) ;;
-			@@\ *)
-				dsc[$ndsc]="${row#"@@ "}"
-				(( ++ndsc ))
-				;;
-		esac
-	done < "${index_file}"
-
-	${my_test_fx} ${flags} "${pname}" \
-	&& for (( i=0 ; $i < $ndsc ; i++ )) ; do einfo ">    ${dsc[$i]}" ; done
-}
-
-#
-# Is $2 (defaults to $MYSQL_VERSION_ID) at least version $1?
-# (nice) idea from versionator.eclass
-#
-mysql_version_is_at_least() {
-	local want_s=$(stripdots "$1") have_s=$(stripdots "${2:-${MYSQL_VERSION_ID}}")
-	[[ -z "${want_s}" ]] && die "mysql_version_is_at_least missing value to check"
-	[[ ${want_s} -le ${have_s} ]] && return 0 || return 1
-}
-
-#
-# To be called on the live filesystem, reassigning symlinks of each MySQL
-# library to the best version available.
-#
-mysql_lib_symlinks() {
-	einfo "Updating MySQL .so symlinks"
-	local d dirlist maxdots soname sonameln reldir
-	reldir="${1}"
-	pushd "${reldir}/usr/$(get_libdir)" &> /dev/null
-		# dirlist must contain the less significative directory left
-		dirlist="mysql"
-
-		# waste some time in removing and recreating symlinks
-		for d in $dirlist ; do
-			for soname in $( find "${d}" -name "*.so*" -and -not -type "l" 2>/dev/null ) ; do
-				# maxdot is a limit versus infinite loop
-				maxdots=0
-				sonameln=${soname##*/}
-				# loop in version of the library to link it, similar to how
-				# libtool works
-				while [[ ${sonameln:0-3} != '.so' ]] && [[ ${maxdots} -lt 6 ]] ; do
-					rm -f "${sonameln}"
-					ln -s "${soname}" "${sonameln}"
-					(( ++maxdots ))
-					sonameln="${sonameln%.*}"
-				done
-				rm -f "${sonameln}"
-				ln -s "${soname}" "${sonameln}"
-			done
-		done
-	popd &> /dev/null
-}