kde5.eclass: Cleanup obsolete blocker
[gentoo.git] / eclass / mysql-multilib-r1.eclass
1 # Copyright 1999-2017 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: mysql-multilib-r1.eclass
5 # @MAINTAINER:
6 # Maintainers:
7 #       - MySQL Team <mysql-bugs@gentoo.org>
8 #       - Robin H. Johnson <robbat2@gentoo.org>
9 #       - Jorge Manuel B. S. Vicetto <jmbsvicetto@gentoo.org>
10 #       - Brian Evans <grknight@gentoo.org>
11 # @BLURB: This eclass provides common functions for mysql ebuilds
12 # @DESCRIPTION:
13 # The mysql-multilib-r1.eclass is the base eclass to build the mysql and
14 # alternative projects (mariadb and percona) ebuilds.
15 # Provider and version specific settings will be included in each ebuild.
16 # It provides the src_unpack, src_prepare, src_configure, src_compile,
17 # src_install, pkg_preinst, pkg_postinst, pkg_config and pkg_postrm
18 # phase hooks.
19
20 MYSQL_EXTRAS=""
21
22 # @ECLASS-VARIABLE: MYSQL_EXTRAS_VER
23 # @DEFAULT_UNSET
24 # @DESCRIPTION:
25 # The version of the MYSQL_EXTRAS repo to use to build mysql
26 # Use "none" to disable it's use
27 [[ ${MY_EXTRAS_VER} == "live" ]] && MYSQL_EXTRAS="git-r3"
28
29 # @ECLASS-VARIABLE: MYSQL_CMAKE_NATIVE_DEFINES
30 # @DEFAULT_UNSET
31 # @DESCRIPTION:
32 # An array of extra CMake arguments for native multilib builds
33
34 # @ECLASS-VARIABLE: MYSQL_CMAKE_NONNATIVE_DEFINES
35 # @DEFAULT_UNSET
36 # @DESCRIPTION:
37 # An array of extra CMake arguments for non-native multilib builds
38
39 # @ECLASS-VARIABLE: MYSQL_CMAKE_EXTRA_DEFINES
40 # @DEFAULT_UNSET
41 # @DESCRIPTION:
42 # An array of CMake arguments added to native and non-native
43
44 # Keeping eutils in EAPI=6 for emktemp in pkg_config
45
46 inherit eutils systemd flag-o-matic ${MYSQL_EXTRAS} versionator \
47         prefix toolchain-funcs user cmake-utils multilib-minimal
48
49 if [[ "${EAPI}x" == "5x" ]]; then
50         inherit multilib mysql_fx
51 fi
52
53 #
54 # Supported EAPI versions and export functions
55 #
56
57 case "${EAPI:-0}" in
58         5|6) ;;
59         *) die "Unsupported EAPI: ${EAPI}" ;;
60 esac
61
62 EXPORT_FUNCTIONS pkg_pretend pkg_setup src_unpack src_prepare src_configure src_compile src_install pkg_preinst pkg_postinst pkg_config
63
64 #
65 # VARIABLES:
66 #
67
68 # Shorten the path because the socket path length must be shorter than 107 chars
69 # and we will run a mysql server during test phase
70 S="${WORKDIR}/mysql"
71
72 [[ ${MY_EXTRAS_VER} == "latest" ]] && MY_EXTRAS_VER="20090228-0714Z"
73 if [[ ${MY_EXTRAS_VER} == "live" ]]; then
74         EGIT_REPO_URI="git://anongit.gentoo.org/proj/mysql-extras.git"
75         EGIT_CHECKOUT_DIR=${WORKDIR}/mysql-extras
76         EGIT_CLONE_TYPE=shallow
77 fi
78
79 # @ECLASS-VARIABLE: MYSQL_PV_MAJOR
80 # @DESCRIPTION:
81 # Upstream MySQL considers the first two parts of the version number to be the
82 # major version. Upgrades that change major version should always run
83 # mysql_upgrade.
84 if [[ -z ${MYSQL_PV_MAJOR} ]] ; then MYSQL_PV_MAJOR="$(get_version_component_range 1-2 ${PV})" ; fi
85
86 # @ECLASS-VARIABLE: MYSQL_VERSION_ID
87 # @DESCRIPTION:
88 # MYSQL_VERSION_ID will be:
89 # major * 10e6 + minor * 10e4 + micro * 10e2 + gentoo revision number, all [0..99]
90 # This is an important part, because many of the choices the MySQL ebuild will do
91 # depend on this variable.
92 # In particular, the code below transforms a $PVR like "5.0.18-r3" in "5001803"
93 # We also strip off upstream's trailing letter that they use to respin tarballs
94 if [[ "${EAPI}x" == "5x" ]]; then
95         MYSQL_VERSION_ID=""
96         tpv="${PV%[a-z]}"
97         tpv=( ${tpv//[-._]/ } ) ; tpv[3]="${PVR:${#PV}}" ; tpv[3]="${tpv[3]##*-r}"
98         for vatom in 0 1 2 3 ; do
99                 # pad to length 2
100                 tpv[${vatom}]="00${tpv[${vatom}]}"
101                 MYSQL_VERSION_ID="${MYSQL_VERSION_ID}${tpv[${vatom}]:0-2}"
102         done
103         # strip leading "0" (otherwise it's considered an octal number by BASH)
104         MYSQL_VERSION_ID=${MYSQL_VERSION_ID##"0"}
105 fi
106
107 # Work out the default SERVER_URI correctly
108 if [[ -z ${SERVER_URI} ]]; then
109         if [[ ${PN} == "mariadb" ]]; then
110                 # Beginning with 5.5, MariaDB stopped putting beta, alpha or rc on their tarball names
111                 MARIA_FULL_PV=$(get_version_component_range 1-3)
112                 MARIA_FULL_P="${PN}-${MARIA_FULL_PV}"
113                 SERVER_URI="https://downloads.mariadb.org/interstitial/${MARIA_FULL_P}/source/${MARIA_FULL_P}.tar.gz"
114         elif [[ ${PN} == "percona-server" ]]; then
115                 PERCONA_PN="Percona-Server"
116                 MIRROR_PV=$(get_version_component_range 1-2 ${PV})
117                 MY_PV=$(get_version_component_range 1-3 ${PV})
118                 PERCONA_RELEASE=$(get_version_component_range 4-5 ${PV})
119                 PERCONA_RC=$(get_version_component_range 6 ${PV})
120                 SERVER_URI="http://www.percona.com/redir/downloads/${PERCONA_PN}-${MIRROR_PV}/${PERCONA_PN}-${MY_PV}-${PERCONA_RC}${PERCONA_RELEASE}/source/tarball/${PN}-${MY_PV}-${PERCONA_RC}${PERCONA_RELEASE}.tar.gz"
121         else
122                 if [[ "${PN}" == "mysql-cluster" ]] ; then
123                         URI_DIR="MySQL-Cluster"
124                         URI_FILE="mysql-cluster-gpl"
125                 else
126                         URI_DIR="MySQL"
127                         URI_FILE="mysql"
128                 fi
129                 [[ -z ${MY_PV} ]] && MY_PV="${PV//_/-}"
130                 URI_A="${URI_FILE}-${MY_PV}.tar.gz"
131                 MIRROR_PV=$(get_version_component_range 1-2 ${PV})
132                 # Recently upstream switched to an archive site, and not on mirrors
133                 SERVER_URI="http://cdn.mysql.com/Downloads/${URI_DIR}-${MIRROR_PV}/${URI_A}
134                         http://downloads.mysql.com/archives/${URI_DIR}-${MIRROR_PV}/${URI_A}"
135         fi
136 fi
137
138 # Define correct SRC_URIs
139 SRC_URI="${SERVER_URI}"
140
141 # Gentoo patches to MySQL
142 if [[ ${MY_EXTRAS_VER} != "live" && ${MY_EXTRAS_VER} != "none" ]]; then
143         SRC_URI="${SRC_URI}
144                 mirror://gentoo/mysql-extras-${MY_EXTRAS_VER}.tar.bz2
145                 https://gitweb.gentoo.org/proj/mysql-extras.git/snapshot/mysql-extras-${MY_EXTRAS_VER}.tar.bz2
146                 https://dev.gentoo.org/~grknight/distfiles/mysql-extras-${MY_EXTRAS_VER}.tar.bz2
147                 https://dev.gentoo.org/~robbat2/distfiles/mysql-extras-${MY_EXTRAS_VER}.tar.bz2
148                 https://dev.gentoo.org/~jmbsvicetto/distfiles/mysql-extras-${MY_EXTRAS_VER}.tar.bz2"
149 fi
150
151 DESCRIPTION="A fast, multi-threaded, multi-user SQL database server"
152 HOMEPAGE="http://www.mysql.com/"
153 LICENSE="GPL-2"
154 SLOT="0/${SUBSLOT:-0}"
155
156 IUSE="debug embedded extraengine jemalloc latin1 libressl +openssl
157         +perl profiling selinux +server systemtap static static-libs tcmalloc test yassl"
158
159 REQUIRED_USE="^^ ( yassl openssl libressl )"
160
161 # Tests always fail when libressl is enabled due to hard-coded ciphers in the tests
162 RESTRICT="libressl? ( test )"
163
164 REQUIRED_USE="${REQUIRED_USE} !server? ( !extraengine !embedded )
165          ?? ( tcmalloc jemalloc )
166          static? ( !libressl !openssl yassl )"
167
168 #
169 # DEPENDENCIES:
170 #
171
172 # Be warned, *DEPEND are version-dependant
173 # These are used for both runtime and compiletime
174 # MULTILIB_USEDEP only set for libraries used by the client library
175 DEPEND="
176         kernel_linux? (
177                 sys-process/procps:0=
178                 dev-libs/libaio:0=
179         )
180         >=sys-apps/sed-4
181         >=sys-apps/texinfo-4.7-r1
182         !dev-db/mariadb-native-client[mysqlcompat]
183         jemalloc? ( dev-libs/jemalloc:0= )
184         tcmalloc? ( dev-util/google-perftools:0= )
185         systemtap? ( >=dev-util/systemtap-1.3:0= )
186         openssl? ( >=dev-libs/openssl-1.0.0:0=[${MULTILIB_USEDEP},static-libs?] )
187         libressl? ( dev-libs/libressl:0=[${MULTILIB_USEDEP},static-libs?] )
188         >=sys-libs/zlib-1.2.3:0=[${MULTILIB_USEDEP},static-libs?]
189         sys-libs/ncurses:0=
190 "
191
192 # prefix: first need to implement something for #196294
193 RDEPEND="${DEPEND}
194         selinux? ( sec-policy/selinux-mysql )
195         abi_x86_32? ( !app-emulation/emul-linux-x86-db[-abi_x86_32(-)] )
196 "
197
198 # Having different flavours at the same time is not a good idea
199 for i in "mysql" "mariadb" "mariadb-galera" "percona-server" "mysql-cluster" ; do
200         [[ ${i} == ${PN} ]] ||
201         RDEPEND="${RDEPEND} !dev-db/${i}"
202 done
203
204 RDEPEND="${RDEPEND}
205         server? ( !prefix? ( dev-db/mysql-init-scripts ) )
206         !<virtual/mysql-5.6-r4"
207
208 # compile-time-only
209 # ncurses only needs multilib for compile time due to a binary that will be not installed
210 DEPEND="${DEPEND}
211         virtual/yacc
212         static? ( sys-libs/ncurses[static-libs] )
213 "
214
215 # For other stuff to bring us in
216 # dev-perl/DBD-mysql is needed by some scripts installed by MySQL
217 PDEPEND="${PDEPEND} perl? ( >=dev-perl/DBD-mysql-2.9004 )
218          server? ( ~virtual/mysql-${MYSQL_PV_MAJOR}[embedded=,static=] )
219          virtual/libmysqlclient:${SLOT}[${MULTILIB_USEDEP},static-libs=]"
220
221 # my_config.h includes ABI specific data
222 MULTILIB_WRAPPED_HEADERS=( /usr/include/mysql/my_config.h /usr/include/mysql/private/embedded_priv.h )
223
224 #
225 # EBUILD FUNCTIONS
226 #
227
228 # @FUNCTION: mysql-multilib-r1_pkg_pretend
229 # @DESCRIPTION:
230 # Perform some basic tests and tasks during pkg_pretend phase:
231 mysql-multilib-r1_pkg_pretend() {
232         if [[ ${MERGE_TYPE} != binary ]] ; then
233                 local GCC_MAJOR_SET=$(gcc-major-version)
234                 local GCC_MINOR_SET=$(gcc-minor-version)
235                 if in_iuse tokudb && use tokudb && [[ ${GCC_MAJOR_SET} -lt 4 || \
236                         ${GCC_MAJOR_SET} -eq 4 && ${GCC_MINOR_SET} -lt 7 ]] ; then
237                         eerror "${PN} with tokudb needs to be built with gcc-4.7 or later."
238                         eerror "Please use gcc-config to switch to gcc-4.7 or later version."
239                         die
240                 fi
241                 # Bug 565584.  InnoDB now requires atomic functions introduced with gcc-4.7 on
242                 # non x86{,_64} arches
243                 if ! use amd64 && ! use x86 && [[ ${GCC_MAJOR_SET} -lt 4 || \
244                         ${GCC_MAJOR_SET} -eq 4 && ${GCC_MINOR_SET} -lt 7 ]] ; then
245                         eerror "${PN} needs to be built with gcc-4.7 or later."
246                         eerror "Please use gcc-config to switch to gcc-4.7 or later version."
247                         die
248                 fi
249         fi
250 }
251
252 # @FUNCTION: mysql-multilib-r1_pkg_setup
253 # @DESCRIPTION:
254 # Perform some basic tests and tasks during pkg_setup phase:
255 #   die if FEATURES="test", USE="server" and not using FEATURES="userpriv"
256 #   create new user and group for mysql
257 #   warn about deprecated features
258 mysql-multilib-r1_pkg_setup() {
259
260         if has test ${FEATURES} && \
261                 use server && ! has userpriv ${FEATURES} ; then
262                         eerror "Testing with FEATURES=-userpriv is no longer supported by upstream. Tests MUST be run as non-root."
263         fi
264
265         # This should come after all of the die statements
266         enewgroup mysql 60 || die "problem adding 'mysql' group"
267         enewuser mysql 60 -1 /dev/null mysql || die "problem adding 'mysql' user"
268 }
269
270 # @FUNCTION: mysql-multilib-r1_src_unpack
271 # @DESCRIPTION:
272 # Unpack the source code
273 mysql-multilib-r1_src_unpack() {
274
275         # Initialize the proper variables first
276         mysql_init_vars
277
278         unpack ${A}
279         # Grab the patches
280         [[ "${MY_EXTRAS_VER}" == "live" ]] && S="${WORKDIR}/mysql-extras" git-r3_src_unpack
281
282         mv -f "${WORKDIR}/${MY_SOURCEDIR}" "${S}"
283 }
284
285 # @FUNCTION: mysql-multilib-r1_src_prepare
286 # @DESCRIPTION:
287 # Apply patches to the source code and remove unneeded bundled libs.
288 mysql-multilib-r1_src_prepare() {
289
290         debug-print-function ${FUNCNAME} "$@"
291
292         cd "${S}"
293
294         if [[ ${MY_EXTRAS_VER} != none ]]; then
295
296                 # Apply the patches for this MySQL version
297                 if [[ "${EAPI}x" == "5x" ]]; then
298                         EPATCH_SUFFIX="patch"
299                         mkdir -p "${EPATCH_SOURCE}" || die "Unable to create epatch directory"
300                         # Clean out old items
301                         rm -f "${EPATCH_SOURCE}"/*
302                         # Now link in right patches
303                         mysql_mv_patches
304                         # And apply
305                         epatch
306                 fi
307         fi
308
309         # last -fPIC fixup, per bug #305873
310         i="${S}"/storage/innodb_plugin/plug.in
311         if [[ -f ${i} ]] ; then sed -i -e '/CFLAGS/s,-prefer-non-pic,,g' "${i}" || die ; fi
312
313         rm -f "scripts/mysqlbug"
314         if use jemalloc && [[ ${PN} != "mariadb" ]] ; then
315                 echo "TARGET_LINK_LIBRARIES(mysqld jemalloc)" >> "${S}/sql/CMakeLists.txt" || die
316         fi
317
318         if use tcmalloc; then
319                 echo "TARGET_LINK_LIBRARIES(mysqld tcmalloc)" >> "${S}/sql/CMakeLists.txt"
320         fi
321
322         if in_iuse tokudb ; then
323                 # Don't build bundled xz-utils
324                 if [[ -d "${S}/storage/tokudb/ft-index" ]] ; then
325                         echo > "${S}/storage/tokudb/ft-index/cmake_modules/TokuThirdParty.cmake" || die
326                         sed -i 's/ build_lzma//' "${S}/storage/tokudb/ft-index/ft/CMakeLists.txt" || die
327                 elif [[ -d "${S}/storage/tokudb/PerconaFT" ]] ; then
328                         echo > "${S}/storage/tokudb/PerconaFT/cmake_modules/TokuThirdParty.cmake" || die
329                         sed -i -e 's/ build_lzma//' -e 's/ build_snappy//' "${S}/storage/tokudb/PerconaFT/ft/CMakeLists.txt" || die
330                         sed -i -e 's/add_dependencies\(tokuportability_static_conv build_jemalloc\)//' "${S}/storage/tokudb/PerconaFT/portability/CMakeLists.txt" || die
331                 fi
332
333                 if [[ -d "${S}/plugin/tokudb-backup-plugin" ]] && ! use tokudb-backup-plugin ; then
334                          rm -r "${S}/plugin/tokudb-backup-plugin/Percona-TokuBackup" || die
335                 fi
336         fi
337
338         # Remove the bundled groonga if it exists
339         # There is no CMake flag, it simply checks for existance
340         if [[ -d "${S}"/storage/mroonga/vendor/groonga ]] ; then
341                 rm -r "${S}"/storage/mroonga/vendor/groonga || die "could not remove packaged groonga"
342         fi
343
344         # Remove the centos and rhel selinux policies to support mysqld_safe under SELinux
345         if [[ -d "${S}/support-files/SELinux" ]] ; then
346                 echo > "${S}/support-files/SELinux/CMakeLists.txt" || die
347         fi
348
349         cmake-utils_src_prepare
350 }
351
352 # @FUNCTION: mysql-multilib-r1_src_configure
353 # @DESCRIPTION:
354 # Configure mysql to build the code for Gentoo respecting the use flags.
355 mysql-multilib-r1_src_configure() {
356         # Bug #114895, bug #110149
357         filter-flags "-O" "-O[01]"
358
359         append-cxxflags -felide-constructors
360
361         # bug #283926, with GCC4.4, this is required to get correct behavior.
362         append-flags -fno-strict-aliasing
363
364         multilib-minimal_src_configure
365 }
366
367 multilib_src_configure() {
368         debug-print-function ${FUNCNAME} "$@"
369
370         CMAKE_BUILD_TYPE="RelWithDebInfo"
371
372         # debug hack wrt #497532
373         mycmakeargs=(
374                 -DCMAKE_C_FLAGS_RELWITHDEBINFO="$(usex debug '' '-DNDEBUG')"
375                 -DCMAKE_CXX_FLAGS_RELWITHDEBINFO="$(usex debug '' '-DNDEBUG')"
376                 -DCMAKE_INSTALL_PREFIX=${EPREFIX}/usr
377                 -DMYSQL_DATADIR=${EPREFIX}/var/lib/mysql
378                 -DSYSCONFDIR=${EPREFIX}/etc/mysql
379                 -DINSTALL_BINDIR=bin
380                 -DINSTALL_DOCDIR=share/doc/${PF}
381                 -DINSTALL_DOCREADMEDIR=share/doc/${PF}
382                 -DINSTALL_INCLUDEDIR=include/mysql
383                 -DINSTALL_INFODIR=share/info
384                 -DINSTALL_LIBDIR=$(get_libdir)
385                 -DINSTALL_ELIBDIR=$(get_libdir)/mysql
386                 -DINSTALL_MANDIR=share/man
387                 -DINSTALL_MYSQLDATADIR=${EPREFIX}/var/lib/mysql
388                 -DINSTALL_MYSQLSHAREDIR=share/mysql
389                 -DINSTALL_PLUGINDIR=$(get_libdir)/mysql/plugin
390                 -DINSTALL_SBINDIR=sbin
391                 -DINSTALL_SCRIPTDIR=share/mysql/scripts
392                 -DINSTALL_SQLBENCHDIR=share/mysql
393                 -DINSTALL_SUPPORTFILESDIR=${EPREFIX}/usr/share/mysql
394                 -DWITH_COMMENT="Gentoo Linux ${PF}"
395                 -DWITH_UNIT_TESTS=$(usex test ON OFF)
396                 -DWITH_LIBEDIT=0
397                 -DWITH_ZLIB=system
398                 -DWITHOUT_LIBWRAP=1
399                 -DENABLED_LOCAL_INFILE=1
400                 -DMYSQL_UNIX_ADDR=${EPREFIX}/var/run/mysqld/mysqld.sock
401                 -DINSTALL_UNIX_ADDRDIR=${EPREFIX}/var/run/mysqld/mysqld.sock
402                 -DWITH_DEFAULT_COMPILER_OPTIONS=0
403                 -DWITH_DEFAULT_FEATURE_SET=0
404                 -DINSTALL_SYSTEMD_UNITDIR="$(systemd_get_systemunitdir)"
405                 -DENABLE_STATIC_LIBS=$(usex static-libs ON OFF)
406                 # The build forces this to be defined when cross-compiling.  We pass it
407                 # all the time for simplicity and to make sure it is actually correct.
408                 -DSTACK_DIRECTION=$(tc-stack-grows-down && echo -1 || echo 1)
409                 -DPKG_CONFIG_EXECUTABLE="${EPREFIX}/usr/bin/$(tc-getPKG_CONFIG)"
410         )
411
412         if use test ; then
413                 mycmakeargs+=( -DINSTALL_MYSQLTESTDIR=share/mysql/mysql-test )
414         else
415                 mycmakeargs+=( -DINSTALL_MYSQLTESTDIR='' )
416         fi
417
418         if use openssl || use libressl ; then
419                 mycmakeargs+=( -DWITH_SSL=system )
420         else
421                 mycmakeargs+=( -DWITH_SSL=bundled )
422         fi
423
424         if ! multilib_is_native_abi ; then
425                 mycmakeargs+=( -DWITHOUT_TOOLS=1 )
426         fi
427
428         if in_iuse bindist ; then
429                 # bfd.h is only used starting with 10.1 and can be controlled by NOT_FOR_DISTRIBUTION
430                 if multilib_is_native_abi; then
431                         mycmakeargs+=(
432                                 -DWITH_READLINE=$(usex bindist 1 0)
433                                 -DNOT_FOR_DISTRIBUTION=$(usex bindist 0 1)
434                         )
435                 else
436                         mycmakeargs+=(
437                                 -DWITH_READLINE=1
438                                 -DNOT_FOR_DISTRIBUTION=0
439                         )
440                 fi
441         fi
442
443         ### TODO: make this system but issues with UTF-8 prevent it
444         mycmakeargs+=( -DWITH_EDITLINE=bundled )
445
446         if multilib_is_native_abi && use server ; then
447
448                 # systemd is only linked to for server notification
449                 if in_iuse systemd ; then
450                         mycmakeargs+=( -DWITH_SYSTEMD=$(usex systemd yes no) )
451                 fi
452
453                 if [[ ( -n ${MYSQL_DEFAULT_CHARSET} ) && ( -n ${MYSQL_DEFAULT_COLLATION} ) ]]; then
454                         ewarn "You are using a custom charset of ${MYSQL_DEFAULT_CHARSET}"
455                         ewarn "and a collation of ${MYSQL_DEFAULT_COLLATION}."
456                         ewarn "You MUST file bugs without these variables set."
457
458                         mycmakeargs+=(
459                                 -DDEFAULT_CHARSET=${MYSQL_DEFAULT_CHARSET}
460                                 -DDEFAULT_COLLATION=${MYSQL_DEFAULT_COLLATION}
461                         )
462
463                 elif ! use latin1 ; then
464                         mycmakeargs+=(
465                                 -DDEFAULT_CHARSET=utf8
466                                 -DDEFAULT_COLLATION=utf8_general_ci
467                         )
468                 else
469                         mycmakeargs+=(
470                                 -DDEFAULT_CHARSET=latin1
471                                 -DDEFAULT_COLLATION=latin1_swedish_ci
472                         )
473                 fi
474                 mycmakeargs+=(
475                         -DEXTRA_CHARSETS=all
476                         -DMYSQL_USER=mysql
477                         -DMYSQL_UNIX_ADDR=${EPREFIX}/var/run/mysqld/mysqld.sock
478                         -DDISABLE_SHARED=$(usex static YES NO)
479                         -DWITH_DEBUG=$(usex debug)
480                         -DWITH_EMBEDDED_SERVER=$(usex embedded)
481                         -DWITH_PROFILING=$(usex profiling)
482                 )
483
484                 if use static; then
485                         mycmakeargs+=( -DWITH_PIC=1 )
486                 fi
487
488                 if use jemalloc || use tcmalloc ; then
489                         mycmakeargs+=( -DWITH_SAFEMALLOC=OFF )
490                 fi
491
492                 # Storage engines
493                 mycmakeargs+=(
494                         -DWITH_ARCHIVE_STORAGE_ENGINE=1
495                         -DWITH_BLACKHOLE_STORAGE_ENGINE=1
496                         -DWITH_CSV_STORAGE_ENGINE=1
497                         -DWITH_HEAP_STORAGE_ENGINE=1
498                         -DWITH_INNOBASE_STORAGE_ENGINE=1
499                         -DWITH_MYISAMMRG_STORAGE_ENGINE=1
500                         -DWITH_MYISAM_STORAGE_ENGINE=1
501                         -DWITH_PARTITION_STORAGE_ENGINE=1
502                 )
503
504                 mycmakeargs+=( -DWITH_FEDERATED_STORAGE_ENGINE=$(usex extraengine) )
505         else
506                 mycmakeargs+=(
507                         -DWITHOUT_SERVER=1
508                         -DWITHOUT_EMBEDDED_SERVER=1
509                         -DEXTRA_CHARSETS=none
510                         -DINSTALL_SQLBENCHDIR=
511                         -DWITH_SYSTEMD=no
512                 )
513         fi
514
515         # systemtap only works on native ABI  bug 530132
516         if multilib_is_native_abi; then
517                 mycmakeargs+=( -DENABLE_DTRACE=$(usex systemtap)
518                         "${MYSQL_CMAKE_NATIVE_DEFINES[@]}" )
519         else
520                 mycmakeargs+=( -DENABLE_DTRACE=0
521                         "${MYSQL_CMAKE_NONNATIVE_DEFINES[@]}" )
522         fi
523
524         mycmakeargs+=( "${MYSQL_CMAKE_EXTRA_DEFINES[@]}" )
525
526         cmake-utils_src_configure
527 }
528
529 mysql-multilib-r1_src_compile() {
530         local _cmake_args=( "${@}" )
531
532         multilib-minimal_src_compile
533 }
534
535 multilib_src_compile() {
536
537         cmake-utils_src_compile "${_cmake_args[@]}"
538 }
539
540
541 # @FUNCTION: mysql-multilib-r1_src_install
542 # @DESCRIPTION:
543 # Install mysql.
544 mysql-multilib-r1_src_install() {
545         # wrap the config script
546         MULTILIB_CHOST_TOOLS=( /usr/bin/mysql_config )
547
548         multilib-minimal_src_install
549 }
550
551 multilib_src_install() {
552         debug-print-function ${FUNCNAME} "$@"
553
554         cmake-utils_src_install
555         # Make sure the vars are correctly initialized
556         mysql_init_vars
557
558         # Remove an unnecessary, private config header which will never match between ABIs and is not meant to be used
559         if [[ -f "${D}${MY_INCLUDEDIR}/private/config.h" ]] ; then
560                 rm "${D}${MY_INCLUDEDIR}/private/config.h" || die
561         fi
562
563         if multilib_is_native_abi; then
564
565                 # Convenience links
566                 einfo "Making Convenience links for mysqlcheck multi-call binary"
567                 dosym "/usr/bin/mysqlcheck" "/usr/bin/mysqlanalyze"
568                 dosym "/usr/bin/mysqlcheck" "/usr/bin/mysqlrepair"
569                 dosym "/usr/bin/mysqlcheck" "/usr/bin/mysqloptimize"
570
571                 # INSTALL_LAYOUT=STANDALONE causes cmake to create a /usr/data dir
572                 if [[ -d "${ED}/usr/data" ]] ; then
573                         rm -Rf "${ED}/usr/data" || die
574                 fi
575
576                 # Unless they explicitly specific USE=test, then do not install the
577                 # testsuite. It DOES have a use to be installed, esp. when you want to do a
578                 # validation of your database configuration after tuning it.
579                 if ! use test ; then
580                         rm -rf "${D}"/${MY_SHAREDSTATEDIR}/mysql-test
581                 fi
582
583                 # Configuration stuff
584                 case ${MYSQL_PV_MAJOR} in
585                         5.5) mysql_mycnf_version="5.5" ;;
586                         5.[6-9]|6*|7*|8*|9*|10*) mysql_mycnf_version="5.6" ;;
587                 esac
588                 einfo "Building default my.cnf (${mysql_mycnf_version})"
589                 insinto "${MY_SYSCONFDIR#${EPREFIX}}"
590                 [[ -f "${S}/scripts/mysqlaccess.conf" ]] && doins "${S}"/scripts/mysqlaccess.conf
591                 mycnf_src="my.cnf-${mysql_mycnf_version}"
592                 sed -e "s!@DATADIR@!${MY_DATADIR}!g" \
593                         "${FILESDIR}/${mycnf_src}" \
594                         > "${TMPDIR}/my.cnf.ok" || die
595                 use prefix && sed -i -r -e '/^user[[:space:]]*=[[:space:]]*mysql$/d' "${TMPDIR}/my.cnf.ok"
596                 if use latin1 ; then
597                         sed -i \
598                                 -e "/character-set/s|utf8|latin1|g" \
599                                 "${TMPDIR}/my.cnf.ok" || die
600                 fi
601                 eprefixify "${TMPDIR}/my.cnf.ok"
602                 newins "${TMPDIR}/my.cnf.ok" my.cnf
603
604                 if use server ; then
605                         einfo "Including support files and sample configurations"
606                         docinto "support-files"
607                         for script in \
608                                 "${S}"/support-files/my-*.cnf.sh \
609                                 "${S}"/support-files/magic \
610                                 "${S}"/support-files/ndb-config-2-node.ini.sh
611                         do
612                                 [[ -f $script ]] && dodoc "${script}"
613                         done
614
615                         docinto "scripts"
616                         for script in "${S}"/scripts/mysql* ; do
617                                 [[ ( -f $script ) && ( ${script%.sh} == ${script} ) ]] && dodoc "${script}"
618                         done
619                 fi
620
621                 #Remove mytop if perl is not selected
622                 [[ -e "${ED}/usr/bin/mytop" ]] && ! use perl && rm -f "${ED}/usr/bin/mytop"
623
624                 # Percona has decided to rename libmysqlclient to libperconaserverclient
625                 # Use a symlink to preserve linkages for those who don't use mysql_config
626                 local suffix
627                 for suffix in ".so" "_r.so" ".a" "_r.a" ; do
628                         if [[ -e "${ED}/usr/$(get_libdir)/libperconaserverclient${suffix}" ]] ; then
629                                 dosym libperconaserverclient${suffix} /usr/$(get_libdir)/libmysqlclient${suffix}
630                         fi
631                 done
632         else
633                 if [[ "${PN}" == "mariadb" ]] && use server ; then
634                         insinto /usr/include/mysql/private
635                         doins "${S}"/sql/*.h
636                 fi
637         fi
638 }
639
640 # @FUNCTION: mysql-multilib-r1_pkg_preinst
641 # @DESCRIPTION:
642 # Warn about ABI changes when switching providers
643 mysql-multilib-r1_pkg_preinst() {
644         debug-print-function ${FUNCNAME} "$@"
645
646         # Here we need to see if the implementation switched client libraries
647         # We check if this is a new instance of the package and a client library already exists
648         local SHOW_ABI_MESSAGE
649         if [[ -z ${REPLACING_VERSIONS} && -e "${EROOT}usr/$(get_libdir)/libmysqlclient.so" ]] ; then
650                 elog "Due to ABI changes when switching between different client libraries,"
651                 elog "revdep-rebuild must find and rebuild all packages linking to libmysqlclient."
652                 elog "Please run: revdep-rebuild --library libmysqlclient.so.${SUBSLOT:-18}"
653                 ewarn "Failure to run revdep-rebuild may cause issues with other programs or libraries"
654         fi
655 }
656
657 # @FUNCTION: mysql-multilib-r1_pkg_postinst
658 # @DESCRIPTION:
659 # Run post-installation tasks:
660 #   create the dir for logfiles if non-existant
661 #   touch the logfiles and secure them
662 #   install scripts
663 #   issue required steps for optional features
664 #   issue deprecation warnings
665 mysql-multilib-r1_pkg_postinst() {
666         debug-print-function ${FUNCNAME} "$@"
667
668         # Make sure the vars are correctly initialized
669         mysql_init_vars
670
671         # Create log directory securely if it does not exist
672         [[ -d "${ROOT}${MY_LOGDIR}" ]] || install -d -m0750 -o mysql -g mysql "${ROOT}${MY_LOGDIR}"
673
674         if use server ; then
675                 docinto "support-files"
676                 for script in \
677                         support-files/my-*.cnf \
678                         support-files/magic \
679                         support-files/ndb-config-2-node.ini
680                 do
681                         [[ -f "${script}" ]] \
682                         && dodoc "${script}"
683                 done
684
685                 docinto "scripts"
686                 for script in scripts/mysql* ; do
687                         if [[ -f "${script}" && "${script%.sh}" == "${script}" ]]; then
688                                 dodoc "${script}"
689                         fi
690                 done
691
692                 if in_iuse pam && use pam; then
693                         einfo
694                         elog "This install includes the PAM authentication plugin."
695                         elog "To activate and configure the PAM plugin, please read:"
696                         if [[ ${PN} == "mariadb" ]] ; then
697                                 elog "https://mariadb.com/kb/en/mariadb/pam-authentication-plugin/"
698                         elif [[ ${PN} == "percona-server" ]] ; then
699                                 elog "https://www.percona.com/doc/percona-server/5.6/management/pam_plugin.html"
700                         fi
701                         einfo
702                 fi
703
704                 if [[ -z "${REPLACING_VERSIONS}" ]] ; then
705                         einfo
706                         elog "You might want to run:"
707                         elog "\"emerge --config =${CATEGORY}/${PF}\""
708                         elog "if this is a new install."
709                         elog
710                         elog "If you are switching server implentations, you should run the"
711                         elog "mysql_upgrade tool."
712                         einfo
713                 else
714                         einfo
715                         elog "If you are upgrading major versions, you should run the"
716                         elog "mysql_upgrade tool."
717                         einfo
718                 fi
719
720                 if in_iuse galera && use galera ; then
721                         einfo
722                         elog "Be sure to edit the my.cnf file to activate your cluster settings."
723                         elog "This should be done after running \"emerge --config =${CATEGORY}/${PF}\""
724                         elog "The first time the cluster is activated, you should add"
725                         elog "--wsrep-new-cluster to the options in /etc/conf.d/mysql for one node."
726                         elog "This option should then be removed for subsequent starts."
727                         einfo
728                 fi
729         fi
730 }
731
732 # @FUNCTION: mysql-multilib-r1_getopt
733 # @DESCRIPTION:
734 # Use my_print_defaults to extract specific config options
735 mysql-multilib-r1_getopt() {
736         local mypd="${EROOT}"/usr/bin/my_print_defaults
737         section="$1"
738         flag="--${2}="
739         "${mypd}" $section | sed -n "/^${flag}/p"
740 }
741
742 # @FUNCTION: mysql-multilib-r1_getoptval
743 # @DESCRIPTION:
744 # Use my_print_defaults to extract specific config options
745 mysql-multilib-r1_getoptval() {
746         local mypd="${EROOT}"/usr/bin/my_print_defaults
747         local section="$1"
748         local flag="--${2}="
749         local extra_options="${3}"
750         "${mypd}" $extra_options $section | sed -n "/^${flag}/s,${flag},,gp"
751 }
752
753 # @FUNCTION: mysql-multilib-r1_pkg_config
754 # @DESCRIPTION:
755 # Configure mysql environment.
756 mysql-multilib-r1_pkg_config() {
757
758         debug-print-function ${FUNCNAME} "$@"
759
760         local old_MY_DATADIR="${MY_DATADIR}"
761         local old_HOME="${HOME}"
762         # my_print_defaults needs to read stuff in $HOME/.my.cnf
763         export HOME=${EPREFIX}/root
764
765         # Make sure the vars are correctly initialized
766         mysql_init_vars
767
768         [[ -z "${MY_DATADIR}" ]] && die "Sorry, unable to find MY_DATADIR"
769         if [[ ! -x "${EROOT}/usr/sbin/mysqld" ]] ; then
770                 die "Minimal builds do NOT include the MySQL server"
771         fi
772
773         if [[ ( -n "${MY_DATADIR}" ) && ( "${MY_DATADIR}" != "${old_MY_DATADIR}" ) ]]; then
774                 local MY_DATADIR_s="${ROOT}/${MY_DATADIR}"
775                 MY_DATADIR_s="${MY_DATADIR_s%%/}"
776                 local old_MY_DATADIR_s="${ROOT}/${old_MY_DATADIR}"
777                 old_MY_DATADIR_s="${old_MY_DATADIR_s%%/}"
778
779                 if [[ ( -d "${old_MY_DATADIR_s}" ) && ( "${old_MY_DATADIR_s}" != / ) ]]; then
780                         if [[ -d "${MY_DATADIR_s}" ]]; then
781                                 ewarn "Both ${old_MY_DATADIR_s} and ${MY_DATADIR_s} exist"
782                                 ewarn "Attempting to use ${MY_DATADIR_s} and preserving ${old_MY_DATADIR_s}"
783                         else
784                                 elog "Moving MY_DATADIR from ${old_MY_DATADIR_s} to ${MY_DATADIR_s}"
785                                 mv --strip-trailing-slashes -T "${old_MY_DATADIR_s}" "${MY_DATADIR_s}" \
786                                 || die "Moving MY_DATADIR failed"
787                         fi
788                 else
789                         ewarn "Previous MY_DATADIR (${old_MY_DATADIR_s}) does not exist"
790                         if [[ -d "${MY_DATADIR_s}" ]]; then
791                                 ewarn "Attempting to use ${MY_DATADIR_s}"
792                         else
793                                 eerror "New MY_DATADIR (${MY_DATADIR_s}) does not exist"
794                                 die "Configuration Failed! Please reinstall ${CATEGORY}/${PN}"
795                         fi
796                 fi
797         fi
798
799         local pwd1="a"
800         local pwd2="b"
801         local maxtry=15
802
803         if [ -z "${MYSQL_ROOT_PASSWORD}" ]; then
804                 local tmp_mysqld_password_source=
805
806                 for tmp_mysqld_password_source in mysql client; do
807                         einfo "Trying to get password for mysql 'root' user from '${tmp_mysqld_password_source}' section ..."
808                         MYSQL_ROOT_PASSWORD="$(mysql-multilib-r1_getoptval "${tmp_mysqld_password_source}" password)"
809                         if [[ -n "${MYSQL_ROOT_PASSWORD}" ]]; then
810                                 if [[ ${MYSQL_ROOT_PASSWORD} == *$'\n'* ]]; then
811                                         ewarn "Ignoring password from '${tmp_mysqld_password_source}' section due to newline character (do you have multiple password options set?)!"
812                                         MYSQL_ROOT_PASSWORD=
813                                         continue
814                                 fi
815
816                                 einfo "Found password in '${tmp_mysqld_password_source}' section!"
817                                 break
818                         fi
819                 done
820
821                 # Sometimes --show is required to display passwords in some implementations of my_print_defaults
822                 if [[ "${MYSQL_ROOT_PASSWORD}" == '*****' ]]; then
823                         MYSQL_ROOT_PASSWORD="$(mysql-multilib-r1_getoptval "${tmp_mysqld_password_source}" password --show)"
824                 fi
825
826                 unset tmp_mysqld_password_source
827         fi
828         MYSQL_TMPDIR="$(mysql-multilib-r1_getoptval mysqld tmpdir)"
829         # These are dir+prefix
830         MYSQL_RELAY_LOG="$(mysql-multilib-r1_getoptval mysqld relay-log)"
831         MYSQL_RELAY_LOG=${MYSQL_RELAY_LOG%/*}
832         MYSQL_LOG_BIN="$(mysql-multilib-r1_getoptval mysqld log-bin)"
833         MYSQL_LOG_BIN=${MYSQL_LOG_BIN%/*}
834
835         if [[ ! -d "${ROOT}"/$MYSQL_TMPDIR ]]; then
836                 einfo "Creating MySQL tmpdir $MYSQL_TMPDIR"
837                 install -d -m 770 -o mysql -g mysql "${EROOT}"/$MYSQL_TMPDIR
838         fi
839         if [[ ! -d "${ROOT}"/$MYSQL_LOG_BIN ]]; then
840                 einfo "Creating MySQL log-bin directory $MYSQL_LOG_BIN"
841                 install -d -m 770 -o mysql -g mysql "${EROOT}"/$MYSQL_LOG_BIN
842         fi
843         if [[ ! -d "${EROOT}"/$MYSQL_RELAY_LOG ]]; then
844                 einfo "Creating MySQL relay-log directory $MYSQL_RELAY_LOG"
845                 install -d -m 770 -o mysql -g mysql "${EROOT}"/$MYSQL_RELAY_LOG
846         fi
847
848         if [[ -d "${ROOT}/${MY_DATADIR}/mysql" ]] ; then
849                 ewarn "You have already a MySQL database in place."
850                 ewarn "(${ROOT}/${MY_DATADIR}/*)"
851                 ewarn "Please rename or delete it if you wish to replace it."
852                 die "MySQL database already exists!"
853         fi
854
855         # Bug #213475 - MySQL _will_ object strenously if your machine is named
856         # localhost. Also causes weird failures.
857         [[ "${HOSTNAME}" == "localhost" ]] && die "Your machine must NOT be named localhost"
858
859         if [ -z "${MYSQL_ROOT_PASSWORD}" ]; then
860
861                 einfo "Please provide a password for the mysql 'root' user now"
862                 einfo "or through the ${HOME}/.my.cnf file."
863                 ewarn "Avoid [\"'\\_%] characters in the password"
864                 read -rsp "    >" pwd1 ; echo
865
866                 einfo "Retype the password"
867                 read -rsp "    >" pwd2 ; echo
868
869                 if [[ "x$pwd1" != "x$pwd2" ]] ; then
870                         die "Passwords are not the same"
871                 fi
872                 MYSQL_ROOT_PASSWORD="${pwd1}"
873                 unset pwd1 pwd2
874         fi
875
876         local options
877         local sqltmp="$(emktemp)"
878
879         # Fix bug 446200. Don't reference host my.cnf, needs to come first,
880         # see http://bugs.mysql.com/bug.php?id=31312
881         use prefix && options="${options} '--defaults-file=${MY_SYSCONFDIR}/my.cnf'"
882
883         local help_tables="${ROOT}${MY_SHAREDSTATEDIR}/fill_help_tables.sql"
884         [[ -r "${help_tables}" ]] \
885         && cp "${help_tables}" "${TMPDIR}/fill_help_tables.sql" \
886         || touch "${TMPDIR}/fill_help_tables.sql"
887         help_tables="${TMPDIR}/fill_help_tables.sql"
888
889         # Figure out which options we need to disable to do the setup
890         local helpfile="${TMPDIR}/mysqld-help"
891         ${EROOT}/usr/sbin/mysqld --verbose --help >"${helpfile}" 2>/dev/null
892         for opt in grant-tables host-cache name-resolve networking slave-start \
893                 federated ssl log-bin relay-log slow-query-log external-locking \
894                 ndbcluster log-slave-updates wsrep-on \
895                 ; do
896                 optexp="--(skip-)?${opt}" optfull="--loose-skip-${opt}"
897                 egrep -sq -- "${optexp}" "${helpfile}" && options="${options} ${optfull}"
898         done
899         # But some options changed names
900         egrep -sq external-locking "${helpfile}" && \
901         options="${options/skip-locking/skip-external-locking}"
902
903         einfo "Creating the mysql database and setting proper permissions on it ..."
904
905         # Now that /var/run is a tmpfs mount point, we need to ensure it exists before using it
906         PID_DIR="${EROOT}/var/run/mysqld"
907         if [[ ! -d "${PID_DIR}" ]]; then
908                 install -d -m 755 -o mysql -g mysql "${PID_DIR}" || die "Could not create pid directory"
909         fi
910
911         if [[ ! -d "${MY_DATADIR}" ]]; then
912                 install -d -m 750 -o mysql -g mysql "${MY_DATADIR}" || die "Could not create data directory"
913         fi
914
915         pushd "${TMPDIR}" &>/dev/null || die
916
917         # Filling timezones, see
918         # http://dev.mysql.com/doc/mysql/en/time-zone-support.html
919         "${EROOT}/usr/bin/mysql_tzinfo_to_sql" "${EROOT}/usr/share/zoneinfo" > "${sqltmp}" 2>/dev/null
920
921         local cmd
922         local initialize_options
923         if [[ ${PN} == "mysql" || ${PN} == "percona-server" ]] && version_is_at_least "5.7.6" ; then
924                 # --initialize-insecure will not set root password
925                 # --initialize would set a random one in the log which we don't need as we set it ourselves
926                 cmd=( "${EROOT}usr/sbin/mysqld" )
927                 initialize_options="--initialize-insecure  --init-file='${sqltmp}'"
928                 sqltmp="" # the initialize will take care of it
929         else
930                 cmd=( "${EROOT}usr/share/mysql/scripts/mysql_install_db" )
931                 [[ -f "${cmd}" ]] || cmd=( "${EROOT}usr/bin/mysql_install_db" )
932                 if [[ -r "${help_tables}" ]] ; then
933                         cat "${help_tables}" >> "${sqltmp}"
934                 fi
935         fi
936         cmd+=( "--basedir=${EPREFIX}/usr" ${options} "--datadir=${ROOT}/${MY_DATADIR}" "--tmpdir=${ROOT}/${MYSQL_TMPDIR}" ${initialize_options} )
937         einfo "Command: ${cmd[*]}"
938         su -s /bin/sh -c "${cmd[*]}" mysql \
939                 >"${TMPDIR}"/mysql_install_db.log 2>&1
940         if [ $? -ne 0 ]; then
941                 grep -B5 -A999 -i "ERROR" "${TMPDIR}"/mysql_install_db.log 1>&2
942                 die "Failed to initialize mysqld. Please review ${EPREFIX}/var/log/mysql/mysqld.err AND ${TMPDIR}/mysql_install_db.log"
943         fi
944         popd &>/dev/null || die
945         [[ -f "${ROOT}/${MY_DATADIR}/mysql/user.frm" ]] \
946         || die "MySQL databases not installed"
947
948         local socket="${EROOT}/var/run/mysqld/mysqld${RANDOM}.sock"
949         local pidfile="${EROOT}/var/run/mysqld/mysqld${RANDOM}.pid"
950         local mysqld="${EROOT}/usr/sbin/mysqld \
951                 ${options} \
952                 $(use prefix || echo --user=mysql) \
953                 --log-warnings=0 \
954                 --basedir=${EROOT}/usr \
955                 --datadir=${ROOT}/${MY_DATADIR} \
956                 --max_allowed_packet=8M \
957                 --net_buffer_length=16K \
958                 --default-storage-engine=MyISAM \
959                 --socket=${socket} \
960                 --pid-file=${pidfile}
961                 --tmpdir=${ROOT}/${MYSQL_TMPDIR}"
962         #einfo "About to start mysqld: ${mysqld}"
963         ebegin "Starting mysqld"
964         einfo "Command ${mysqld}"
965         ${mysqld} &
966         rc=$?
967         while ! [[ -S "${socket}" || "${maxtry}" -lt 1 ]] ; do
968                 maxtry=$((${maxtry}-1))
969                 echo -n "."
970                 sleep 1
971         done
972         eend $rc
973
974         if ! [[ -S "${socket}" ]]; then
975                 die "Completely failed to start up mysqld with: ${mysqld}"
976         fi
977
978         ebegin "Setting root password"
979         # Do this from memory, as we don't want clear text passwords in temp files
980         local sql="UPDATE mysql.user SET Password = PASSWORD('${MYSQL_ROOT_PASSWORD}') WHERE USER='root'; FLUSH PRIVILEGES"
981         "${EROOT}/usr/bin/mysql" \
982                 --socket=${socket} \
983                 -hlocalhost \
984                 -e "${sql}"
985         eend $?
986
987         if [[ -n "${sqltmp}" ]] ; then
988                 ebegin "Loading \"zoneinfo\", this step may require a few seconds"
989                 "${EROOT}/usr/bin/mysql" \
990                         --socket=${socket} \
991                         -hlocalhost \
992                         -uroot \
993                         --password="${MYSQL_ROOT_PASSWORD}" \
994                         mysql < "${sqltmp}"
995                 rc=$?
996                 eend $?
997                 [[ $rc -ne 0 ]] && ewarn "Failed to load zoneinfo!"
998         fi
999
1000         # Stop the server and cleanup
1001         einfo "Stopping the server ..."
1002         kill $(< "${pidfile}" )
1003         rm -f "${sqltmp}"
1004         wait %1
1005         einfo "Done"
1006 }
1007
1008
1009 #
1010 # HELPER FUNCTIONS:
1011 #
1012
1013 # @FUNCTION: mysql-multilib-r1_disable_test
1014 # @DESCRIPTION:
1015 # Helper function to disable specific tests.
1016 mysql-multilib-r1_disable_test() {
1017
1018         local rawtestname testname testsuite reason mysql_disabled_file mysql_disabled_dir
1019         rawtestname="${1}" ; shift
1020         reason="${@}"
1021         ewarn "test '${rawtestname}' disabled: '${reason}'"
1022
1023         testsuite="${rawtestname/.*}"
1024         testname="${rawtestname/*.}"
1025         for mysql_disabled_file in \
1026                 ${S}/mysql-test/disabled.def \
1027                 ${S}/mysql-test/t/disabled.def ; do
1028                 [[ -f ${mysql_disabled_file} ]] && break
1029         done
1030         #mysql_disabled_file="${S}/mysql-test/t/disabled.def"
1031         #einfo "rawtestname=${rawtestname} testname=${testname} testsuite=${testsuite}"
1032         echo ${testname} : ${reason} >> "${mysql_disabled_file}"
1033
1034         if [[ ( -n ${testsuite} ) && ( ${testsuite} != "main" ) ]]; then
1035                 for mysql_disabled_file in \
1036                         ${S}/mysql-test/suite/${testsuite}/disabled.def \
1037                         ${S}/mysql-test/suite/${testsuite}/t/disabled.def \
1038                         FAILED ; do
1039                         [[ -f ${mysql_disabled_file} ]] && break
1040                 done
1041                 if [[ ${mysql_disabled_file} != "FAILED" ]]; then
1042                         echo "${testname} : ${reason}" >> "${mysql_disabled_file}"
1043                 else
1044                         for mysql_disabled_dir in \
1045                                 ${S}/mysql-test/suite/${testsuite} \
1046                                 ${S}/mysql-test/suite/${testsuite}/t \
1047                                 FAILED ; do
1048                                 [[ -d ${mysql_disabled_dir} ]] && break
1049                         done
1050                         if [[ ${mysql_disabled_dir} != "FAILED" ]]; then
1051                                 echo "${testname} : ${reason}" >> "${mysql_disabled_dir}/disabled.def"
1052                         else
1053                                 ewarn "Could not find testsuite disabled.def location for ${rawtestname}"
1054                         fi
1055                 fi
1056         fi
1057 }
1058
1059 # @FUNCTION: mysql-cmake_use_plugin
1060 # @DESCRIPTION:
1061 # Helper function to enable/disable plugins by use flags
1062 # cmake-utils_use_with is not enough as some references check WITH_ (0|1)
1063 # and some check WITHOUT_. Also, this can easily extend to non-storage plugins.
1064 mysql-cmake_use_plugin() {
1065         [[ -z $2 ]] && die "mysql-cmake_use_plugin <USE flag> <flag name>"
1066         if in_iuse $1 && use $1 ; then
1067                 echo "-DWITH_$2=1 -DPLUGIN_$2=YES"
1068         else
1069                 echo "-DWITHOUT_$2=1 -DWITH_$2=0 -DPLUGIN_$2=NO"
1070         fi
1071 }
1072
1073 # @FUNCTION: mysql_init_vars
1074 # @DESCRIPTION:
1075 # void mysql_init_vars()
1076 # Initialize global variables
1077 # 2005-11-19 <vivo@gentoo.org>
1078 if [[ "${EAPI}x" != "5x" ]]; then
1079
1080 mysql_init_vars() {
1081         MY_SHAREDSTATEDIR=${MY_SHAREDSTATEDIR="${EPREFIX}/usr/share/mysql"}
1082         MY_SYSCONFDIR=${MY_SYSCONFDIR="${EPREFIX}/etc/mysql"}
1083         MY_LOCALSTATEDIR=${MY_LOCALSTATEDIR="${EPREFIX}/var/lib/mysql"}
1084         MY_LOGDIR=${MY_LOGDIR="${EPREFIX}/var/log/mysql"}
1085         MY_INCLUDEDIR=${MY_INCLUDEDIR="${EPREFIX}/usr/include/mysql"}
1086         MY_LIBDIR=${MY_LIBDIR="${EPREFIX}/usr/$(get_libdir)/mysql"}
1087
1088         if [[ -z "${MY_DATADIR}" ]] ; then
1089                 MY_DATADIR=""
1090                 if [[ -f "${MY_SYSCONFDIR}/my.cnf" ]] ; then
1091                         MY_DATADIR=`"my_print_defaults" mysqld 2>/dev/null \
1092                                 | sed -ne '/datadir/s|^--datadir=||p' \
1093                                 | tail -n1`
1094                         if [[ -z "${MY_DATADIR}" ]] ; then
1095                                 MY_DATADIR=`grep ^datadir "${MY_SYSCONFDIR}/my.cnf" \
1096                                 | sed -e 's/.*=\s*//' \
1097                                 | tail -n1`
1098                         fi
1099                 fi
1100                 if [[ -z "${MY_DATADIR}" ]] ; then
1101                         MY_DATADIR="${MY_LOCALSTATEDIR}"
1102                         einfo "Using default MY_DATADIR"
1103                 fi
1104                 elog "MySQL MY_DATADIR is ${MY_DATADIR}"
1105
1106                 if [[ -z "${PREVIOUS_DATADIR}" ]] ; then
1107                         if [[ -e "${MY_DATADIR}" ]] ; then
1108                                 # If you get this and you're wondering about it, see bug #207636
1109                                 elog "MySQL datadir found in ${MY_DATADIR}"
1110                                 elog "A new one will not be created."
1111                                 PREVIOUS_DATADIR="yes"
1112                         else
1113                                 PREVIOUS_DATADIR="no"
1114                         fi
1115                         export PREVIOUS_DATADIR
1116                 fi
1117         else
1118                 if [[ ${EBUILD_PHASE} == "config" ]]; then
1119                         local new_MY_DATADIR
1120                         new_MY_DATADIR=`"my_print_defaults" mysqld 2>/dev/null \
1121                                 | sed -ne '/datadir/s|^--datadir=||p' \
1122                                 | tail -n1`
1123
1124                         if [[ ( -n "${new_MY_DATADIR}" ) && ( "${new_MY_DATADIR}" != "${MY_DATADIR}" ) ]]; then
1125                                 ewarn "MySQL MY_DATADIR has changed"
1126                                 ewarn "from ${MY_DATADIR}"
1127                                 ewarn "to ${new_MY_DATADIR}"
1128                                 MY_DATADIR="${new_MY_DATADIR}"
1129                         fi
1130                 fi
1131         fi
1132
1133         if [ "${MY_SOURCEDIR:-unset}" == "unset" ]; then
1134                 MY_SOURCEDIR=${SERVER_URI##*/}
1135                 MY_SOURCEDIR=${MY_SOURCEDIR%.tar*}
1136         fi
1137
1138         export MY_SHAREDSTATEDIR MY_SYSCONFDIR
1139         export MY_LIBDIR MY_LOCALSTATEDIR MY_LOGDIR
1140         export MY_INCLUDEDIR MY_DATADIR MY_SOURCEDIR
1141 }
1142 fi