#(ie. use with rpm --rebuild):
#
#	--with debug	Compile with debugging code
# 
#  enable build with debugging code: will _not_ strip away any debugging code,
#  will _add_ -g3 to CFLAGS, will _add_ --enable-maintainer-mode to 
#  configure.

%define build_debug 0
%define build_test 0

# commandline overrides:
# rpm -ba|--rebuild --with 'xxx'
%{?_with_debug: %{expand: %%define build_debug 1}}
%{?_with_test: %{expand: %%define build_test 1}}
%{?_without_test: %global build_test 0}

%if %{build_debug}
# disable build root strip policy
%define __spec_install_post %{_libdir}/rpm/brp-compress || :

# This gives extra debuggin and huge binaries
%{expand:%%define optflags %{optflags} %([ ! $DEBUG ] && echo '-g3')}
%endif

%if %{build_debug}
%define build_debug 1
%endif

%if %{build_test}
%define build_test 1
%endif


%define major 18
%define libmysqlembedded_major 0
%define libmysqlembedded_minor 0.1
%define libname %mklibname mariadb %{major}
%define libmariadbservices %mklibname mariadbservices
%define libmariadbembedded %mklibname mariadb-embedded %{major}
%define develname %mklibname -d mariadb
%define old_staticdevelname %mklibname -d -s mariadb
%define libmariadbembedded_devel %mklibname -d mariadb-embedded

%define mysql_libname %mklibname mysql %{major}
%define mysql_develname %mklibname -d mysql
%define libmysqlservices %mklibname mysqlservices
%define libmysqlembedded %mklibname mysqld %{libmysqlembedded_major}
%define libmysqlembedded_devel %mklibname -d mariadb-embedded

%define mirror	http://ftp.osuosl.org/pub/mariadb

%define muser	mysql
Summary:	A very fast and reliable SQL database engine
Name: 		mariadb
Version:	5.5.23
Release:	%mkrel 4
Group:		Databases
License:	GPLv2 with exceptions
URL:		http://mariadb.org/
Source0:        %{mirror}/%{name}-%{version}/kvm-tarbake-jaunty-x86/%{name}-%{version}.tar.gz
Source2:	mysqld.sysconfig
Source3:	my.cnf
Source4:	libmysql.version
Source10:	mysql.tmpfiles.d
Source11:	mysqld.service
Source12:	mysqld-prepare-db-dir
Source13:	mysqld-wait-ready
# the following patches are rediffed from the mysql-5.5 src.rpm to mariadb-5.5 
# fedora patches
Patch1: 	mariadb-5.5-errno.patch
Patch2: 	mariadb-5.5-strmov.patch
Patch3: 	mariadb-5.5-install-test.patch
Patch4: 	mysql-expired-certs.patch
Patch7: 	mariadb-5.5-versioning.patch
Patch8: 	mariadb-5.5-dubious-exports.patch
Patch12: 	mysql-openssl-test.patch

# mandriva patches
Patch101:	mariadb-5.5-logrotate.patch
Patch102:	mariadb-5.5-initscript.patch
Patch103:	mariadb-5.5-mysql_upgrade-exit-status.patch
Patch106:	mariadb-5.5-hotcopy.patch
Patch107:	mariadb-5.5-mysql_install_db-quiet.patch

Requires(post):  rpm-helper >= 0.24.8-1
Requires(preun): rpm-helper >= 0.24.8-1
Requires(post): %{name}-common%{_isa} = %{version}-%{release}
Requires(preun): %{name}-common%{_isa} = %{version}-%{release}
Requires(post): %{name}-client%{_isa} = %{version}-%{release}
Requires(preun): %{name}-client%{_isa} = %{version}-%{release}
Requires(postun): %{name}-common%{_isa} = %{version}-%{release}
Requires(postun): %{name}-client%{_isa} = %{version}-%{release}
Requires:	%{name}-common%{_isa} = %{version}-%{release}
Requires:	%{name}-core%{_isa} = %{version}-%{release}
Requires:	%{name}-client%{_isa} = %{version}-%{release}
Provides:	mysql = %{version}-%{release}
Obsoletes:	mysql < %{version}-%{release}
Obsoletes:	%{libmariadbservices} < 5.5.18-0.3194.20111227.1
Obsoletes:	%{libmysqlservices} < %{version}-%{release}
Conflicts:	%{name}-extra%{_isa} < %{version}-%{release}
Conflicts:	%{name}-feedback%{_isa} < %{version}-%{release}
Conflicts:	%{name}-obsolete%{_isa} < %{version}-%{release}
Suggests:	%{name}-extra%{_isa}
BuildRequires:	bison
BuildRequires:	cmake
BuildRequires:	doxygen
BuildRequires:	glibc-devel
BuildRequires:	libaio-devel
BuildRequires:	libstdc++-devel
BuildRequires:	libtermcap-devel
BuildRequires:	multiarch-utils >= 1.0.3
BuildRequires:	ncurses-devel
BuildRequires:	openssl-devel
BuildRequires:	wrap-devel
BuildRequires:	python
BuildRequires:	systemtap
BuildRequires:	tetex
BuildRequires:	texinfo
BuildRequires:	xfs-devel
BuildRequires:	zlib-devel
BuildRequires:	boost-devel
BuildRequires:	libaio-devel
BuildConflicts:	edit-devel

