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