1 # Copyright 1999-2017 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: mysql-multilib-r1.eclass
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
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
22 # @ECLASS-VARIABLE: MYSQL_EXTRAS_VER
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"
29 # @ECLASS-VARIABLE: MYSQL_CMAKE_NATIVE_DEFINES
32 # An array of extra CMake arguments for native multilib builds
34 # @ECLASS-VARIABLE: MYSQL_CMAKE_NONNATIVE_DEFINES
37 # An array of extra CMake arguments for non-native multilib builds
39 # @ECLASS-VARIABLE: MYSQL_CMAKE_EXTRA_DEFINES
42 # An array of CMake arguments added to native and non-native
44 # Keeping eutils in EAPI=6 for emktemp in pkg_config
46 inherit eutils systemd flag-o-matic ${MYSQL_EXTRAS} versionator \
47 prefix toolchain-funcs user cmake-utils multilib-minimal
49 if [[ "${EAPI}x" == "5x" ]]; then
50 inherit multilib mysql_fx
54 # Supported EAPI versions and export functions
59 *) die "Unsupported EAPI: ${EAPI}" ;;
62 EXPORT_FUNCTIONS pkg_pretend pkg_setup src_unpack src_prepare src_configure src_compile src_install pkg_preinst pkg_postinst pkg_config
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
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
79 # @ECLASS-VARIABLE: MYSQL_PV_MAJOR
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
84 if [[ -z ${MYSQL_PV_MAJOR} ]] ; then MYSQL_PV_MAJOR="$(get_version_component_range 1-2 ${PV})" ; fi
86 # @ECLASS-VARIABLE: MYSQL_VERSION_ID
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
97 tpv=( ${tpv//[-._]/ } ) ; tpv[3]="${PVR:${#PV}}" ; tpv[3]="${tpv[3]##*-r}"
98 for vatom in 0 1 2 3 ; do
100 tpv[${vatom}]="00${tpv[${vatom}]}"
101 MYSQL_VERSION_ID="${MYSQL_VERSION_ID}${tpv[${vatom}]:0-2}"
103 # strip leading "0" (otherwise it's considered an octal number by BASH)
104 MYSQL_VERSION_ID=${MYSQL_VERSION_ID##"0"}
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"
122 if [[ "${PN}" == "mysql-cluster" ]] ; then
123 URI_DIR="MySQL-Cluster"
124 URI_FILE="mysql-cluster-gpl"
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}"
138 # Define correct SRC_URIs
139 SRC_URI="${SERVER_URI}"
141 # Gentoo patches to MySQL
142 if [[ ${MY_EXTRAS_VER} != "live" && ${MY_EXTRAS_VER} != "none" ]]; then
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"
151 DESCRIPTION="A fast, multi-threaded, multi-user SQL database server"
152 HOMEPAGE="https://www.mysql.com/"
154 SLOT="0/${SUBSLOT:-0}"
156 IUSE="debug embedded extraengine jemalloc latin1 libressl +openssl
157 +perl profiling selinux +server systemtap static static-libs tcmalloc test yassl"
159 REQUIRED_USE="^^ ( yassl openssl libressl )"
161 # Tests always fail when libressl is enabled due to hard-coded ciphers in the tests
162 RESTRICT="libressl? ( test )"
164 REQUIRED_USE="${REQUIRED_USE} !server? ( !extraengine !embedded )
165 ?? ( tcmalloc jemalloc )
166 static? ( !libressl !openssl yassl )"
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
177 sys-process/procps:0=
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?]
192 # prefix: first need to implement something for #196294
194 selinux? ( sec-policy/selinux-mysql )
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}"
204 server? ( !prefix? ( dev-db/mysql-init-scripts ) )
205 !<virtual/mysql-5.6-r4"
208 # ncurses only needs multilib for compile time due to a binary that will be not installed
211 static? ( sys-libs/ncurses[static-libs] )
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=]"
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 )
227 # @FUNCTION: mysql-multilib-r1_pkg_pretend
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."
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."
251 # @FUNCTION: mysql-multilib-r1_pkg_setup
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() {
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."
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"
269 # @FUNCTION: mysql-multilib-r1_src_unpack
271 # Unpack the source code
272 mysql-multilib-r1_src_unpack() {
274 # Initialize the proper variables first
279 [[ "${MY_EXTRAS_VER}" == "live" ]] && S="${WORKDIR}/mysql-extras" git-r3_src_unpack
281 mv -f "${WORKDIR}/${MY_SOURCEDIR}" "${S}"
284 # @FUNCTION: mysql-multilib-r1_src_prepare
286 # Apply patches to the source code and remove unneeded bundled libs.
287 mysql-multilib-r1_src_prepare() {
289 debug-print-function ${FUNCNAME} "$@"
293 if [[ ${MY_EXTRAS_VER} != none ]]; then
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
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
312 rm -f "scripts/mysqlbug"
313 if use jemalloc && [[ ${PN} != "mariadb" ]] ; then
314 echo "TARGET_LINK_LIBRARIES(mysqld jemalloc)" >> "${S}/sql/CMakeLists.txt" || die
317 if use tcmalloc; then
318 echo "TARGET_LINK_LIBRARIES(mysqld tcmalloc)" >> "${S}/sql/CMakeLists.txt"
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
332 if [[ -d "${S}/plugin/tokudb-backup-plugin" ]] && ! use tokudb-backup-plugin ; then
333 rm -r "${S}/plugin/tokudb-backup-plugin/Percona-TokuBackup" || die
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"
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
348 cmake-utils_src_prepare
351 # @FUNCTION: mysql-multilib-r1_src_configure
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]"
358 append-cxxflags -felide-constructors
360 # bug #283926, with GCC4.4, this is required to get correct behavior.
361 append-flags -fno-strict-aliasing
363 multilib-minimal_src_configure
366 multilib_src_configure() {
367 debug-print-function ${FUNCNAME} "$@"
369 CMAKE_BUILD_TYPE="RelWithDebInfo"
371 # debug hack wrt #497532
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
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)
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)"
412 mycmakeargs+=( -DINSTALL_MYSQLTESTDIR=share/mysql/mysql-test )
414 mycmakeargs+=( -DINSTALL_MYSQLTESTDIR='' )
417 if use openssl || use libressl ; then
418 mycmakeargs+=( -DWITH_SSL=system )
420 mycmakeargs+=( -DWITH_SSL=bundled )
423 if ! multilib_is_native_abi ; then
424 mycmakeargs+=( -DWITHOUT_TOOLS=1 )
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
431 -DWITH_READLINE=$(usex bindist 1 0)
432 -DNOT_FOR_DISTRIBUTION=$(usex bindist 0 1)
437 -DNOT_FOR_DISTRIBUTION=0
442 ### TODO: make this system but issues with UTF-8 prevent it
443 mycmakeargs+=( -DWITH_EDITLINE=bundled )
445 if multilib_is_native_abi && use server ; then
447 # systemd is only linked to for server notification
448 if in_iuse systemd ; then
449 mycmakeargs+=( -DWITH_SYSTEMD=$(usex systemd yes no) )
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."
458 -DDEFAULT_CHARSET=${MYSQL_DEFAULT_CHARSET}
459 -DDEFAULT_COLLATION=${MYSQL_DEFAULT_COLLATION}
462 elif ! use latin1 ; then
464 -DDEFAULT_CHARSET=utf8
465 -DDEFAULT_COLLATION=utf8_general_ci
469 -DDEFAULT_CHARSET=latin1
470 -DDEFAULT_COLLATION=latin1_swedish_ci
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)
484 mycmakeargs+=( -DWITH_PIC=1 )
487 if use jemalloc || use tcmalloc ; then
488 mycmakeargs+=( -DWITH_SAFEMALLOC=OFF )
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
503 mycmakeargs+=( -DWITH_FEDERATED_STORAGE_ENGINE=$(usex extraengine) )
507 -DWITHOUT_EMBEDDED_SERVER=1
508 -DEXTRA_CHARSETS=none
509 -DINSTALL_SQLBENCHDIR=
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[@]}" )
519 mycmakeargs+=( -DENABLE_DTRACE=0
520 "${MYSQL_CMAKE_NONNATIVE_DEFINES[@]}" )
523 mycmakeargs+=( "${MYSQL_CMAKE_EXTRA_DEFINES[@]}" )
525 cmake-utils_src_configure
528 mysql-multilib-r1_src_compile() {
529 local _cmake_args=( "${@}" )
531 multilib-minimal_src_compile
534 multilib_src_compile() {
536 cmake-utils_src_compile "${_cmake_args[@]}"
540 # @FUNCTION: mysql-multilib-r1_src_install
543 mysql-multilib-r1_src_install() {
544 # wrap the config script
545 MULTILIB_CHOST_TOOLS=( /usr/bin/mysql_config )
547 multilib-minimal_src_install
550 multilib_src_install() {
551 debug-print-function ${FUNCNAME} "$@"
553 cmake-utils_src_install
554 # Make sure the vars are correctly initialized
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
562 if multilib_is_native_abi; then
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"
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
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.
579 rm -rf "${D}"/${MY_SHAREDSTATEDIR}/mysql-test
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" ;;
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"
597 -e "/character-set/s|utf8|latin1|g" \
598 "${TMPDIR}/my.cnf.ok" || die
600 eprefixify "${TMPDIR}/my.cnf.ok"
601 newins "${TMPDIR}/my.cnf.ok" my.cnf
604 einfo "Including support files and sample configurations"
605 docinto "support-files"
607 "${S}"/support-files/my-*.cnf.sh \
608 "${S}"/support-files/magic \
609 "${S}"/support-files/ndb-config-2-node.ini.sh
611 [[ -f $script ]] && dodoc "${script}"
615 for script in "${S}"/scripts/mysql* ; do
616 [[ ( -f $script ) && ( ${script%.sh} == ${script} ) ]] && dodoc "${script}"
620 #Remove mytop if perl is not selected
621 [[ -e "${ED}/usr/bin/mytop" ]] && ! use perl && rm -f "${ED}/usr/bin/mytop"
623 # Percona has decided to rename libmysqlclient to libperconaserverclient
624 # Use a symlink to preserve linkages for those who don't use mysql_config
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}
632 if [[ "${PN}" == "mariadb" ]] && use server ; then
633 insinto /usr/include/mysql/private
639 # @FUNCTION: mysql-multilib-r1_pkg_preinst
641 # Warn about ABI changes when switching providers
642 mysql-multilib-r1_pkg_preinst() {
643 debug-print-function ${FUNCNAME} "$@"
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"
656 # @FUNCTION: mysql-multilib-r1_pkg_postinst
658 # Run post-installation tasks:
659 # create the dir for logfiles if non-existant
660 # touch the logfiles and secure them
662 # issue required steps for optional features
663 # issue deprecation warnings
664 mysql-multilib-r1_pkg_postinst() {
665 debug-print-function ${FUNCNAME} "$@"
667 # Make sure the vars are correctly initialized
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}"
674 docinto "support-files"
676 support-files/my-*.cnf \
677 support-files/magic \
678 support-files/ndb-config-2-node.ini
680 [[ -f "${script}" ]] \
685 for script in scripts/mysql* ; do
686 if [[ -f "${script}" && "${script%.sh}" == "${script}" ]]; then
691 if in_iuse pam && use pam; then
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"
703 if [[ -z "${REPLACING_VERSIONS}" ]] ; then
705 elog "You might want to run:"
706 elog "\"emerge --config =${CATEGORY}/${PF}\""
707 elog "if this is a new install."
709 elog "If you are switching server implentations, you should run the"
710 elog "mysql_upgrade tool."
714 elog "If you are upgrading major versions, you should run the"
715 elog "mysql_upgrade tool."
719 if in_iuse galera && use galera ; then
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."
731 # @FUNCTION: mysql-multilib-r1_getopt
733 # Use my_print_defaults to extract specific config options
734 mysql-multilib-r1_getopt() {
735 local mypd="${EROOT}"/usr/bin/my_print_defaults
738 "${mypd}" $section | sed -n "/^${flag}/p"
741 # @FUNCTION: mysql-multilib-r1_getoptval
743 # Use my_print_defaults to extract specific config options
744 mysql-multilib-r1_getoptval() {
745 local mypd="${EROOT}"/usr/bin/my_print_defaults
748 local extra_options="${3}"
749 "${mypd}" $extra_options $section | sed -n "/^${flag}/s,${flag},,gp"
752 # @FUNCTION: mysql-multilib-r1_pkg_config
754 # Configure mysql environment.
755 mysql-multilib-r1_pkg_config() {
757 debug-print-function ${FUNCNAME} "$@"
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
764 # Make sure the vars are correctly initialized
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"
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%%/}"
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}"
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"
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}"
792 eerror "New MY_DATADIR (${MY_DATADIR_s}) does not exist"
793 die "Configuration Failed! Please reinstall ${CATEGORY}/${PN}"
802 if [ -z "${MYSQL_ROOT_PASSWORD}" ]; then
803 local tmp_mysqld_password_source=
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?)!"
815 einfo "Found password in '${tmp_mysqld_password_source}' section!"
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)"
825 unset tmp_mysqld_password_source
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%/*}
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
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
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
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!"
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"
858 if [ -z "${MYSQL_ROOT_PASSWORD}" ]; then
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
865 einfo "Retype the password"
866 read -rsp " >" pwd2 ; echo
868 if [[ "x$pwd1" != "x$pwd2" ]] ; then
869 die "Passwords are not the same"
871 MYSQL_ROOT_PASSWORD="${pwd1}"
876 local sqltmp="$(emktemp)"
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'"
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"
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 \
895 optexp="--(skip-)?${opt}" optfull="--loose-skip-${opt}"
896 egrep -sq -- "${optexp}" "${helpfile}" && options="${options} ${optfull}"
898 # But some options changed names
899 egrep -sq external-locking "${helpfile}" && \
900 options="${options/skip-locking/skip-external-locking}"
902 einfo "Creating the mysql database and setting proper permissions on it ..."
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"
910 if [[ ! -d "${MY_DATADIR}" ]]; then
911 install -d -m 750 -o mysql -g mysql "${MY_DATADIR}" || die "Could not create data directory"
914 pushd "${TMPDIR}" &>/dev/null || die
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
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
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}"
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"
943 popd &>/dev/null || die
944 [[ -f "${ROOT}/${MY_DATADIR}/mysql/user.frm" ]] \
945 || die "MySQL databases not installed"
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 \
951 $(use prefix || echo --user=mysql) \
953 --basedir=${EROOT}/usr \
954 --datadir=${ROOT}/${MY_DATADIR} \
955 --max_allowed_packet=8M \
956 --net_buffer_length=16K \
957 --default-storage-engine=MyISAM \
959 --pid-file=${pidfile}
960 --tmpdir=${ROOT}/${MYSQL_TMPDIR}"
961 #einfo "About to start mysqld: ${mysqld}"
962 ebegin "Starting mysqld"
963 einfo "Command ${mysqld}"
966 while ! [[ -S "${socket}" || "${maxtry}" -lt 1 ]] ; do
967 maxtry=$((${maxtry}-1))
973 if ! [[ -S "${socket}" ]]; then
974 die "Completely failed to start up mysqld with: ${mysqld}"
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" \
986 if [[ -n "${sqltmp}" ]] ; then
987 ebegin "Loading \"zoneinfo\", this step may require a few seconds"
988 "${EROOT}/usr/bin/mysql" \
992 --password="${MYSQL_ROOT_PASSWORD}" \
996 [[ $rc -ne 0 ]] && ewarn "Failed to load zoneinfo!"
999 # Stop the server and cleanup
1000 einfo "Stopping the server ..."
1001 kill $(< "${pidfile}" )
1012 # @FUNCTION: mysql-multilib-r1_disable_test
1014 # Helper function to disable specific tests.
1015 mysql-multilib-r1_disable_test() {
1017 local rawtestname testname testsuite reason mysql_disabled_file mysql_disabled_dir
1018 rawtestname="${1}" ; shift
1020 ewarn "test '${rawtestname}' disabled: '${reason}'"
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
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}"
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 \
1038 [[ -f ${mysql_disabled_file} ]] && break
1040 if [[ ${mysql_disabled_file} != "FAILED" ]]; then
1041 echo "${testname} : ${reason}" >> "${mysql_disabled_file}"
1043 for mysql_disabled_dir in \
1044 ${S}/mysql-test/suite/${testsuite} \
1045 ${S}/mysql-test/suite/${testsuite}/t \
1047 [[ -d ${mysql_disabled_dir} ]] && break
1049 if [[ ${mysql_disabled_dir} != "FAILED" ]]; then
1050 echo "${testname} : ${reason}" >> "${mysql_disabled_dir}/disabled.def"
1052 ewarn "Could not find testsuite disabled.def location for ${rawtestname}"
1058 # @FUNCTION: mysql-cmake_use_plugin
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"
1068 echo "-DWITHOUT_$2=1 -DWITH_$2=0 -DPLUGIN_$2=NO"
1072 # @FUNCTION: mysql_init_vars
1074 # void mysql_init_vars()
1075 # Initialize global variables
1076 # 2005-11-19 <vivo@gentoo.org>
1077 if [[ "${EAPI}x" != "5x" ]]; then
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"}
1087 if [[ -z "${MY_DATADIR}" ]] ; then
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' \
1093 if [[ -z "${MY_DATADIR}" ]] ; then
1094 MY_DATADIR=`grep ^datadir "${MY_SYSCONFDIR}/my.cnf" \
1095 | sed -e 's/.*=\s*//' \
1099 if [[ -z "${MY_DATADIR}" ]] ; then
1100 MY_DATADIR="${MY_LOCALSTATEDIR}"
1101 einfo "Using default MY_DATADIR"
1103 elog "MySQL MY_DATADIR is ${MY_DATADIR}"
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"
1112 PREVIOUS_DATADIR="no"
1114 export PREVIOUS_DATADIR
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' \
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}"
1132 if [ "${MY_SOURCEDIR:-unset}" == "unset" ]; then
1133 MY_SOURCEDIR=${SERVER_URI##*/}
1134 MY_SOURCEDIR=${MY_SOURCEDIR%.tar*}
1137 export MY_SHAREDSTATEDIR MY_SYSCONFDIR
1138 export MY_LIBDIR MY_LOCALSTATEDIR MY_LOGDIR
1139 export MY_INCLUDEDIR MY_DATADIR MY_SOURCEDIR