%description
The MariaDB software delivers a very fast, multi-threaded, multi-user, and
robust SQL (Structured Query Language) database server. MariaDB Server is
intended for mission-critical, heavy-load production systems as well as for
embedding into mass-deployed software.

The mariadb server is compiled with the following storage engines:

 - Aria Storage Engine
 - Archive Storage Engine
 - Blackhole Storage Engine
 - CSV Storage Engine
 - FederatedX Storage Engine (Federated replacement)
 - Heap Storage Engine
 - MyISAM Storage Engine
 - MyISAMMRG Storage Engine
 - Partition Storage Engine
 - Perfschema Storage Engine
 - XtraDB Storage Engine (InnoDB replacement)

The following extra storage engines are provided by the mariadb-extra package

 - OQGraph Storage Engine
 - Sphinx Storage Engine

The feedback storage engine is provided by the mariadb-feedback package

 - Feedback Storage Engine

The following storage engines are provided in the mariadb-obsolete package

 - Federated Storage Engine
 - InnoDB Storage Engine

%package -n	mysql-MariaDB
Summary:	A MySQL drop-in replacement
Group:		System/Servers
Requires:	%{name}%{_isa}

%description -n	mysql-MariaDB
MariaDB is a complete MySQL drop-in replacement with additional fixes and
storage engines.

This package is used as a transitional virtual package, which requires
MariaDB so that people who used to use mysql can find it nicely.

%package	feedback
Summary:	MariaDB feedback storage engine
Group:		System/Servers
Requires:	%{name}-common-core%{_isa} >= %{version}-%{release}
Conflicts:	%{name}-common-core%{_isa} < %{version}-%{release}

%description	feedback
MariaDB feedback storage engine submits feedback about your mariadb server.
Results can be seen on http://mariadb.org/feedback_plugin/ .

%package	extra
Summary:	MariaDB extra storage engines
Group:		System/Servers
Requires:	%{name}-common-core%{_isa} >= %{version}-%{release}
Conflicts:	%{name}-common-core%{_isa} < %{version}-%{release}

%description	extra
MariaDB oqgraph and sphinx storage engines.

%package	obsolete
Summary:	MariaDB obsolete storage engines
Group:		System/Servers
Requires:	%{name}-common-core%{_isa} >= %{version}-%{release}
Conflicts:	%{name}-common-core%{_isa} < %{version}-%{release}
Conflicts:	mysql-core < 5.5.18

%description	obsolete
MariaDB obsolete storage engines. InnoDB and Federated are being replaced by
XtraDB and FederatedX storage engines. These obsolete storage engines are
provided in case you need the vanilla mysql storage engines.

%package	core
Summary:	Server core binary
Group:		System/Servers
Requires:	%{name}-common-core%{_isa} >= %{version}-%{release}
Provides:	mysql-core = %{version}-%{release}
Obsoletes:	mysql-core < %{version}-%{release}

%description	core
Core mysqld server binary. For a full MariaDB database server, install
package 'mariadb'.

%package	common-core
Summary:	Common files required by core binary
Group:		System/Servers
Provides:	mysql-common-core = %{version}-%{release}
Obsoletes:	mysql-common-core < %{version}-%{release}

%description	common-core
Common files minimally required by mysqld server binary.

%package	common
Summary:	Common files
Group:		System/Servers
Requires(post): rpm-helper
Requires(preun): rpm-helper
Requires(pre): rpm-helper
Requires(postun): rpm-helper
Requires(post): %{name}-client%{_isa} >= %{version}-%{release}
Requires(preun): %{name}-client%{_isa} >= %{version}-%{release}
Requires:	%{name}-client%{_isa} >= %{version}-%{release}
Requires:	%{name}-common-core%{_isa} >= %{version}-%{release}
Provides:	mysql-common = %{version}-%{release}
Obsoletes:	mysql-common < %{version}-%{release}

%description	common
Common files for the MariaDB database server.

%package	client
Summary:	Client
Group:		Databases
Requires(post): %{libname}%{_isa} >= %{version}-%{release}
Requires(preun): %{libname}%{_isa} >= %{version}-%{release}
Requires:	%{libname}%{_isa} >= %{version}-%{release}
Provides:	mysql-client = %{version}-%{release}
Obsoletes:	mysql-client < %{version}-%{release}

