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="http://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 )
195 abi_x86_32? ( !app-emulation/emul-linux-x86-db[-abi_x86_32(-)] )
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}"
205 server? ( !prefix? ( dev-db/mysql-init-scripts ) )
206 !<virtual/mysql-5.6-r4"
209 # ncurses only needs multilib for compile time due to a binary that will be not installed
212 static? ( sys-libs/ncurses[static-libs] )
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=]"
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 )
228 # @FUNCTION: mysql-multilib-r1_pkg_pretend
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."
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."
252 # @FUNCTION: mysql-multilib-r1_pkg_setup
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() {
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."
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"
270 # @FUNCTION: mysql-multilib-r1_src_unpack
272 # Unpack the source code
273 mysql-multilib-r1_src_unpack() {
275 # Initialize the proper variables first
280 [[ "${MY_EXTRAS_VER}" == "live" ]] && S="${WORKDIR}/mysql-extras" git-r3_src_unpack
282 mv -f "${WORKDIR}/${MY_SOURCEDIR}" "${S}"
285 # @FUNCTION: mysql-multilib-r1_src_prepare
287 # Apply patches to the source code and remove unneeded bundled libs.
288 mysql-multilib-r1_src_prepare() {
290 debug-print-function ${FUNCNAME} "$@"
294 if [[ ${MY_EXTRAS_VER} != none ]]; then
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
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
313 rm -f "scripts/mysqlbug"
314 if use jemalloc && [[ ${PN} != "mariadb" ]] ; then
315 echo "TARGET_LINK_LIBRARIES(mysqld jemalloc)" >> "${S}/sql/CMakeLists.txt" || die
318 if use tcmalloc; then
319 echo "TARGET_LINK_LIBRARIES(mysqld tcmalloc)" >> "${S}/sql/CMakeLists.txt"
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
333 if [[ -d "${S}/plugin/tokudb-backup-plugin" ]] && ! use tokudb-backup-plugin ; then
334 rm -r "${S}/plugin/tokudb-backup-plugin/Percona-TokuBackup" || die
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"
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
349 cmake-utils_src_prepare
352 # @FUNCTION: mysql-multilib-r1_src_configure
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]"
359 append-cxxflags -felide-constructors
361 # bug #283926, with GCC4.4, this is required to get correct behavior.
362 append-flags -fno-strict-aliasing
364 multilib-minimal_src_configure
367 multilib_src_configure() {
368 debug-print-function ${FUNCNAME} "$@"
370 CMAKE_BUILD_TYPE="RelWithDebInfo"
372 # debug hack wrt #497532
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
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)
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)"
413 mycmakeargs+=( -DINSTALL_MYSQLTESTDIR=share/mysql/mysql-test )
415 mycmakeargs+=( -DINSTALL_MYSQLTESTDIR='' )
418 if use openssl || use libressl ; then
419 mycmakeargs+=( -DWITH_SSL=system )
421 mycmakeargs+=( -DWITH_SSL=bundled )
424 if ! multilib_is_native_abi ; then
425 mycmakeargs+=( -DWITHOUT_TOOLS=1 )
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
432 -DWITH_READLINE=$(usex bindist 1 0)
433 -DNOT_FOR_DISTRIBUTION=$(usex bindist 0 1)
438 -DNOT_FOR_DISTRIBUTION=0
443 ### TODO: make this system but issues with UTF-8 prevent it
444 mycmakeargs+=( -DWITH_EDITLINE=bundled )
446 if multilib_is_native_abi && use server ; then
448 # systemd is only linked to for server notification
449 if in_iuse systemd ; then
450 mycmakeargs+=( -DWITH_SYSTEMD=$(usex systemd yes no) )
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."
459 -DDEFAULT_CHARSET=${MYSQL_DEFAULT_CHARSET}
460 -DDEFAULT_COLLATION=${MYSQL_DEFAULT_COLLATION}
463 elif ! use latin1 ; then
465 -DDEFAULT_CHARSET=utf8
466 -DDEFAULT_COLLATION=utf8_general_ci
470 -DDEFAULT_CHARSET=latin1
471 -DDEFAULT_COLLATION=latin1_swedish_ci
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)
485 mycmakeargs+=( -DWITH_PIC=1 )
488 if use jemalloc || use tcmalloc ; then
489 mycmakeargs+=( -DWITH_SAFEMALLOC=OFF )
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
504 mycmakeargs+=( -DWITH_FEDERATED_STORAGE_ENGINE=$(usex extraengine) )
508 -DWITHOUT_EMBEDDED_SERVER=1
509 -DEXTRA_CHARSETS=none
510 -DINSTALL_SQLBENCHDIR=
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[@]}" )
520 mycmakeargs+=( -DENABLE_DTRACE=0
521 "${MYSQL_CMAKE_NONNATIVE_DEFINES[@]}" )
524 mycmakeargs+=( "${MYSQL_CMAKE_EXTRA_DEFINES[@]}" )
526 cmake-utils_src_configure
529 mysql-multilib-r1_src_compile() {
530 local _cmake_args=( "${@}" )
532 multilib-minimal_src_compile
535 multilib_src_compile() {
537 cmake-utils_src_compile "${_cmake_args[@]}"
541 # @FUNCTION: mysql-multilib-r1_src_install
544 mysql-multilib-r1_src_install() {
545 # wrap the config script
546 MULTILIB_CHOST_TOOLS=( /usr/bin/mysql_config )
548 multilib-minimal_src_install
551 multilib_src_install() {
552 debug-print-function ${FUNCNAME} "$@"
554 cmake-utils_src_install
555 # Make sure the vars are correctly initialized
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
563 if multilib_is_native_abi; then
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"
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
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.
580 rm -rf "${D}"/${MY_SHAREDSTATEDIR}/mysql-test
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" ;;
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"
598 -e "/character-set/s|utf8|latin1|g" \
599 "${TMPDIR}/my.cnf.ok" || die
601 eprefixify "${TMPDIR}/my.cnf.ok"
602 newins "${TMPDIR}/my.cnf.ok" my.cnf
605 einfo "Including support files and sample configurations"
606 docinto "support-files"
608 "${S}"/support-files/my-*.cnf.sh \
609 "${S}"/support-files/magic \
610 "${S}"/support-files/ndb-config-2-node.ini.sh
612 [[ -f $script ]] && dodoc "${script}"
616 for script in "${S}"/scripts/mysql* ; do
617 [[ ( -f $script ) && ( ${script%.sh} == ${script} ) ]] && dodoc "${script}"
621 #Remove mytop if perl is not selected
622 [[ -e "${ED}/usr/bin/mytop" ]] && ! use perl && rm -f "${ED}/usr/bin/mytop"
624 # Percona has decided to rename libmysqlclient to libperconaserverclient
625 # Use a symlink to preserve linkages for those who don't use mysql_config
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}
633 if [[ "${PN}" == "mariadb" ]] && use server ; then
634 insinto /usr/include/mysql/private
640 # @FUNCTION: mysql-multilib-r1_pkg_preinst
642 # Warn about ABI changes when switching providers
643 mysql-multilib-r1_pkg_preinst() {
644 debug-print-function ${FUNCNAME} "$@"
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"
657 # @FUNCTION: mysql-multilib-r1_pkg_postinst
659 # Run post-installation tasks:
660 # create the dir for logfiles if non-existant
661 # touch the logfiles and secure them
663 # issue required steps for optional features
664 # issue deprecation warnings
665 mysql-multilib-r1_pkg_postinst() {
666 debug-print-function ${FUNCNAME} "$@"
668 # Make sure the vars are correctly initialized
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}"
675 docinto "support-files"
677 support-files/my-*.cnf \
678 support-files/magic \
679 support-files/ndb-config-2-node.ini
681 [[ -f "${script}" ]] \
686 for script in scripts/mysql* ; do
687 if [[ -f "${script}" && "${script%.sh}" == "${script}" ]]; then
692 if in_iuse pam && use pam; then
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"
704 if [[ -z "${REPLACING_VERSIONS}" ]] ; then
706 elog "You might want to run:"
707 elog "\"emerge --config =${CATEGORY}/${PF}\""
708 elog "if this is a new install."
710 elog "If you are switching server implentations, you should run the"
711 elog "mysql_upgrade tool."
715 elog "If you are upgrading major versions, you should run the"
716 elog "mysql_upgrade tool."
720 if in_iuse galera && use galera ; then
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."
732 # @FUNCTION: mysql-multilib-r1_getopt
734 # Use my_print_defaults to extract specific config options
735 mysql-multilib-r1_getopt() {
736 local mypd="${EROOT}"/usr/bin/my_print_defaults
739 "${mypd}" $section | sed -n "/^${flag}/p"
742 # @FUNCTION: mysql-multilib-r1_getoptval
744 # Use my_print_defaults to extract specific config options
745 mysql-multilib-r1_getoptval() {
746 local mypd="${EROOT}"/usr/bin/my_print_defaults
749 local extra_options="${3}"
750 "${mypd}" $extra_options $section | sed -n "/^${flag}/s,${flag},,gp"
753 # @FUNCTION: mysql-multilib-r1_pkg_config
755 # Configure mysql environment.
756 mysql-multilib-r1_pkg_config() {
758 debug-print-function ${FUNCNAME} "$@"
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
765 # Make sure the vars are correctly initialized
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"
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%%/}"
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}"
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"
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}"
793 eerror "New MY_DATADIR (${MY_DATADIR_s}) does not exist"
794 die "Configuration Failed! Please reinstall ${CATEGORY}/${PN}"
803 if [ -z "${MYSQL_ROOT_PASSWORD}" ]; then
804 local tmp_mysqld_password_source=
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?)!"
816 einfo "Found password in '${tmp_mysqld_password_source}' section!"
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)"
826 unset tmp_mysqld_password_source
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%/*}
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
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
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
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!"
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"
859 if [ -z "${MYSQL_ROOT_PASSWORD}" ]; then
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
866 einfo "Retype the password"
867 read -rsp " >" pwd2 ; echo
869 if [[ "x$pwd1" != "x$pwd2" ]] ; then
870 die "Passwords are not the same"
872 MYSQL_ROOT_PASSWORD="${pwd1}"
877 local sqltmp="$(emktemp)"
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'"
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"
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 \
896 optexp="--(skip-)?${opt}" optfull="--loose-skip-${opt}"
897 egrep -sq -- "${optexp}" "${helpfile}" && options="${options} ${optfull}"
899 # But some options changed names
900 egrep -sq external-locking "${helpfile}" && \
901 options="${options/skip-locking/skip-external-locking}"
903 einfo "Creating the mysql database and setting proper permissions on it ..."
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"
911 if [[ ! -d "${MY_DATADIR}" ]]; then
912 install -d -m 750 -o mysql -g mysql "${MY_DATADIR}" || die "Could not create data directory"
915 pushd "${TMPDIR}" &>/dev/null || die
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
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
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}"
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"
944 popd &>/dev/null || die
945 [[ -f "${ROOT}/${MY_DATADIR}/mysql/user.frm" ]] \
946 || die "MySQL databases not installed"
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 \
952 $(use prefix || echo --user=mysql) \
954 --basedir=${EROOT}/usr \
955 --datadir=${ROOT}/${MY_DATADIR} \
956 --max_allowed_packet=8M \
957 --net_buffer_length=16K \
958 --default-storage-engine=MyISAM \
960 --pid-file=${pidfile}
961 --tmpdir=${ROOT}/${MYSQL_TMPDIR}"
962 #einfo "About to start mysqld: ${mysqld}"
963 ebegin "Starting mysqld"
964 einfo "Command ${mysqld}"
967 while ! [[ -S "${socket}" || "${maxtry}" -lt 1 ]] ; do
968 maxtry=$((${maxtry}-1))
974 if ! [[ -S "${socket}" ]]; then
975 die "Completely failed to start up mysqld with: ${mysqld}"
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" \
987 if [[ -n "${sqltmp}" ]] ; then
988 ebegin "Loading \"zoneinfo\", this step may require a few seconds"
989 "${EROOT}/usr/bin/mysql" \
993 --password="${MYSQL_ROOT_PASSWORD}" \
997 [[ $rc -ne 0 ]] && ewarn "Failed to load zoneinfo!"
1000 # Stop the server and cleanup
1001 einfo "Stopping the server ..."
1002 kill $(< "${pidfile}" )
1013 # @FUNCTION: mysql-multilib-r1_disable_test
1015 # Helper function to disable specific tests.
1016 mysql-multilib-r1_disable_test() {
1018 local rawtestname testname testsuite reason mysql_disabled_file mysql_disabled_dir
1019 rawtestname="${1}" ; shift
1021 ewarn "test '${rawtestname}' disabled: '${reason}'"
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
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}"
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 \
1039 [[ -f ${mysql_disabled_file} ]] && break
1041 if [[ ${mysql_disabled_file} != "FAILED" ]]; then
1042 echo "${testname} : ${reason}" >> "${mysql_disabled_file}"
1044 for mysql_disabled_dir in \
1045 ${S}/mysql-test/suite/${testsuite} \
1046 ${S}/mysql-test/suite/${testsuite}/t \
1048 [[ -d ${mysql_disabled_dir} ]] && break
1050 if [[ ${mysql_disabled_dir} != "FAILED" ]]; then
1051 echo "${testname} : ${reason}" >> "${mysql_disabled_dir}/disabled.def"
1053 ewarn "Could not find testsuite disabled.def location for ${rawtestname}"
1059 # @FUNCTION: mysql-cmake_use_plugin
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"
1069 echo "-DWITHOUT_$2=1 -DWITH_$2=0 -DPLUGIN_$2=NO"
1073 # @FUNCTION: mysql_init_vars
1075 # void mysql_init_vars()
1076 # Initialize global variables
1077 # 2005-11-19 <vivo@gentoo.org>
1078 if [[ "${EAPI}x" != "5x" ]]; then
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"}
1088 if [[ -z "${MY_DATADIR}" ]] ; then
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' \
1094 if [[ -z "${MY_DATADIR}" ]] ; then
1095 MY_DATADIR=`grep ^datadir "${MY_SYSCONFDIR}/my.cnf" \
1096 | sed -e 's/.*=\s*//' \
1100 if [[ -z "${MY_DATADIR}" ]] ; then
1101 MY_DATADIR="${MY_LOCALSTATEDIR}"
1102 einfo "Using default MY_DATADIR"
1104 elog "MySQL MY_DATADIR is ${MY_DATADIR}"
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"
1113 PREVIOUS_DATADIR="no"
1115 export PREVIOUS_DATADIR
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' \
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}"
1133 if [ "${MY_SOURCEDIR:-unset}" == "unset" ]; then
1134 MY_SOURCEDIR=${SERVER_URI##*/}
1135 MY_SOURCEDIR=${MY_SOURCEDIR%.tar*}
1138 export MY_SHAREDSTATEDIR MY_SYSCONFDIR
1139 export MY_LIBDIR MY_LOCALSTATEDIR MY_LOGDIR
1140 export MY_INCLUDEDIR MY_DATADIR MY_SOURCEDIR