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
24 # The version of the MYSQL_EXTRAS repo to use to build mysql
25 # Use "none" to disable it's use
26 [[ ${MY_EXTRAS_VER} == "live" ]] && MYSQL_EXTRAS="git-r3"
28 # @ECLASS-VARIABLE: MYSQL_CMAKE_NATIVE_DEFINES
30 # An array of extra CMake arguments for native multilib builds
32 # @ECLASS-VARIABLE: MYSQL_CMAKE_NONNATIVE_DEFINES
34 # An array of extra CMake arguments for non-native multilib builds
36 # @ECLASS-VARIABLE: MYSQL_CMAKE_EXTRA_DEFINES
38 # An array of CMake arguments added to native and non-native
40 # Keeping eutils in EAPI=6 for emktemp in pkg_config
42 inherit eutils systemd flag-o-matic ${MYSQL_EXTRAS} versionator \
43 prefix toolchain-funcs user cmake-utils multilib-minimal
45 if [[ "${EAPI}x" == "5x" ]]; then
46 inherit multilib mysql_fx
50 # Supported EAPI versions and export functions
55 *) die "Unsupported EAPI: ${EAPI}" ;;
58 EXPORT_FUNCTIONS pkg_pretend pkg_setup src_unpack src_prepare src_configure src_compile src_install pkg_preinst pkg_postinst pkg_config
64 # Shorten the path because the socket path length must be shorter than 107 chars
65 # and we will run a mysql server during test phase
68 [[ ${MY_EXTRAS_VER} == "latest" ]] && MY_EXTRAS_VER="20090228-0714Z"
69 if [[ ${MY_EXTRAS_VER} == "live" ]]; then
70 EGIT_REPO_URI="git://anongit.gentoo.org/proj/mysql-extras.git"
71 EGIT_CHECKOUT_DIR=${WORKDIR}/mysql-extras
72 EGIT_CLONE_TYPE=shallow
75 # @ECLASS-VARIABLE: MYSQL_PV_MAJOR
77 # Upstream MySQL considers the first two parts of the version number to be the
78 # major version. Upgrades that change major version should always run
80 if [[ -z ${MYSQL_PV_MAJOR} ]] ; then MYSQL_PV_MAJOR="$(get_version_component_range 1-2 ${PV})" ; fi
82 # @ECLASS-VARIABLE: MYSQL_VERSION_ID
84 # MYSQL_VERSION_ID will be:
85 # major * 10e6 + minor * 10e4 + micro * 10e2 + gentoo revision number, all [0..99]
86 # This is an important part, because many of the choices the MySQL ebuild will do
87 # depend on this variable.
88 # In particular, the code below transforms a $PVR like "5.0.18-r3" in "5001803"
89 # We also strip off upstream's trailing letter that they use to respin tarballs
90 if [[ "${EAPI}x" == "5x" ]]; then
93 tpv=( ${tpv//[-._]/ } ) ; tpv[3]="${PVR:${#PV}}" ; tpv[3]="${tpv[3]##*-r}"
94 for vatom in 0 1 2 3 ; do
96 tpv[${vatom}]="00${tpv[${vatom}]}"
97 MYSQL_VERSION_ID="${MYSQL_VERSION_ID}${tpv[${vatom}]:0-2}"
99 # strip leading "0" (otherwise it's considered an octal number by BASH)
100 MYSQL_VERSION_ID=${MYSQL_VERSION_ID##"0"}
103 # Work out the default SERVER_URI correctly
104 if [[ -z ${SERVER_URI} ]]; then
105 if [[ ${PN} == "mariadb" ]]; then
106 # Beginning with 5.5, MariaDB stopped putting beta, alpha or rc on their tarball names
107 MARIA_FULL_PV=$(get_version_component_range 1-3)
108 MARIA_FULL_P="${PN}-${MARIA_FULL_PV}"
109 SERVER_URI="https://downloads.mariadb.org/interstitial/${MARIA_FULL_P}/source/${MARIA_FULL_P}.tar.gz"
110 elif [[ ${PN} == "percona-server" ]]; then
111 PERCONA_PN="Percona-Server"
112 MIRROR_PV=$(get_version_component_range 1-2 ${PV})
113 MY_PV=$(get_version_component_range 1-3 ${PV})
114 PERCONA_RELEASE=$(get_version_component_range 4-5 ${PV})
115 PERCONA_RC=$(get_version_component_range 6 ${PV})
116 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"
118 if [[ "${PN}" == "mysql-cluster" ]] ; then
119 URI_DIR="MySQL-Cluster"
120 URI_FILE="mysql-cluster-gpl"
125 [[ -z ${MY_PV} ]] && MY_PV="${PV//_/-}"
126 URI_A="${URI_FILE}-${MY_PV}.tar.gz"
127 MIRROR_PV=$(get_version_component_range 1-2 ${PV})
128 # Recently upstream switched to an archive site, and not on mirrors
129 SERVER_URI="http://cdn.mysql.com/Downloads/${URI_DIR}-${MIRROR_PV}/${URI_A}
130 http://downloads.mysql.com/archives/${URI_DIR}-${MIRROR_PV}/${URI_A}"
134 # Define correct SRC_URIs
135 SRC_URI="${SERVER_URI}"
137 # Gentoo patches to MySQL
138 if [[ ${MY_EXTRAS_VER} != "live" && ${MY_EXTRAS_VER} != "none" ]]; then
140 mirror://gentoo/mysql-extras-${MY_EXTRAS_VER}.tar.bz2
141 https://gitweb.gentoo.org/proj/mysql-extras.git/snapshot/mysql-extras-${MY_EXTRAS_VER}.tar.bz2
142 https://dev.gentoo.org/~grknight/distfiles/mysql-extras-${MY_EXTRAS_VER}.tar.bz2
143 https://dev.gentoo.org/~robbat2/distfiles/mysql-extras-${MY_EXTRAS_VER}.tar.bz2
144 https://dev.gentoo.org/~jmbsvicetto/distfiles/mysql-extras-${MY_EXTRAS_VER}.tar.bz2"
147 DESCRIPTION="A fast, multi-threaded, multi-user SQL database server"
148 HOMEPAGE="http://www.mysql.com/"
150 SLOT="0/${SUBSLOT:-0}"
152 IUSE="debug embedded extraengine jemalloc latin1 libressl +openssl
153 +perl profiling selinux +server systemtap static static-libs tcmalloc test yassl"
155 REQUIRED_USE="^^ ( yassl openssl libressl )"
157 # Tests always fail when libressl is enabled due to hard-coded ciphers in the tests
158 RESTRICT="libressl? ( test )"
160 REQUIRED_USE="${REQUIRED_USE} !server? ( !extraengine !embedded )
161 ?? ( tcmalloc jemalloc )
162 static? ( !libressl !openssl yassl )"
168 # Be warned, *DEPEND are version-dependant
169 # These are used for both runtime and compiletime
170 # MULTILIB_USEDEP only set for libraries used by the client library
173 sys-process/procps:0=
177 >=sys-apps/texinfo-4.7-r1
178 !dev-db/mariadb-native-client[mysqlcompat]
179 jemalloc? ( dev-libs/jemalloc:0= )
180 tcmalloc? ( dev-util/google-perftools:0= )
181 systemtap? ( >=dev-util/systemtap-1.3:0= )
182 openssl? ( >=dev-libs/openssl-1.0.0:0=[${MULTILIB_USEDEP},static-libs?] )
183 libressl? ( dev-libs/libressl:0=[${MULTILIB_USEDEP},static-libs?] )
184 >=sys-libs/zlib-1.2.3:0=[${MULTILIB_USEDEP},static-libs?]
188 # prefix: first need to implement something for #196294
190 selinux? ( sec-policy/selinux-mysql )
191 abi_x86_32? ( !app-emulation/emul-linux-x86-db[-abi_x86_32(-)] )
194 # Having different flavours at the same time is not a good idea
195 for i in "mysql" "mariadb" "mariadb-galera" "percona-server" "mysql-cluster" ; do
196 [[ ${i} == ${PN} ]] ||
197 RDEPEND="${RDEPEND} !dev-db/${i}"
201 server? ( !prefix? ( dev-db/mysql-init-scripts ) )
202 !<virtual/mysql-5.6-r4"
205 # ncurses only needs multilib for compile time due to a binary that will be not installed
208 static? ( sys-libs/ncurses[static-libs] )
211 # For other stuff to bring us in
212 # dev-perl/DBD-mysql is needed by some scripts installed by MySQL
213 PDEPEND="${PDEPEND} perl? ( >=dev-perl/DBD-mysql-2.9004 )
214 server? ( ~virtual/mysql-${MYSQL_PV_MAJOR}[embedded=,static=] )
215 virtual/libmysqlclient:${SLOT}[${MULTILIB_USEDEP},static-libs=]"
217 # my_config.h includes ABI specific data
218 MULTILIB_WRAPPED_HEADERS=( /usr/include/mysql/my_config.h /usr/include/mysql/private/embedded_priv.h )
224 # @FUNCTION: mysql-multilib-r1_pkg_pretend
226 # Perform some basic tests and tasks during pkg_pretend phase:
227 mysql-multilib-r1_pkg_pretend() {
228 if [[ ${MERGE_TYPE} != binary ]] ; then
229 local GCC_MAJOR_SET=$(gcc-major-version)
230 local GCC_MINOR_SET=$(gcc-minor-version)
231 if in_iuse tokudb && use tokudb && [[ ${GCC_MAJOR_SET} -lt 4 || \
232 ${GCC_MAJOR_SET} -eq 4 && ${GCC_MINOR_SET} -lt 7 ]] ; then
233 eerror "${PN} with tokudb needs to be built with gcc-4.7 or later."
234 eerror "Please use gcc-config to switch to gcc-4.7 or later version."
237 # Bug 565584. InnoDB now requires atomic functions introduced with gcc-4.7 on
238 # non x86{,_64} arches
239 if ! use amd64 && ! use x86 && [[ ${GCC_MAJOR_SET} -lt 4 || \
240 ${GCC_MAJOR_SET} -eq 4 && ${GCC_MINOR_SET} -lt 7 ]] ; then
241 eerror "${PN} needs to be built with gcc-4.7 or later."
242 eerror "Please use gcc-config to switch to gcc-4.7 or later version."
248 # @FUNCTION: mysql-multilib-r1_pkg_setup
250 # Perform some basic tests and tasks during pkg_setup phase:
251 # die if FEATURES="test", USE="server" and not using FEATURES="userpriv"
252 # create new user and group for mysql
253 # warn about deprecated features
254 mysql-multilib-r1_pkg_setup() {
256 if has test ${FEATURES} && \
257 use server && ! has userpriv ${FEATURES} ; then
258 eerror "Testing with FEATURES=-userpriv is no longer supported by upstream. Tests MUST be run as non-root."
261 # This should come after all of the die statements
262 enewgroup mysql 60 || die "problem adding 'mysql' group"
263 enewuser mysql 60 -1 /dev/null mysql || die "problem adding 'mysql' user"
266 # @FUNCTION: mysql-multilib-r1_src_unpack
268 # Unpack the source code
269 mysql-multilib-r1_src_unpack() {
271 # Initialize the proper variables first
276 [[ "${MY_EXTRAS_VER}" == "live" ]] && S="${WORKDIR}/mysql-extras" git-r3_src_unpack
278 mv -f "${WORKDIR}/${MY_SOURCEDIR}" "${S}"
281 # @FUNCTION: mysql-multilib-r1_src_prepare
283 # Apply patches to the source code and remove unneeded bundled libs.
284 mysql-multilib-r1_src_prepare() {
286 debug-print-function ${FUNCNAME} "$@"
290 if [[ ${MY_EXTRAS_VER} != none ]]; then
292 # Apply the patches for this MySQL version
293 if [[ "${EAPI}x" == "5x" ]]; then
294 EPATCH_SUFFIX="patch"
295 mkdir -p "${EPATCH_SOURCE}" || die "Unable to create epatch directory"
296 # Clean out old items
297 rm -f "${EPATCH_SOURCE}"/*
298 # Now link in right patches
305 # last -fPIC fixup, per bug #305873
306 i="${S}"/storage/innodb_plugin/plug.in
307 if [[ -f ${i} ]] ; then sed -i -e '/CFLAGS/s,-prefer-non-pic,,g' "${i}" || die ; fi
309 rm -f "scripts/mysqlbug"
310 if use jemalloc && [[ ${PN} != "mariadb" ]] ; then
311 echo "TARGET_LINK_LIBRARIES(mysqld jemalloc)" >> "${S}/sql/CMakeLists.txt" || die
314 if use tcmalloc; then
315 echo "TARGET_LINK_LIBRARIES(mysqld tcmalloc)" >> "${S}/sql/CMakeLists.txt"
318 if in_iuse tokudb ; then
319 # Don't build bundled xz-utils
320 if [[ -d "${S}/storage/tokudb/ft-index" ]] ; then
321 echo > "${S}/storage/tokudb/ft-index/cmake_modules/TokuThirdParty.cmake" || die
322 sed -i 's/ build_lzma//' "${S}/storage/tokudb/ft-index/ft/CMakeLists.txt" || die
323 elif [[ -d "${S}/storage/tokudb/PerconaFT" ]] ; then
324 echo > "${S}/storage/tokudb/PerconaFT/cmake_modules/TokuThirdParty.cmake" || die
325 sed -i -e 's/ build_lzma//' -e 's/ build_snappy//' "${S}/storage/tokudb/PerconaFT/ft/CMakeLists.txt" || die
326 sed -i -e 's/add_dependencies\(tokuportability_static_conv build_jemalloc\)//' "${S}/storage/tokudb/PerconaFT/portability/CMakeLists.txt" || die
329 if [[ -d "${S}/plugin/tokudb-backup-plugin" ]] && ! use tokudb-backup-plugin ; then
330 rm -r "${S}/plugin/tokudb-backup-plugin/Percona-TokuBackup" || die
334 # Remove the bundled groonga if it exists
335 # There is no CMake flag, it simply checks for existance
336 if [[ -d "${S}"/storage/mroonga/vendor/groonga ]] ; then
337 rm -r "${S}"/storage/mroonga/vendor/groonga || die "could not remove packaged groonga"
340 # Remove the centos and rhel selinux policies to support mysqld_safe under SELinux
341 if [[ -d "${S}/support-files/SELinux" ]] ; then
342 echo > "${S}/support-files/SELinux/CMakeLists.txt" || die
345 if [[ "${EAPI}x" == "5x" ]] ; then
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) )
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 "Creating initial directories"
606 # Empty directories ...
608 if [[ ${PREVIOUS_DATADIR} != "yes" ]] ; then
609 dodir "${MY_DATADIR#${EPREFIX}}"
610 keepdir "${MY_DATADIR#${EPREFIX}}"
611 chown -R mysql:mysql "${D}/${MY_DATADIR}"
615 for folder in "${MY_LOGDIR#${EPREFIX}}" ; do
618 chown -R mysql:mysql "${ED}/${folder}"
621 einfo "Including support files and sample configurations"
622 docinto "support-files"
624 "${S}"/support-files/my-*.cnf.sh \
625 "${S}"/support-files/magic \
626 "${S}"/support-files/ndb-config-2-node.ini.sh
628 [[ -f $script ]] && dodoc "${script}"
632 for script in "${S}"/scripts/mysql* ; do
633 [[ ( -f $script ) && ( ${script%.sh} == ${script} ) ]] && dodoc "${script}"
637 #Remove mytop if perl is not selected
638 [[ -e "${ED}/usr/bin/mytop" ]] && ! use perl && rm -f "${ED}/usr/bin/mytop"
640 # Percona has decided to rename libmysqlclient to libperconaserverclient
641 # Use a symlink to preserve linkages for those who don't use mysql_config
643 for suffix in ".so" "_r.so" ".a" "_r.a" ; do
644 if [[ -e "${ED}/usr/$(get_libdir)/libperconaserverclient${suffix}" ]] ; then
645 dosym libperconaserverclient${suffix} /usr/$(get_libdir)/libmysqlclient${suffix}
649 if [[ "${PN}" == "mariadb" ]] && use server ; then
650 insinto /usr/include/mysql/private
656 # @FUNCTION: mysql-multilib-r1_pkg_preinst
658 # Warn about ABI changes when switching providers
659 mysql-multilib-r1_pkg_preinst() {
660 debug-print-function ${FUNCNAME} "$@"
662 # Here we need to see if the implementation switched client libraries
663 # We check if this is a new instance of the package and a client library already exists
664 local SHOW_ABI_MESSAGE
665 if [[ -z ${REPLACING_VERSIONS} && -e "${EROOT}usr/$(get_libdir)/libmysqlclient.so" ]] ; then
666 elog "Due to ABI changes when switching between different client libraries,"
667 elog "revdep-rebuild must find and rebuild all packages linking to libmysqlclient."
668 elog "Please run: revdep-rebuild --library libmysqlclient.so.${SUBSLOT:-18}"
669 ewarn "Failure to run revdep-rebuild may cause issues with other programs or libraries"
673 # @FUNCTION: mysql-multilib-r1_pkg_postinst
675 # Run post-installation tasks:
676 # create the dir for logfiles if non-existant
677 # touch the logfiles and secure them
679 # issue required steps for optional features
680 # issue deprecation warnings
681 mysql-multilib-r1_pkg_postinst() {
682 debug-print-function ${FUNCNAME} "$@"
684 # Make sure the vars are correctly initialized
687 # Check FEATURES="collision-protect" before removing this
688 [[ -d "${ROOT}${MY_LOGDIR}" ]] || install -d -m0750 -o mysql -g mysql "${ROOT}${MY_LOGDIR}"
690 # Secure the logfiles
691 touch "${ROOT}${MY_LOGDIR}"/mysql.{log,err}
692 chown mysql:mysql "${ROOT}${MY_LOGDIR}"/mysql*
693 chmod 0660 "${ROOT}${MY_LOGDIR}"/mysql*
695 # Minimal builds don't have the MySQL server
697 docinto "support-files"
699 support-files/my-*.cnf \
700 support-files/magic \
701 support-files/ndb-config-2-node.ini
703 [[ -f "${script}" ]] \
708 for script in scripts/mysql* ; do
709 if [[ -f "${script}" && "${script%.sh}" == "${script}" ]]; then
714 if in_iuse pam && use pam; then
716 elog "This install includes the PAM authentication plugin."
717 elog "To activate and configure the PAM plugin, please read:"
718 if [[ ${PN} == "mariadb" ]] ; then
719 elog "https://mariadb.com/kb/en/mariadb/pam-authentication-plugin/"
720 elif [[ ${PN} == "percona-server" ]] ; then
721 elog "https://www.percona.com/doc/percona-server/5.6/management/pam_plugin.html"
726 if [[ -z "${REPLACING_VERSIONS}" ]] ; then
728 elog "You might want to run:"
729 elog "\"emerge --config =${CATEGORY}/${PF}\""
730 elog "if this is a new install."
732 elog "If you are switching server implentations, you should run the"
733 elog "mysql_upgrade tool."
737 elog "If you are upgrading major versions, you should run the"
738 elog "mysql_upgrade tool."
742 if in_iuse galera && use galera ; then
744 elog "Be sure to edit the my.cnf file to activate your cluster settings."
745 elog "This should be done after running \"emerge --config =${CATEGORY}/${PF}\""
746 elog "The first time the cluster is activated, you should add"
747 elog "--wsrep-new-cluster to the options in /etc/conf.d/mysql for one node."
748 elog "This option should then be removed for subsequent starts."
754 # @FUNCTION: mysql-multilib-r1_getopt
756 # Use my_print_defaults to extract specific config options
757 mysql-multilib-r1_getopt() {
758 local mypd="${EROOT}"/usr/bin/my_print_defaults
761 "${mypd}" $section | sed -n "/^${flag}/p"
764 # @FUNCTION: mysql-multilib-r1_getoptval
766 # Use my_print_defaults to extract specific config options
767 mysql-multilib-r1_getoptval() {
768 local mypd="${EROOT}"/usr/bin/my_print_defaults
771 local extra_options="${3}"
772 "${mypd}" $extra_options $section | sed -n "/^${flag}/s,${flag},,gp"
775 # @FUNCTION: mysql-multilib-r1_pkg_config
777 # Configure mysql environment.
778 mysql-multilib-r1_pkg_config() {
780 debug-print-function ${FUNCNAME} "$@"
782 local old_MY_DATADIR="${MY_DATADIR}"
783 local old_HOME="${HOME}"
784 # my_print_defaults needs to read stuff in $HOME/.my.cnf
785 export HOME=${EPREFIX}/root
787 # Make sure the vars are correctly initialized
790 [[ -z "${MY_DATADIR}" ]] && die "Sorry, unable to find MY_DATADIR"
791 if [[ ! -x "${EROOT}/usr/sbin/mysqld" ]] ; then
792 die "Minimal builds do NOT include the MySQL server"
795 if [[ ( -n "${MY_DATADIR}" ) && ( "${MY_DATADIR}" != "${old_MY_DATADIR}" ) ]]; then
796 local MY_DATADIR_s="${ROOT}/${MY_DATADIR}"
797 MY_DATADIR_s="${MY_DATADIR_s%%/}"
798 local old_MY_DATADIR_s="${ROOT}/${old_MY_DATADIR}"
799 old_MY_DATADIR_s="${old_MY_DATADIR_s%%/}"
801 if [[ ( -d "${old_MY_DATADIR_s}" ) && ( "${old_MY_DATADIR_s}" != / ) ]]; then
802 if [[ -d "${MY_DATADIR_s}" ]]; then
803 ewarn "Both ${old_MY_DATADIR_s} and ${MY_DATADIR_s} exist"
804 ewarn "Attempting to use ${MY_DATADIR_s} and preserving ${old_MY_DATADIR_s}"
806 elog "Moving MY_DATADIR from ${old_MY_DATADIR_s} to ${MY_DATADIR_s}"
807 mv --strip-trailing-slashes -T "${old_MY_DATADIR_s}" "${MY_DATADIR_s}" \
808 || die "Moving MY_DATADIR failed"
811 ewarn "Previous MY_DATADIR (${old_MY_DATADIR_s}) does not exist"
812 if [[ -d "${MY_DATADIR_s}" ]]; then
813 ewarn "Attempting to use ${MY_DATADIR_s}"
815 eerror "New MY_DATADIR (${MY_DATADIR_s}) does not exist"
816 die "Configuration Failed! Please reinstall ${CATEGORY}/${PN}"
825 if [ -z "${MYSQL_ROOT_PASSWORD}" ]; then
826 local tmp_mysqld_password_source=
828 for tmp_mysqld_password_source in mysql client; do
829 einfo "Trying to get password for mysql 'root' user from '${tmp_mysqld_password_source}' section ..."
830 MYSQL_ROOT_PASSWORD="$(mysql-multilib-r1_getoptval "${tmp_mysqld_password_source}" password)"
831 if [[ -n "${MYSQL_ROOT_PASSWORD}" ]]; then
832 if [[ ${MYSQL_ROOT_PASSWORD} == *$'\n'* ]]; then
833 ewarn "Ignoring password from '${tmp_mysqld_password_source}' section due to newline character (do you have multiple password options set?)!"
838 einfo "Found password in '${tmp_mysqld_password_source}' section!"
843 # Sometimes --show is required to display passwords in some implementations of my_print_defaults
844 if [[ "${MYSQL_ROOT_PASSWORD}" == '*****' ]]; then
845 MYSQL_ROOT_PASSWORD="$(mysql-multilib-r1_getoptval "${tmp_mysqld_password_source}" password --show)"
848 unset tmp_mysqld_password_source
850 MYSQL_TMPDIR="$(mysql-multilib-r1_getoptval mysqld tmpdir)"
851 # These are dir+prefix
852 MYSQL_RELAY_LOG="$(mysql-multilib-r1_getoptval mysqld relay-log)"
853 MYSQL_RELAY_LOG=${MYSQL_RELAY_LOG%/*}
854 MYSQL_LOG_BIN="$(mysql-multilib-r1_getoptval mysqld log-bin)"
855 MYSQL_LOG_BIN=${MYSQL_LOG_BIN%/*}
857 if [[ ! -d "${ROOT}"/$MYSQL_TMPDIR ]]; then
858 einfo "Creating MySQL tmpdir $MYSQL_TMPDIR"
859 install -d -m 770 -o mysql -g mysql "${EROOT}"/$MYSQL_TMPDIR
861 if [[ ! -d "${ROOT}"/$MYSQL_LOG_BIN ]]; then
862 einfo "Creating MySQL log-bin directory $MYSQL_LOG_BIN"
863 install -d -m 770 -o mysql -g mysql "${EROOT}"/$MYSQL_LOG_BIN
865 if [[ ! -d "${EROOT}"/$MYSQL_RELAY_LOG ]]; then
866 einfo "Creating MySQL relay-log directory $MYSQL_RELAY_LOG"
867 install -d -m 770 -o mysql -g mysql "${EROOT}"/$MYSQL_RELAY_LOG
870 if [[ -d "${ROOT}/${MY_DATADIR}/mysql" ]] ; then
871 ewarn "You have already a MySQL database in place."
872 ewarn "(${ROOT}/${MY_DATADIR}/*)"
873 ewarn "Please rename or delete it if you wish to replace it."
874 die "MySQL database already exists!"
877 # Bug #213475 - MySQL _will_ object strenously if your machine is named
878 # localhost. Also causes weird failures.
879 [[ "${HOSTNAME}" == "localhost" ]] && die "Your machine must NOT be named localhost"
881 if [ -z "${MYSQL_ROOT_PASSWORD}" ]; then
883 einfo "Please provide a password for the mysql 'root' user now"
884 einfo "or through the ${HOME}/.my.cnf file."
885 ewarn "Avoid [\"'\\_%] characters in the password"
886 read -rsp " >" pwd1 ; echo
888 einfo "Retype the password"
889 read -rsp " >" pwd2 ; echo
891 if [[ "x$pwd1" != "x$pwd2" ]] ; then
892 die "Passwords are not the same"
894 MYSQL_ROOT_PASSWORD="${pwd1}"
899 local sqltmp="$(emktemp)"
901 # Fix bug 446200. Don't reference host my.cnf, needs to come first,
902 # see http://bugs.mysql.com/bug.php?id=31312
903 use prefix && options="${options} '--defaults-file=${MY_SYSCONFDIR}/my.cnf'"
905 local help_tables="${ROOT}${MY_SHAREDSTATEDIR}/fill_help_tables.sql"
906 [[ -r "${help_tables}" ]] \
907 && cp "${help_tables}" "${TMPDIR}/fill_help_tables.sql" \
908 || touch "${TMPDIR}/fill_help_tables.sql"
909 help_tables="${TMPDIR}/fill_help_tables.sql"
911 # Figure out which options we need to disable to do the setup
912 local helpfile="${TMPDIR}/mysqld-help"
913 ${EROOT}/usr/sbin/mysqld --verbose --help >"${helpfile}" 2>/dev/null
914 for opt in grant-tables host-cache name-resolve networking slave-start \
915 federated ssl log-bin relay-log slow-query-log external-locking \
916 ndbcluster log-slave-updates \
918 optexp="--(skip-)?${opt}" optfull="--loose-skip-${opt}"
919 egrep -sq -- "${optexp}" "${helpfile}" && options="${options} ${optfull}"
921 # But some options changed names
922 egrep -sq external-locking "${helpfile}" && \
923 options="${options/skip-locking/skip-external-locking}"
925 use prefix || options="${options} --user=mysql"
927 einfo "Creating the mysql database and setting proper permissions on it ..."
929 # Now that /var/run is a tmpfs mount point, we need to ensure it exists before using it
930 PID_DIR="${EROOT}/var/run/mysqld"
931 if [[ ! -d "${PID_DIR}" ]]; then
932 mkdir -p "${PID_DIR}" || die "Could not create pid directory"
933 chown mysql:mysql "${PID_DIR}" || die "Could not set ownership on pid directory"
934 chmod 755 "${PID_DIR}" || die "Could not set permissions on pid directory"
937 pushd "${TMPDIR}" &>/dev/null
939 # Filling timezones, see
940 # http://dev.mysql.com/doc/mysql/en/time-zone-support.html
941 "${EROOT}/usr/bin/mysql_tzinfo_to_sql" "${EROOT}/usr/share/zoneinfo" > "${sqltmp}" 2>/dev/null
944 local initialize_options
945 if [[ ${PN} == "mysql" || ${PN} == "percona-server" ]] && version_is_at_least "5.7.6" ; then
946 # --initialize-insecure will not set root password
947 # --initialize would set a random one in the log which we don't need as we set it ourselves
948 cmd=( "${EROOT}usr/sbin/mysqld" )
949 initialize_options="--initialize-insecure --init-file='${sqltmp}'"
950 sqltmp="" # the initialize will take care of it
952 cmd=( "${EROOT}usr/share/mysql/scripts/mysql_install_db" )
953 [[ -f "${cmd}" ]] || cmd=( "${EROOT}usr/bin/mysql_install_db" )
954 if [[ -r "${help_tables}" ]] ; then
955 cat "${help_tables}" >> "${sqltmp}"
958 cmd+=( "--basedir=${EPREFIX}/usr" ${options} "--datadir=${ROOT}/${MY_DATADIR}" "--tmpdir=${ROOT}/${MYSQL_TMPDIR}" ${initialize_options} )
959 einfo "Command: ${cmd[*]}"
961 >"${TMPDIR}"/mysql_install_db.log 2>&1
962 if [ $? -ne 0 ]; then
963 grep -B5 -A999 -i "ERROR" "${TMPDIR}"/mysql_install_db.log 1>&2
964 die "Failed to initialize mysqld. Please review ${EPREFIX}/var/log/mysql/mysqld.err AND ${TMPDIR}/mysql_install_db.log"
967 [[ -f "${ROOT}/${MY_DATADIR}/mysql/user.frm" ]] \
968 || die "MySQL databases not installed"
969 chown -R mysql:mysql "${ROOT}/${MY_DATADIR}" 2>/dev/null
970 chmod 0750 "${ROOT}/${MY_DATADIR}" 2>/dev/null
972 local socket="${EROOT}/var/run/mysqld/mysqld${RANDOM}.sock"
973 local pidfile="${EROOT}/var/run/mysqld/mysqld${RANDOM}.pid"
974 local mysqld="${EROOT}/usr/sbin/mysqld \
976 $(use prefix || echo --user=mysql) \
978 --basedir=${EROOT}/usr \
979 --datadir=${ROOT}/${MY_DATADIR} \
980 --max_allowed_packet=8M \
981 --net_buffer_length=16K \
982 --default-storage-engine=MyISAM \
984 --pid-file=${pidfile}
985 --tmpdir=${ROOT}/${MYSQL_TMPDIR}"
986 #einfo "About to start mysqld: ${mysqld}"
987 ebegin "Starting mysqld"
988 einfo "Command ${mysqld}"
991 while ! [[ -S "${socket}" || "${maxtry}" -lt 1 ]] ; do
992 maxtry=$((${maxtry}-1))
998 if ! [[ -S "${socket}" ]]; then
999 die "Completely failed to start up mysqld with: ${mysqld}"
1002 ebegin "Setting root password"
1003 # Do this from memory, as we don't want clear text passwords in temp files
1004 local sql="UPDATE mysql.user SET Password = PASSWORD('${MYSQL_ROOT_PASSWORD}') WHERE USER='root'; FLUSH PRIVILEGES"
1005 "${EROOT}/usr/bin/mysql" \
1006 --socket=${socket} \
1011 if [[ -n "${sqltmp}" ]] ; then
1012 ebegin "Loading \"zoneinfo\", this step may require a few seconds"
1013 "${EROOT}/usr/bin/mysql" \
1014 --socket=${socket} \
1017 --password="${MYSQL_ROOT_PASSWORD}" \
1021 [[ $rc -ne 0 ]] && ewarn "Failed to load zoneinfo!"
1024 # Stop the server and cleanup
1025 einfo "Stopping the server ..."
1026 kill $(< "${pidfile}" )
1037 # @FUNCTION: mysql-multilib-r1_disable_test
1039 # Helper function to disable specific tests.
1040 mysql-multilib-r1_disable_test() {
1042 local rawtestname testname testsuite reason mysql_disabled_file mysql_disabled_dir
1043 rawtestname="${1}" ; shift
1045 ewarn "test '${rawtestname}' disabled: '${reason}'"
1047 testsuite="${rawtestname/.*}"
1048 testname="${rawtestname/*.}"
1049 for mysql_disabled_file in \
1050 ${S}/mysql-test/disabled.def \
1051 ${S}/mysql-test/t/disabled.def ; do
1052 [[ -f ${mysql_disabled_file} ]] && break
1054 #mysql_disabled_file="${S}/mysql-test/t/disabled.def"
1055 #einfo "rawtestname=${rawtestname} testname=${testname} testsuite=${testsuite}"
1056 echo ${testname} : ${reason} >> "${mysql_disabled_file}"
1058 if [[ ( -n ${testsuite} ) && ( ${testsuite} != "main" ) ]]; then
1059 for mysql_disabled_file in \
1060 ${S}/mysql-test/suite/${testsuite}/disabled.def \
1061 ${S}/mysql-test/suite/${testsuite}/t/disabled.def \
1063 [[ -f ${mysql_disabled_file} ]] && break
1065 if [[ ${mysql_disabled_file} != "FAILED" ]]; then
1066 echo "${testname} : ${reason}" >> "${mysql_disabled_file}"
1068 for mysql_disabled_dir in \
1069 ${S}/mysql-test/suite/${testsuite} \
1070 ${S}/mysql-test/suite/${testsuite}/t \
1072 [[ -d ${mysql_disabled_dir} ]] && break
1074 if [[ ${mysql_disabled_dir} != "FAILED" ]]; then
1075 echo "${testname} : ${reason}" >> "${mysql_disabled_dir}/disabled.def"
1077 ewarn "Could not find testsuite disabled.def location for ${rawtestname}"
1083 # @FUNCTION: mysql-cmake_use_plugin
1085 # Helper function to enable/disable plugins by use flags
1086 # cmake-utils_use_with is not enough as some references check WITH_ (0|1)
1087 # and some check WITHOUT_. Also, this can easily extend to non-storage plugins.
1088 mysql-cmake_use_plugin() {
1089 [[ -z $2 ]] && die "mysql-cmake_use_plugin <USE flag> <flag name>"
1090 if in_iuse $1 && use $1 ; then
1091 echo "-DWITH_$2=1 -DPLUGIN_$2=YES"
1093 echo "-DWITHOUT_$2=1 -DWITH_$2=0 -DPLUGIN_$2=NO"
1097 # @FUNCTION: mysql_init_vars
1099 # void mysql_init_vars()
1100 # Initialize global variables
1101 # 2005-11-19 <vivo@gentoo.org>
1102 if [[ "${EAPI}x" != "5x" ]]; then
1105 MY_SHAREDSTATEDIR=${MY_SHAREDSTATEDIR="${EPREFIX}/usr/share/mysql"}
1106 MY_SYSCONFDIR=${MY_SYSCONFDIR="${EPREFIX}/etc/mysql"}
1107 MY_LOCALSTATEDIR=${MY_LOCALSTATEDIR="${EPREFIX}/var/lib/mysql"}
1108 MY_LOGDIR=${MY_LOGDIR="${EPREFIX}/var/log/mysql"}
1109 MY_INCLUDEDIR=${MY_INCLUDEDIR="${EPREFIX}/usr/include/mysql"}
1110 MY_LIBDIR=${MY_LIBDIR="${EPREFIX}/usr/$(get_libdir)/mysql"}
1112 if [[ -z "${MY_DATADIR}" ]] ; then
1114 if [[ -f "${MY_SYSCONFDIR}/my.cnf" ]] ; then
1115 MY_DATADIR=`"my_print_defaults" mysqld 2>/dev/null \
1116 | sed -ne '/datadir/s|^--datadir=||p' \
1118 if [[ -z "${MY_DATADIR}" ]] ; then
1119 MY_DATADIR=`grep ^datadir "${MY_SYSCONFDIR}/my.cnf" \
1120 | sed -e 's/.*=\s*//' \
1124 if [[ -z "${MY_DATADIR}" ]] ; then
1125 MY_DATADIR="${MY_LOCALSTATEDIR}"
1126 einfo "Using default MY_DATADIR"
1128 elog "MySQL MY_DATADIR is ${MY_DATADIR}"
1130 if [[ -z "${PREVIOUS_DATADIR}" ]] ; then
1131 if [[ -e "${MY_DATADIR}" ]] ; then
1132 # If you get this and you're wondering about it, see bug #207636
1133 elog "MySQL datadir found in ${MY_DATADIR}"
1134 elog "A new one will not be created."
1135 PREVIOUS_DATADIR="yes"
1137 PREVIOUS_DATADIR="no"
1139 export PREVIOUS_DATADIR
1142 if [[ ${EBUILD_PHASE} == "config" ]]; then
1143 local new_MY_DATADIR
1144 new_MY_DATADIR=`"my_print_defaults" mysqld 2>/dev/null \
1145 | sed -ne '/datadir/s|^--datadir=||p' \
1148 if [[ ( -n "${new_MY_DATADIR}" ) && ( "${new_MY_DATADIR}" != "${MY_DATADIR}" ) ]]; then
1149 ewarn "MySQL MY_DATADIR has changed"
1150 ewarn "from ${MY_DATADIR}"
1151 ewarn "to ${new_MY_DATADIR}"
1152 MY_DATADIR="${new_MY_DATADIR}"
1157 if [ "${MY_SOURCEDIR:-unset}" == "unset" ]; then
1158 MY_SOURCEDIR=${SERVER_URI##*/}
1159 MY_SOURCEDIR=${MY_SOURCEDIR%.tar*}
1162 export MY_SHAREDSTATEDIR MY_SYSCONFDIR
1163 export MY_LIBDIR MY_LOCALSTATEDIR MY_LOGDIR
1164 export MY_INCLUDEDIR MY_DATADIR MY_SOURCEDIR