%description	client
This package contains the standard MariaDB clients.

%package	bench
Summary:	Benchmarks and test system
Group:		System/Servers
Requires(post): %{name}-client%{_isa} >= %{version}-%{release}
Requires(preun): %{name}-client%{_isa} >= %{version}-%{release}
Requires:	%{name}-client%{_isa} >= %{version}-%{release}
Provides:	mysql-bench = %{version}-%{release}
Obsoletes:	mysql-bench < %{version}-%{release}

%description	bench
This package contains MariaDB benchmark scripts and data.

%package -n	%{libname}
Summary:	Shared libraries
Group:		System/Libraries
Provides:	%{name}-shared-libs = %{version}-%{release}
Provides:	%{name}-shared = %{version}-%{release}
Provides:	%{mysql_libname} = %{version}-%{release}
Obsoletes:	%{mysql_libname} < %{version}-%{release}

%description -n	%{libname}
This package contains the shared libraries (*.so*) which certain languages and
applications need to dynamically load and use MariaDB.

%package -n	%{develname}
Summary:	Development header files and libraries
Group:		Development/Other
Requires(post): %{libname} >= %{version}-%{release}
Requires(preun): %{libname} >= %{version}-%{release}
Requires(post): %{name}-common%{_isa} >= %{version}-%{release}
Requires(preun): %{name}-common%{_isa} >= %{version}-%{release}
Requires(post): %{name}-client%{_isa} >= %{version}-%{release}
Requires(preun): %{name}-client%{_isa} >= %{version}-%{release}
Requires:	%{libname} = %{version}-%{release}
Requires:	%{name}-common%{_isa} >= %{version}-%{release}
Requires:	%{name}-client%{_isa} >= %{version}-%{release}
Provides:	%{name}-devel = %{version}-%{release}
Provides:	%{libname}-devel = %{version}-%{release}
Obsoletes:	%{libname}-devel < %{version}-%{release}
Obsoletes:	%{old_staticdevelname} < %{version}-%{release}
Provides:	%{mysql_develname} = %{version}-%{release}
Obsoletes:	%{mysql_develname} < %{version}-%{release}
Provides:	mysql-devel = %{version}-%{release}

%description -n	%{develname}
This package contains the development header files and libraries necessary to
develop MariaDB client applications.

%package -n 	%{libmariadbembedded}
Summary: 	MariaDB as an embeddable library
Group: 		System/Libraries
Provides: 	%{name}-embedded = %{version}-%{release}
Obsoletes: 	%{name}-embedded < %{version}-%{release}
Provides:	%{libmysqlembedded} = %{version}-%{release}
Obsoletes:	%{libmysqlembedded} < %{version}-%{release}

%description -n %{libmariadbembedded}
MariaDB is a multi-user, multi-threaded SQL database server. This
package contains a version of the MariaDB server that can be embedded
into a client application instead of running as a separate process.

The API is identical for the embedded MariaDB version and the client/server
version.

%package -n 	%{libmariadbembedded_devel}
Summary: 	Development files for MySQL as an embeddable library
Group: 		Development/Other
Provides: 	%{name}-embedded-devel = %{version}-%{release}
Obsoletes: 	%{name}-embedded-devel < %{version}-%{release}
Requires: 	%{libmariadbembedded} = %{version}-%{release}
Requires: 	%{develname} = %{version}-%{release}
Provides:	%{libmysqlembedded_devel} = %{version}-%{release}
Obsoletes:	%{libmysqlembedded_devel} < %{version}-%{release}
Provides:	mysql-embedded-devel = %{version}-%{release}

%description -n %{libmariadbembedded_devel}
MariaDB is a multi-user, multi-threaded SQL database server. This
package contains files needed for developing and testing with
the embedded version of the MariaDB server.
 
The API is identical for the embedded MariaDB version and the client/server
version.


%prep
%setup -q
%apply_patches

mkdir -p Mageia
cp %{SOURCE2} Mageia/mysqld.sysconfig
cp %{SOURCE3} Mageia/my.cnf

# lib64 fix
perl -pi -e "s|/usr/lib/|%{_libdir}/|g" Mageia/my.cnf

# antiborker
perl -pi -e "s|\@bindir\@|%{_bindir}|g" support-files/* scripts/*
perl -pi -e "s|\@sbindir\@|%{_sbindir}|g" support-files/* scripts/*
perl -pi -e "s|\@libexecdir\@|%{_sbindir}|g" support-files/* scripts/*
perl -pi -e "s|\@localstatedir\@|/var/lib/mysql|g" support-files/* scripts/*
perl -pi -e "s|^basedir=.*|basedir=%{_prefix}|g" support-files/* scripts/mysql_install_db*

# this may be part of the problems with mysql-test
# http://bugs.mysql.com/bug.php?id=52223
#perl -pi -e "s|basedir/lib\b|basedir/%{_lib}\b|g" mysql-test/mysql-test-run.pl
#perl -pi -e "s|basedir/lib/|basedir/%{_lib}/|g" mysql-test/mysql-test-run.pl

# workaround for upstream bug #56342
rm -f mysql-test/t/ssl_8k_key-master.opt

# upstream has fallen down badly on symbol versioning, do it ourselves
cp %{SOURCE4} libmysql/libmysql.version

%build
%serverbuild
export CFLAGS="${CFLAGS:-%{optflags}}"
export CXXFLAGS="${CXXFLAGS:-%{optflags}}"
export FFLAGS="${FFLAGS:-%{optflags}}"

%cmake \
    -DCMAKE_BUILD_TYPE=RelWithDebInfo \
    -DCMAKE_INSTALL_PREFIX=%{_prefix} \
    -DINSTALL_SBINDIR=sbin \
    -DMYSQL_DATADIR=/var/lib/mysql \
    -DSYSCONFDIR=%{_sysconfdir} \
    -DINSTALL_PLUGINDIR=%{_lib}/mysql/plugin \
    -DINSTALL_MANDIR=share/man \
    -DINSTALL_SHAREDIR=share/mysql \
    -DINSTALL_LIBDIR=%{_lib} \
    -DINSTALL_INCLUDEDIR=include/mysql \
    -DINSTALL_INFODIR=share/info \
    -DINSTALL_MYSQLDATADIR=/var/lib/mysql \
    -DINSTALL_MYSQLTESTDIR=share/mysql/mysql-test \
    -DINSTALL_SQLBENCHDIR=share/mysql \
    -DINSTALL_SUPPORTFILESDIR=share/mysql \
    -DINSTALL_MYSQLSHAREDIR=share/mysql \
    -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
    -DWITH_READLINE=0 \
    -DWITH_LIBEDIT=0 \
    -DWITH_LIBWRAP=1 \
    -DWITH_SSL=system \
    -DWITH_ZLIB=system \
    -DWITH_PIC=1 \
    -DMYSQL_TCP_PORT=3306 \
    -DEXTRA_CHARSETS=all \
    -DENABLED_LOCAL_INFILE=1 \
    -DENABLE_DTRACE=1 \
    -DWITH_EMBEDDED_SERVER=1 \
    -DMYSQL_USER=%{muser} \
%if %{build_debug}
    -DWITH_DEBUG=1 \
%else
    -DWITH_DEBUG=0 \
%endif
    -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
    -DWITHOUT_NDBCLUSTER_STORAGE_ENGINE=1 \
    -DWITHOUT_DAEMON_EXAMPLE=1 \
    -DWITH_PLUGIN_PBXT=1 \
    -DFEATURE_SET="community" \
    -DCOMPILATION_COMMENT="%{_vendor} - MariaDB Community Edition (GPL)"

cp ../libmysql/libmysql.version libmysql/libmysql.version

%make

%install
rm -rf %{buildroot}

# don't fiddle with the initscript!
export DONT_GPRINTIFY=1

%if %{build_debug}
export DONT_STRIP=1
%endif

install -d %{buildroot}%{_sysconfdir}/sysconfig
install -d %{buildroot}%{_initrddir}
install -d %{buildroot}%{_var}/run/mysqld
install -d %{buildroot}%{_var}/log/mysqld
install -d %{buildroot}/var/lib/mysql/{mysql,test}

%makeinstall_std -C build

# install init scripts
install -m0755 build/support-files/mysql.server %{buildroot}%{_initrddir}/mysqld

# install configuration files
install -m0644 Mageia/mysqld.sysconfig %{buildroot}%{_sysconfdir}/sysconfig/mysqld
install -m0644 Mageia/my.cnf %{buildroot}%{_sysconfdir}/my.cnf

mkdir -p %{buildroot}/etc/tmpfiles.d
install -m 0644 %{SOURCE10} %{buildroot}/etc/tmpfiles.d/mysql.conf
mkdir -p %{buildroot}/lib/systemd/system
install -m 644 %{SOURCE11} %{buildroot}/lib/systemd/system
install -m 755 %{SOURCE12} %{buildroot}%{_sbindir}/mysqld-prepare-db-dir
install -m 755 %{SOURCE13} %{buildroot}%{_sbindir}/mysqld-wait-ready

# bork
mv %{buildroot}%{_bindir}/mysqlaccess.conf %{buildroot}%{_sysconfdir}/
chmod 644 %{buildroot}%{_sysconfdir}/mysqlaccess.conf
mv %{buildroot}%{_prefix}/scripts/mysql_install_db %{buildroot}%{_bindir}/
mv %{buildroot}%{_datadir}/mysql/aclocal %{buildroot}%{_datadir}/aclocal

pushd %{buildroot}%{_bindir}
    ln -sf mysqlcheck mysqlrepair
    ln -sf mysqlcheck mysqlanalyze
    ln -sf mysqlcheck mysqloptimize
popd

# nuke -Wl,--as-needed from the mysql_config file
perl -pi -e "s|^ldflags=.*|ldflags=\'-rdynamic\'|g" %{buildroot}%{_bindir}/mysql_config

# cmake generates some completely wacko references to -lprobes_mysql when
# building with dtrace support.  Haven't found where to shut that off,
# so resort to this blunt instrument.  While at it, let's not reference
# libmysqlclient_r anymore either.
sed -e 's/-lprobes_mysql//' -e 's/-lmysqlclient_r/-lmysqlclient/' \
	%{buildroot}%{_bindir}/mysql_config >mysql_config.tmp
cp -f mysql_config.tmp %{buildroot}%{_bindir}/mysql_config
chmod 755 %{buildroot}%{_bindir}/mysql_config
install -m 0755 -d %{buildroot}/var/lib/mysql

# Remove libmysqld.a, + hardlink libmysqld.so.%{libmysqlembedded_major} so that it's provided
rm -f %{buildroot}%{_libdir}/libmysqld.a
ln %{buildroot}%{_libdir}/libmysqld.so.%{major} %{buildroot}%{_libdir}/libmysqld.so.%{libmysqlembedded_major}.%{libmysqlembedded_minor}
ln -s libmysqld.so.%{libmysqlembedded_major}.%{libmysqlembedded_minor} %{buildroot}%{_libdir}/libmysqld.so.%{libmysqlembedded_major}

# libmysqlclient_r is no more.  Upstream tries to replace it with symlinks
# but that really doesn't work (wrong soname in particular).  We'll keep
# just the devel libmysqlclient_r.so link, so that rebuilding without any
# source change is enough to get rid of dependency on libmysqlclient_r.
rm -f %{buildroot}%{_libdir}/libmysqlclient_r.so*
ln -s libmysqlclient.so %{buildroot}%{_libdir}/libmysqlclient_r.so

# remove static libs
rm -f %{buildroot}%{_libdir}/libmysqlclient.a
rm -f %{buildroot}%{_libdir}/libmysqlclient_r.a

# mysql-test includes one executable that doesn't belong under /usr/share,
# so move it and provide a symlink
mv %{buildroot}%{_datadir}/mysql/mysql-test/lib/My/SafeProcess/my_safe_process %{buildroot}%{_bindir}
ln -s %{_bindir}/my_safe_process %{buildroot}%{_datadir}/mysql/mysql-test/lib/My/SafeProcess/my_safe_process

# mysql client statically built against a local embedded library, pretty useless
rm -f %{buildroot}%{_bindir}/mysql_embedded

# this command enables plugins, but needs ini file + configuration in my.cnf
# before executing... and oh yeah, mysql must be stopped... => useless
# however, apparently tests seem to want it, even thought they don't use it.
#rm -f %{buildroot}%{_bindir}/mysql_plugin
rm -f %{buildroot}%{_libdir}/mysql/plugin/daemon_example.ini

# remove more useless plugins
rm -f %{buildroot}%{_libdir}/mysql/plugin/auth_test_plugin.so
rm -f %{buildroot}%{_libdir}/mysql/plugin/dialog_examples.so

# house cleaning
rm -rf %{buildroot}%{_datadir}/info
rm -f %{buildroot}%{_bindir}/client_test
rm -f %{buildroot}%{_bindir}/make_win_binary_distribution
rm -f %{buildroot}%{_bindir}/make_win_src_distribution
rm -f %{buildroot}%{_datadir}/mysql/binary-configure
rm -f %{buildroot}%{_datadir}/mysql/config.huge.ini
rm -f %{buildroot}%{_datadir}/mysql/config.medium.ini
rm -f %{buildroot}%{_datadir}/mysql/config.small.ini
rm -f %{buildroot}%{_datadir}/mysql/mysqld_multi.server
rm -f %{buildroot}%{_datadir}/mysql/mysql-log-rotate
rm -f %{buildroot}%{_datadir}/mysql/mysql.server
rm -f %{buildroot}%{_datadir}/mysql/ndb-config-2-node.ini
rm -f %{buildroot}%{_datadir}/mysql/binary-configure
rm -f %{buildroot}%{_mandir}/man1/make_win_bin_dist.1*
rm -f %{buildroot}%{_mandir}/man1/make_win_src_distribution.1*
rm -f %{buildroot}%{_datadir}/mysql/magic

# no idea how to fix this
rm -rf %{buildroot}%{_prefix}/data
rm -rf %{buildroot}%{_prefix}/docs
rm -rf %{buildroot}%{_prefix}/scripts
rm -f %{buildroot}%{_prefix}/COPYING
rm -f %{buildroot}%{_prefix}/COPYING.LESSER
rm -f %{buildroot}%{_prefix}/INSTALL-BINARY
rm -f %{buildroot}%{_prefix}/README

%multiarch_binaries %{buildroot}%{_bindir}/mysql_config
%multiarch_includes %{buildroot}%{_includedir}/mysql/my_config.h

cat > README.urpmi <<EOF

NOTE: MariaDB is installed without root password, it is recommended to set the
root password with the following command as soon as possible:

   mysqladmin password

The initscript used to start mysql has been reverted to use the one shipped
by MariaDB. This means the following changes:

 * The generation of the initial system mysql database is now done when mysql
   is started from the initscript and only if the /var/lib/mysql/mysql
   directory is empty (mysql_install_db). Previousely this was quite hidden and
   silently done at (rpm) install time. As a consequence to this change you may
   have to perform some manual tasks to upgrade the mysql system database and
   such. So, doing something like this might help you:

   /etc/init.d/mysqld stop
   TMPDIR=/var/tmp mysql_install_db
   mysql_upgrade

The cluster functionalities (ndb) has been deactivated and will be removed in
future mysql versions. Oracle has a new product named mysql-cluster that
replaces the cluster functionalities.

The mysql-common-core package ships with a default /etc/my.cnf file that is 
based on the my-medium.cnf file that comes with the source code.
EOF

################################################################################
# run the tests
%if %{build_test}
# disable failing tests
echo "rpl_trigger : Unstable test case" >> mysql-test/t/disabled.def
echo "type_enum : Unstable test case" >> mysql-test/t/disabled.def
echo "windows : For MS Windows only" >> mysql-test/t/disabled.def
pushd build/mysql-test
export LANG=C
export LC_ALL=C
export LANGUAGE=C
    perl ./mysql-test-run.pl \
    --mtr-build-thread="$((${RANDOM} % 100))" \
    --skip-ndb \
    --timer \
    --retry=0 \
    --ssl \
    --mysqld=--binlog-format=mixed \
    --testcase-timeout=60 \
    --suite-timeout=120 || false
popd
%endif

%pre
# enable plugins
if [ -f %{_sysconfdir}/my.cnf ]; then
    perl -pi -e "s|^#plugin-load|plugin-load|g" %{_sysconfdir}/my.cnf
    perl -pi -e "s|^#federated|federated|g" %{_sysconfdir}/my.cnf
    # switch to federatedx provider
    perl -pi -e "s|;ha_federated\.so$|;ha_federatedx\.so|g" %{_sysconfdir}/my.cnf
fi

%pre common
# delete the mysql group if no mysql user is found, before adding the user
if [ -z "`getent passwd %{muser}`" ] && ! [ -z "`getent group %{muser}`" ]; then
    %{_sbindir}/groupdel %{muser} 2> /dev/null || :
fi

%_pre_useradd %{muser} /var/lib/mysql /bin/bash

%post
%_post_service mysqld

%preun
%_preun_service mysqld

%postun
if [ "$1" = "0" ]; then
    if [ -f /var/lock/subsys/mysqld ]; then
        %{_initrddir}/mysqld restart > /dev/null 2>/dev/null || :
    fi
fi

%pre common-core
# enable plugins
if [ -f %{_sysconfdir}/my.cnf ]; then
    perl -pi -e "s|^#plugin-load|plugin-load|g" %{_sysconfdir}/my.cnf
    perl -pi -e "s|^#federated|federated|g" %{_sysconfdir}/my.cnf
    # switch to federatedx provider
    perl -pi -e "s|;ha_federated\.so$|;ha_federatedx\.so|g" %{_sysconfdir}/my.cnf
fi

%files
%doc README.urpmi
%{_initrddir}/mysqld
%_sysconfdir/tmpfiles.d/mysql.conf
/lib/systemd/system/mysqld.service
%{_sbindir}/mysqld-prepare-db-dir
%{_sbindir}/mysqld-wait-ready
%dir %{_libdir}/mysql/plugin
# authentication plugins
%{_libdir}/mysql/plugin/auth_socket.so
%{_libdir}/mysql/plugin/dialog.so
%{_libdir}/mysql/plugin/mysql_clear_password.so
# replication plugins
%{_libdir}/mysql/plugin/semisync_master.so
%{_libdir}/mysql/plugin/semisync_slave.so
# storage engines
%{_libdir}/mysql/plugin/ha_archive.so
%{_libdir}/mysql/plugin/ha_blackhole.so
%{_libdir}/mysql/plugin/ha_federatedx.so
# sql logging plugin
%{_libdir}/mysql/plugin/sql_errlog.so
# upstream describes this as "junk"
%{_libdir}/mysql/plugin/adt_null.so
%{_libdir}/mysql/plugin/mypluglib.so
%{_libdir}/mysql/plugin/qa_auth_client.so
%{_libdir}/mysql/plugin/qa_auth_interface.so
%{_libdir}/mysql/plugin/qa_auth_server.so
# example plugins, not usefull at all, removing
#%{_libdir}/mysql/plugin/auth_test_plugin.so
#%{_libdir}/mysql/plugin/dialog_examples.so

%files -n mysql-MariaDB

%files obsolete
%{_libdir}/mysql/plugin/ha_innodb.so
%{_libdir}/mysql/plugin/ha_federated.so

%files feedback
%{_libdir}/mysql/plugin/feedback.so

%files extra
%{_libdir}/mysql/plugin/ha_oqgraph.so
%{_libdir}/mysql/plugin/ha_sphinx.so

%files client
%config(noreplace) %{_sysconfdir}/mysqlaccess.conf
%{_bindir}/msql2mysql
%{_bindir}/mysql
%{_bindir}/mysqlaccess
%{_bindir}/mysqladmin
%{_bindir}/mysqlanalyze
%{_bindir}/mysqlbinlog
%{_bindir}/mysqlcheck
%{_bindir}/mysqldump
%{_bindir}/mysqldumpslow
%{_bindir}/mysql_find_rows
%{_bindir}/mysqlimport
%{_bindir}/mysqloptimize
%{_bindir}/mysqlrepair
%{_bindir}/mysqlshow
%{_bindir}/mysqlslap
%{_bindir}/mysql_waitpid
%{_mandir}/man1/msql2mysql.1*
%{_mandir}/man1/myisam_ftdump.1*
%{_mandir}/man1/mysql.1*
%{_mandir}/man1/mysqlaccess.1*
%{_mandir}/man1/mysqladmin.1*
%{_mandir}/man1/mysqlbinlog.1*
%{_mandir}/man1/mysqlcheck.1*
%{_mandir}/man1/mysqldump.1*
%{_mandir}/man1/mysqldumpslow.1*
%{_mandir}/man1/mysql_find_rows.1*
%{_mandir}/man1/mysqlimport.1*
%{_mandir}/man1/mysqlshow.1*
%{_mandir}/man1/mysql_waitpid.1*

%files bench
%doc build/sql-bench/README
%{_bindir}/my_safe_process
%{_bindir}/mysql_client_test
%{_bindir}/mysql_client_test_embedded
%{_bindir}/mysqltest_embedded
%{_datadir}/mysql/sql-bench
%attr(-,mysql,mysql) %{_datadir}/mysql/mysql-test
%{_mandir}/man1/mysql-stress-test.pl.1*
%{_mandir}/man1/mysql-test-run.pl.1*
%{_mandir}/man1/mysql_client_test.1*
%{_mandir}/man1/mysql_client_test_embedded.1*
%{_mandir}/man1/mysqltest.1*
%{_mandir}/man1/mysqltest_embedded.1*

%files core
%{_sbindir}/mysqld

%files common-core
%config(noreplace) %{_sysconfdir}/my.cnf
%dir %{_datadir}/mysql
%{_datadir}/mysql/english
%{_datadir}/mysql/charsets

%files common
%doc README COPYING
%config(noreplace) %{_sysconfdir}/sysconfig/mysqld
%{_bindir}/aria_chk
%{_bindir}/aria_dump_log
%{_bindir}/aria_ftdump
%{_bindir}/aria_pack
%{_bindir}/aria_read_log
%{_bindir}/innochecksum
%{_bindir}/myisamchk
%{_bindir}/myisam_ftdump
%{_bindir}/myisamlog
%{_bindir}/myisampack
%{_bindir}/my_print_defaults
%{_bindir}/mysqlbug
%{_bindir}/mysql_convert_table_format
%{_bindir}/mysqld_multi
%{_bindir}/mysqld_safe
%{_bindir}/mysql_fix_extensions 
%{_bindir}/mysqlhotcopy
%{_bindir}/mysql_install_db
%{_bindir}/mysql_plugin
%{_bindir}/mysql_secure_installation
%{_bindir}/mysql_setpermission
%{_bindir}/mysqltest
%{_bindir}/mysql_tzinfo_to_sql
%{_bindir}/mysql_upgrade
%{_bindir}/mysql_zap
%{_bindir}/perror
%{_bindir}/replace
%{_bindir}/resolveip
%{_bindir}/resolve_stack_dump
%attr(0755,%{muser},%{muser}) %dir /var/lib/mysql
%attr(0755,%{muser},%{muser}) %dir /var/lib/mysql/mysql
%attr(0755,%{muser},%{muser}) %dir /var/lib/mysql/test
%attr(0755,%{muser},%{muser}) %dir %{_var}/run/mysqld
%attr(0755,%{muser},%{muser}) %dir %{_var}/log/mysqld
%{_datadir}/mysql/*.cnf
%{_datadir}/mysql/fill_help_tables.sql
%{_datadir}/mysql/mysql_system_tables.sql
%{_datadir}/mysql/mysql_system_tables_data.sql
%{_datadir}/mysql/mysql_test_data_timezone.sql
%{_datadir}/mysql/errmsg-utf8.txt
%{_datadir}/mysql/czech
%{_datadir}/mysql/danish
%{_datadir}/mysql/dutch
%{_datadir}/mysql/estonian
%{_datadir}/mysql/french
%{_datadir}/mysql/german
%{_datadir}/mysql/greek
%{_datadir}/mysql/hungarian
%{_datadir}/mysql/italian
%{_datadir}/mysql/japanese
%{_datadir}/mysql/korean
%{_datadir}/mysql/norwegian
%{_datadir}/mysql/norwegian-ny
%{_datadir}/mysql/polish
%{_datadir}/mysql/portuguese
%{_datadir}/mysql/romanian
%{_datadir}/mysql/russian
%{_datadir}/mysql/serbian
%{_datadir}/mysql/slovak
%{_datadir}/mysql/spanish
%{_datadir}/mysql/swedish
%{_datadir}/mysql/ukrainian
%{_mandir}/man1/innochecksum.1*
%{_mandir}/man1/myisamchk.1*
%{_mandir}/man1/myisamlog.1*
%{_mandir}/man1/myisampack.1*
%{_mandir}/man1/my_print_defaults.1*
%{_mandir}/man1/mysqlbug.1*
%{_mandir}/man1/mysql_convert_table_format.1*
%{_mandir}/man1/mysqld_multi.1*
%{_mandir}/man1/mysqld_safe.1*
%{_mandir}/man1/mysql_fix_extensions.1*
%{_mandir}/man1/mysql_fix_privilege_tables.1*
%{_mandir}/man1/mysqlhotcopy.1*
%{_mandir}/man1/mysql_install_db.1*
%{_mandir}/man1/mysqlman.1*
%{_mandir}/man1/mysql_secure_installation.1*
%{_mandir}/man1/mysql.server.1*
%{_mandir}/man1/mysql_setpermission.1*
%{_mandir}/man1/mysqlslap.1*
%{_mandir}/man1/mysql_tzinfo_to_sql.1*
%{_mandir}/man1/mysql_upgrade.1*
%{_mandir}/man1/mysql_zap.1*
%{_mandir}/man1/perror.1*
%{_mandir}/man1/replace.1*
%{_mandir}/man1/resolveip.1*
%{_mandir}/man1/resolve_stack_dump.1*
%{_mandir}/man8/mysqld.8*
%{_mandir}/man8/mysqlmanager.8*

%files -n %{libname}
%{_libdir}/libmysqlclient.so.%{major}*

%files -n %{develname}
%doc INSTALL-SOURCE
%multiarch %{multiarch_bindir}/mysql_config
%{_bindir}/mysql_config
%{_libdir}/libmysqlclient_r.so
%{_libdir}/libmysqlclient.so
%dir %{_includedir}/mysql
%dir %{_includedir}/mysql/psi
%{_includedir}/mysql/*.h
%{_includedir}/mysql/psi/*.h
%multiarch %{multiarch_includedir}/mysql/my_config.h
%{_mandir}/man1/comp_err.1*
%{_mandir}/man1/mysql_config.1*
%{_datadir}/aclocal/mysql.m4
# mysqlservices library is static, because it doesn't contain any code
# itself, and is meant to be statically linked to all plugins.
%{_libdir}/libmysqlservices.a

%files -n %{libmariadbembedded}
%doc README COPYING 
%{_libdir}/libmysqld.so.%{major}
%{_libdir}/libmysqld.so.%{libmysqlembedded_major}*

%files -n %{libmariadbembedded_devel}
%{_libdir}/libmysqld.so
%{_bindir}/mysql_client_test_embedded
%{_bindir}/mysqltest_embedded
%{_mandir}/man1/mysql_client_test_embedded.1*
%{_mandir}/man1/mysqltest_embedded.1*
