1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: mysql-multilib.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)
412 mycmakeargs+=( -DINSTALL_MYSQLTESTDIR=share/mysql/mysql-test )
414 mycmakeargs+=( -DINSTALL_MYSQLTESTDIR='' )
417 if in_iuse systemd ; then
418 mycmakeargs+=( -DWITH_SYSTEMD=$(usex systemd) )
421 if use openssl || use libressl ; then
422 mycmakeargs+=( -DWITH_SSL=system )
424 mycmakeargs+=( -DWITH_SSL=bundled )
427 if ! multilib_is_native_abi ; then
428 mycmakeargs+=( -DWITHOUT_TOOLS=1 )
431 if in_iuse bindist ; then
432 # bfd.h is only used starting with 10.1 and can be controlled by NOT_FOR_DISTRIBUTION
433 if multilib_is_native_abi; then
435 -DWITH_READLINE=$(usex bindist 1 0)
436 -DNOT_FOR_DISTRIBUTION=$(usex bindist 0 1)
441 -DNOT_FOR_DISTRIBUTION=0
446 ### TODO: make this system but issues with UTF-8 prevent it
447 mycmakeargs+=( -DWITH_EDITLINE=bundled )
449 if multilib_is_native_abi && use server ; then
450 if [[ ( -n ${MYSQL_DEFAULT_CHARSET} ) && ( -n ${MYSQL_DEFAULT_COLLATION} ) ]]; then
451 ewarn "You are using a custom charset of ${MYSQL_DEFAULT_CHARSET}"
452 ewarn "and a collation of ${MYSQL_DEFAULT_COLLATION}."
453 ewarn "You MUST file bugs without these variables set."
456 -DDEFAULT_CHARSET=${MYSQL_DEFAULT_CHARSET}
457 -DDEFAULT_COLLATION=${MYSQL_DEFAULT_COLLATION}
460 elif ! use latin1 ; then
462 -DDEFAULT_CHARSET=utf8
463 -DDEFAULT_COLLATION=utf8_general_ci
467 -DDEFAULT_CHARSET=latin1
468 -DDEFAULT_COLLATION=latin1_swedish_ci
474 -DMYSQL_UNIX_ADDR=${EPREFIX}/var/run/mysqld/mysqld.sock
475 -DDISABLE_SHARED=$(usex static YES NO)
476 -DWITH_DEBUG=$(usex debug)
477 -DWITH_EMBEDDED_SERVER=$(usex embedded)
478 -DWITH_PROFILING=$(usex profiling)
482 mycmakeargs+=( -DWITH_PIC=1 )
485 if use jemalloc || use tcmalloc ; then
486 mycmakeargs+=( -DWITH_SAFEMALLOC=OFF )
491 -DWITH_ARCHIVE_STORAGE_ENGINE=1
492 -DWITH_BLACKHOLE_STORAGE_ENGINE=1
493 -DWITH_CSV_STORAGE_ENGINE=1
494 -DWITH_HEAP_STORAGE_ENGINE=1
495 -DWITH_INNOBASE_STORAGE_ENGINE=1
496 -DWITH_MYISAMMRG_STORAGE_ENGINE=1
497 -DWITH_MYISAM_STORAGE_ENGINE=1
498 -DWITH_PARTITION_STORAGE_ENGINE=1
501 mycmakeargs+=( -DWITH_FEDERATED_STORAGE_ENGINE=$(usex extraengine) )
505 -DWITHOUT_EMBEDDED_SERVER=1
506 -DEXTRA_CHARSETS=none
507 -DINSTALL_SQLBENCHDIR=
511 # systemtap only works on native ABI bug 530132
512 if multilib_is_native_abi; then
513 mycmakeargs+=( -DENABLE_DTRACE=$(usex systemtap)
514 "${MYSQL_CMAKE_NATIVE_DEFINES[@]}" )
516 mycmakeargs+=( -DENABLE_DTRACE=0
517 "${MYSQL_CMAKE_NONNATIVE_DEFINES[@]}" )
520 mycmakeargs+=( "${MYSQL_CMAKE_EXTRA_DEFINES[@]}" )
522 cmake-utils_src_configure
525 mysql-multilib-r1_src_compile() {
526 local _cmake_args=( "${@}" )
528 multilib-minimal_src_compile
531 multilib_src_compile() {
533 cmake-utils_src_compile "${_cmake_args[@]}"
537 # @FUNCTION: mysql-multilib-r1_src_install
540 mysql-multilib-r1_src_install() {
541 # wrap the config script
542 MULTILIB_CHOST_TOOLS=( /usr/bin/mysql_config )
544 multilib-minimal_src_install
547 multilib_src_install() {
548 debug-print-function ${FUNCNAME} "$@"
550 cmake-utils_src_install
551 # Make sure the vars are correctly initialized
554 # Remove an unnecessary, private config header which will never match between ABIs and is not meant to be used
555 if [[ -f "${D}${MY_INCLUDEDIR}/private/config.h" ]] ; then
556 rm "${D}${MY_INCLUDEDIR}/private/config.h" || die
559 if multilib_is_native_abi; then
562 einfo "Making Convenience links for mysqlcheck multi-call binary"
563 dosym "/usr/bin/mysqlcheck" "/usr/bin/mysqlanalyze"
564 dosym "/usr/bin/mysqlcheck" "/usr/bin/mysqlrepair"
565 dosym "/usr/bin/mysqlcheck" "/usr/bin/mysqloptimize"
567 # INSTALL_LAYOUT=STANDALONE causes cmake to create a /usr/data dir
568 if [[ -d "${ED}/usr/data" ]] ; then
569 rm -Rf "${ED}/usr/data" || die
572 # Unless they explicitly specific USE=test, then do not install the
573 # testsuite. It DOES have a use to be installed, esp. when you want to do a
574 # validation of your database configuration after tuning it.
576 rm -rf "${D}"/${MY_SHAREDSTATEDIR}/mysql-test
579 # Configuration stuff
580 case ${MYSQL_PV_MAJOR} in
581 5.5) mysql_mycnf_version="5.5" ;;
582 5.[6-9]|6*|7*|8*|9*|10*) mysql_mycnf_version="5.6" ;;
584 einfo "Building default my.cnf (${mysql_mycnf_version})"
585 insinto "${MY_SYSCONFDIR#${EPREFIX}}"
586 [[ -f "${S}/scripts/mysqlaccess.conf" ]] && doins "${S}"/scripts/mysqlaccess.conf
587 mycnf_src="my.cnf-${mysql_mycnf_version}"
588 sed -e "s!@DATADIR@!${MY_DATADIR}!g" \
589 "${FILESDIR}/${mycnf_src}" \
590 > "${TMPDIR}/my.cnf.ok" || die
591 use prefix && sed -i -r -e '/^user[[:space:]]*=[[:space:]]*mysql$/d' "${TMPDIR}/my.cnf.ok"
594 -e "/character-set/s|utf8|latin1|g" \
595 "${TMPDIR}/my.cnf.ok" || die
597 eprefixify "${TMPDIR}/my.cnf.ok"
598 newins "${TMPDIR}/my.cnf.ok" my.cnf
601 einfo "Creating initial directories"
602 # Empty directories ...
604 if [[ ${PREVIOUS_DATADIR} != "yes" ]] ; then
605 dodir "${MY_DATADIR#${EPREFIX}}"
606 keepdir "${MY_DATADIR#${EPREFIX}}"
607 chown -R mysql:mysql "${D}/${MY_DATADIR}"
611 for folder in "${MY_LOGDIR#${EPREFIX}}" ; do
614 chown -R mysql:mysql "${ED}/${folder}"
617 einfo "Including support files and sample configurations"
618 docinto "support-files"
620 "${S}"/support-files/my-*.cnf.sh \
621 "${S}"/support-files/magic \
622 "${S}"/support-files/ndb-config-2-node.ini.sh
624 [[ -f $script ]] && dodoc "${script}"
628 for script in "${S}"/scripts/mysql* ; do
629 [[ ( -f $script ) && ( ${script%.sh} == ${script} ) ]] && dodoc "${script}"
633 #Remove mytop if perl is not selected
634 [[ -e "${ED}/usr/bin/mytop" ]] && ! use perl && rm -f "${ED}/usr/bin/mytop"
636 # Percona has decided to rename libmysqlclient to libperconaserverclient
637 # Use a symlink to preserve linkages for those who don't use mysql_config
639 for suffix in ".so" "_r.so" ".a" "_r.a" ; do
640 if [[ -e "${ED}/usr/$(get_libdir)/libperconaserverclient${suffix}" ]] ; then
641 dosym libperconaserverclient${suffix} /usr/$(get_libdir)/libmysqlclient${suffix}
645 if [[ "${PN}" == "mariadb" ]] && use server ; then
646 insinto /usr/include/mysql/private
652 # @FUNCTION: mysql-multilib-r1_pkg_preinst
654 # Warn about ABI changes when switching providers
655 mysql-multilib-r1_pkg_preinst() {
656 debug-print-function ${FUNCNAME} "$@"
658 # Here we need to see if the implementation switched client libraries
659 # We check if this is a new instance of the package and a client library already exists
660 local SHOW_ABI_MESSAGE
661 if [[ -z ${REPLACING_VERSIONS} && -e "${EROOT}usr/$(get_libdir)/libmysqlclient.so" ]] ; then
662 elog "Due to ABI changes when switching between different client libraries,"
663 elog "revdep-rebuild must find and rebuild all packages linking to libmysqlclient."
664 elog "Please run: revdep-rebuild --library libmysqlclient.so.${SUBSLOT:-18}"
665 ewarn "Failure to run revdep-rebuild may cause issues with other programs or libraries"
669 # @FUNCTION: mysql-multilib-r1_pkg_postinst
671 # Run post-installation tasks:
672 # create the dir for logfiles if non-existant
673 # touch the logfiles and secure them
675 # issue required steps for optional features
676 # issue deprecation warnings
677 mysql-multilib-r1_pkg_postinst() {
678 debug-print-function ${FUNCNAME} "$@"
680 # Make sure the vars are correctly initialized
683 # Check FEATURES="collision-protect" before removing this
684 [[ -d "${ROOT}${MY_LOGDIR}" ]] || install -d -m0750 -o mysql -g mysql "${ROOT}${MY_LOGDIR}"
686 # Secure the logfiles
687 touch "${ROOT}${MY_LOGDIR}"/mysql.{log,err}
688 chown mysql:mysql "${ROOT}${MY_LOGDIR}"/mysql*
689 chmod 0660 "${ROOT}${MY_LOGDIR}"/mysql*
691 # Minimal builds don't have the MySQL server
693 docinto "support-files"
695 support-files/my-*.cnf \
696 support-files/magic \
697 support-files/ndb-config-2-node.ini
699 [[ -f "${script}" ]] \
704 for script in scripts/mysql* ; do
705 if [[ -f "${script}" && "${script%.sh}" == "${script}" ]]; then
710 if in_iuse pam && use pam; then
712 elog "This install includes the PAM authentication plugin."
713 elog "To activate and configure the PAM plugin, please read:"
714 if [[ ${PN} == "mariadb" ]] ; then
715 elog "https://mariadb.com/kb/en/mariadb/pam-authentication-plugin/"
716 elif [[ ${PN} == "percona-server" ]] ; then
717 elog "https://www.percona.com/doc/percona-server/5.6/management/pam_plugin.html"
722 if [[ -z "${REPLACING_VERSIONS}" ]] ; then
724 elog "You might want to run:"
725 elog "\"emerge --config =${CATEGORY}/${PF}\""
726 elog "if this is a new install."
728 elog "If you are switching server implentations, you should run the"
729 elog "mysql_upgrade tool."
733 elog "If you are upgrading major versions, you should run the"
734 elog "mysql_upgrade tool."
738 if in_iuse galera && use galera ; then
740 elog "Be sure to edit the my.cnf file to activate your cluster settings."
741 elog "This should be done after running \"emerge --config =${CATEGORY}/${PF}\""
742 elog "The first time the cluster is activated, you should add"
743 elog "--wsrep-new-cluster to the options in /etc/conf.d/mysql for one node."
744 elog "This option should then be removed for subsequent starts."
750 # @FUNCTION: mysql-multilib-r1_getopt
752 # Use my_print_defaults to extract specific config options
753 mysql-multilib-r1_getopt() {
754 local mypd="${EROOT}"/usr/bin/my_print_defaults
757 "${mypd}" $section | sed -n "/^${flag}/p"
760 # @FUNCTION: mysql-multilib-r1_getoptval
762 # Use my_print_defaults to extract specific config options
763 mysql-multilib-r1_getoptval() {
764 local mypd="${EROOT}"/usr/bin/my_print_defaults
767 local extra_options="${3}"
768 "${mypd}" $extra_options $section | sed -n "/^${flag}/s,${flag},,gp"
771 # @FUNCTION: mysql-multilib-r1_pkg_config
773 # Configure mysql environment.
774 mysql-multilib-r1_pkg_config() {
776 debug-print-function ${FUNCNAME} "$@"
778 local old_MY_DATADIR="${MY_DATADIR}"
779 local old_HOME="${HOME}"
780 # my_print_defaults needs to read stuff in $HOME/.my.cnf
781 export HOME=${EPREFIX}/root
783 # Make sure the vars are correctly initialized
786 [[ -z "${MY_DATADIR}" ]] && die "Sorry, unable to find MY_DATADIR"
787 if [[ ! -x "${EROOT}/usr/sbin/mysqld" ]] ; then
788 die "Minimal builds do NOT include the MySQL server"
791 if [[ ( -n "${MY_DATADIR}" ) && ( "${MY_DATADIR}" != "${old_MY_DATADIR}" ) ]]; then
792 local MY_DATADIR_s="${ROOT}/${MY_DATADIR}"
793 MY_DATADIR_s="${MY_DATADIR_s%%/}"
794 local old_MY_DATADIR_s="${ROOT}/${old_MY_DATADIR}"
795 old_MY_DATADIR_s="${old_MY_DATADIR_s%%/}"
797 if [[ ( -d "${old_MY_DATADIR_s}" ) && ( "${old_MY_DATADIR_s}" != / ) ]]; then
798 if [[ -d "${MY_DATADIR_s}" ]]; then
799 ewarn "Both ${old_MY_DATADIR_s} and ${MY_DATADIR_s} exist"
800 ewarn "Attempting to use ${MY_DATADIR_s} and preserving ${old_MY_DATADIR_s}"
802 elog "Moving MY_DATADIR from ${old_MY_DATADIR_s} to ${MY_DATADIR_s}"
803 mv --strip-trailing-slashes -T "${old_MY_DATADIR_s}" "${MY_DATADIR_s}" \
804 || die "Moving MY_DATADIR failed"
807 ewarn "Previous MY_DATADIR (${old_MY_DATADIR_s}) does not exist"
808 if [[ -d "${MY_DATADIR_s}" ]]; then
809 ewarn "Attempting to use ${MY_DATADIR_s}"
811 eerror "New MY_DATADIR (${MY_DATADIR_s}) does not exist"
812 die "Configuration Failed! Please reinstall ${CATEGORY}/${PN}"
821 if [ -z "${MYSQL_ROOT_PASSWORD}" ]; then
822 local tmp_mysqld_password_source=
824 for tmp_mysqld_password_source in mysql client; do
825 einfo "Trying to get password for mysql 'root' user from '${tmp_mysqld_password_source}' section ..."
826 MYSQL_ROOT_PASSWORD="$(mysql-multilib-r1_getoptval "${tmp_mysqld_password_source}" password)"
827 if [[ -n "${MYSQL_ROOT_PASSWORD}" ]]; then
828 if [[ ${MYSQL_ROOT_PASSWORD} == *$'\n'* ]]; then
829 ewarn "Ignoring password from '${tmp_mysqld_password_source}' section due to newline character (do you have multiple password options set?)!"
834 einfo "Found password in '${tmp_mysqld_password_source}' section!"
839 # Sometimes --show is required to display passwords in some implementations of my_print_defaults
840 if [[ "${MYSQL_ROOT_PASSWORD}" == '*****' ]]; then
841 MYSQL_ROOT_PASSWORD="$(mysql-multilib-r1_getoptval "${tmp_mysqld_password_source}" password --show)"
844 unset tmp_mysqld_password_source
846 MYSQL_TMPDIR="$(mysql-multilib-r1_getoptval mysqld tmpdir)"
847 # These are dir+prefix
848 MYSQL_RELAY_LOG="$(mysql-multilib-r1_getoptval mysqld relay-log)"
849 MYSQL_RELAY_LOG=${MYSQL_RELAY_LOG%/*}
850 MYSQL_LOG_BIN="$(mysql-multilib-r1_getoptval mysqld log-bin)"
851 MYSQL_LOG_BIN=${MYSQL_LOG_BIN%/*}
853 if [[ ! -d "${ROOT}"/$MYSQL_TMPDIR ]]; then
854 einfo "Creating MySQL tmpdir $MYSQL_TMPDIR"
855 install -d -m 770 -o mysql -g mysql "${EROOT}"/$MYSQL_TMPDIR
857 if [[ ! -d "${ROOT}"/$MYSQL_LOG_BIN ]]; then
858 einfo "Creating MySQL log-bin directory $MYSQL_LOG_BIN"
859 install -d -m 770 -o mysql -g mysql "${EROOT}"/$MYSQL_LOG_BIN
861 if [[ ! -d "${EROOT}"/$MYSQL_RELAY_LOG ]]; then
862 einfo "Creating MySQL relay-log directory $MYSQL_RELAY_LOG"
863 install -d -m 770 -o mysql -g mysql "${EROOT}"/$MYSQL_RELAY_LOG
866 if [[ -d "${ROOT}/${MY_DATADIR}/mysql" ]] ; then
867 ewarn "You have already a MySQL database in place."
868 ewarn "(${ROOT}/${MY_DATADIR}/*)"
869 ewarn "Please rename or delete it if you wish to replace it."
870 die "MySQL database already exists!"
873 # Bug #213475 - MySQL _will_ object strenously if your machine is named
874 # localhost. Also causes weird failures.
875 [[ "${HOSTNAME}" == "localhost" ]] && die "Your machine must NOT be named localhost"
877 if [ -z "${MYSQL_ROOT_PASSWORD}" ]; then
879 einfo "Please provide a password for the mysql 'root' user now"
880 einfo "or through the ${HOME}/.my.cnf file."
881 ewarn "Avoid [\"'\\_%] characters in the password"
882 read -rsp " >" pwd1 ; echo
884 einfo "Retype the password"
885 read -rsp " >" pwd2 ; echo
887 if [[ "x$pwd1" != "x$pwd2" ]] ; then
888 die "Passwords are not the same"
890 MYSQL_ROOT_PASSWORD="${pwd1}"
895 local sqltmp="$(emktemp)"
897 # Fix bug 446200. Don't reference host my.cnf, needs to come first,
898 # see http://bugs.mysql.com/bug.php?id=31312
899 use prefix && options="${options} '--defaults-file=${MY_SYSCONFDIR}/my.cnf'"
901 local help_tables="${ROOT}${MY_SHAREDSTATEDIR}/fill_help_tables.sql"
902 [[ -r "${help_tables}" ]] \
903 && cp "${help_tables}" "${TMPDIR}/fill_help_tables.sql" \
904 || touch "${TMPDIR}/fill_help_tables.sql"
905 help_tables="${TMPDIR}/fill_help_tables.sql"
907 # Figure out which options we need to disable to do the setup
908 local helpfile="${TMPDIR}/mysqld-help"
909 ${EROOT}/usr/sbin/mysqld --verbose --help >"${helpfile}" 2>/dev/null
910 for opt in grant-tables host-cache name-resolve networking slave-start \
911 federated ssl log-bin relay-log slow-query-log external-locking \
912 ndbcluster log-slave-updates \
914 optexp="--(skip-)?${opt}" optfull="--loose-skip-${opt}"
915 egrep -sq -- "${optexp}" "${helpfile}" && options="${options} ${optfull}"
917 # But some options changed names
918 egrep -sq external-locking "${helpfile}" && \
919 options="${options/skip-locking/skip-external-locking}"
921 use prefix || options="${options} --user=mysql"
923 einfo "Creating the mysql database and setting proper permissions on it ..."
925 # Now that /var/run is a tmpfs mount point, we need to ensure it exists before using it
926 PID_DIR="${EROOT}/var/run/mysqld"
927 if [[ ! -d "${PID_DIR}" ]]; then
928 mkdir -p "${PID_DIR}" || die "Could not create pid directory"
929 chown mysql:mysql "${PID_DIR}" || die "Could not set ownership on pid directory"
930 chmod 755 "${PID_DIR}" || die "Could not set permissions on pid directory"
933 pushd "${TMPDIR}" &>/dev/null
935 # Filling timezones, see
936 # http://dev.mysql.com/doc/mysql/en/time-zone-support.html
937 "${EROOT}/usr/bin/mysql_tzinfo_to_sql" "${EROOT}/usr/share/zoneinfo" > "${sqltmp}" 2>/dev/null
940 local initialize_options
941 if [[ ${PN} == "mysql" || ${PN} == "percona-server" ]] && version_is_at_least "5.7.6" ; then
942 # --initialize-insecure will not set root password
943 # --initialize would set a random one in the log which we don't need as we set it ourselves
944 cmd=( "${EROOT}usr/sbin/mysqld" )
945 initialize_options="--initialize-insecure '--init-file=${sqltmp}'"
946 sqltmp="" # the initialize will take care of it
948 cmd=( "${EROOT}usr/share/mysql/scripts/mysql_install_db" )
949 [[ -f "${cmd}" ]] || cmd=( "${EROOT}usr/bin/mysql_install_db" )
950 if [[ -r "${help_tables}" ]] ; then
951 cat "${help_tables}" >> "${sqltmp}"
954 cmd+=( "--basedir=${EPREFIX}/usr" ${options} "--datadir=${ROOT}/${MY_DATADIR}" "--tmpdir=${ROOT}/${MYSQL_TMPDIR}" ${initialize_options} )
955 einfo "Command: ${cmd[*]}"
957 >"${TMPDIR}"/mysql_install_db.log 2>&1
958 if [ $? -ne 0 ]; then
959 grep -B5 -A999 -i "ERROR" "${TMPDIR}"/mysql_install_db.log 1>&2
960 die "Failed to initialize mysqld. Please review ${EPREFIX}/var/log/mysql/mysqld.err AND ${TMPDIR}/mysql_install_db.log"
963 [[ -f "${ROOT}/${MY_DATADIR}/mysql/user.frm" ]] \
964 || die "MySQL databases not installed"
965 chown -R mysql:mysql "${ROOT}/${MY_DATADIR}" 2>/dev/null
966 chmod 0750 "${ROOT}/${MY_DATADIR}" 2>/dev/null
968 local socket="${EROOT}/var/run/mysqld/mysqld${RANDOM}.sock"
969 local pidfile="${EROOT}/var/run/mysqld/mysqld${RANDOM}.pid"
970 local mysqld="${EROOT}/usr/sbin/mysqld \
972 $(use prefix || echo --user=mysql) \
974 --basedir=${EROOT}/usr \
975 --datadir=${ROOT}/${MY_DATADIR} \
976 --max_allowed_packet=8M \
977 --net_buffer_length=16K \
978 --default-storage-engine=MyISAM \
980 --pid-file=${pidfile}
981 --tmpdir=${ROOT}/${MYSQL_TMPDIR}"
982 #einfo "About to start mysqld: ${mysqld}"
983 ebegin "Starting mysqld"
984 einfo "Command ${mysqld}"
987 while ! [[ -S "${socket}" || "${maxtry}" -lt 1 ]] ; do
988 maxtry=$((${maxtry}-1))
994 if ! [[ -S "${socket}" ]]; then
995 die "Completely failed to start up mysqld with: ${mysqld}"
998 ebegin "Setting root password"
999 # Do this from memory, as we don't want clear text passwords in temp files
1000 local sql="UPDATE mysql.user SET Password = PASSWORD('${MYSQL_ROOT_PASSWORD}') WHERE USER='root'; FLUSH PRIVILEGES"
1001 "${EROOT}/usr/bin/mysql" \
1002 --socket=${socket} \
1007 if [[ -n "${sqltmp}" ]] ; then
1008 ebegin "Loading \"zoneinfo\", this step may require a few seconds"
1009 "${EROOT}/usr/bin/mysql" \
1010 --socket=${socket} \
1013 --password="${MYSQL_ROOT_PASSWORD}" \
1017 [[ $rc -ne 0 ]] && ewarn "Failed to load zoneinfo!"
1020 # Stop the server and cleanup
1021 einfo "Stopping the server ..."
1022 kill $(< "${pidfile}" )
1033 # @FUNCTION: mysql-multilib-r1_disable_test
1035 # Helper function to disable specific tests.
1036 mysql-multilib-r1_disable_test() {
1038 local rawtestname testname testsuite reason mysql_disabled_file mysql_disabled_dir
1039 rawtestname="${1}" ; shift
1041 ewarn "test '${rawtestname}' disabled: '${reason}'"
1043 testsuite="${rawtestname/.*}"
1044 testname="${rawtestname/*.}"
1045 for mysql_disabled_file in \
1046 ${S}/mysql-test/disabled.def \
1047 ${S}/mysql-test/t/disabled.def ; do
1048 [[ -f ${mysql_disabled_file} ]] && break
1050 #mysql_disabled_file="${S}/mysql-test/t/disabled.def"
1051 #einfo "rawtestname=${rawtestname} testname=${testname} testsuite=${testsuite}"
1052 echo ${testname} : ${reason} >> "${mysql_disabled_file}"
1054 if [[ ( -n ${testsuite} ) && ( ${testsuite} != "main" ) ]]; then
1055 for mysql_disabled_file in \
1056 ${S}/mysql-test/suite/${testsuite}/disabled.def \
1057 ${S}/mysql-test/suite/${testsuite}/t/disabled.def \
1059 [[ -f ${mysql_disabled_file} ]] && break
1061 if [[ ${mysql_disabled_file} != "FAILED" ]]; then
1062 echo "${testname} : ${reason}" >> "${mysql_disabled_file}"
1064 for mysql_disabled_dir in \
1065 ${S}/mysql-test/suite/${testsuite} \
1066 ${S}/mysql-test/suite/${testsuite}/t \
1068 [[ -d ${mysql_disabled_dir} ]] && break
1070 if [[ ${mysql_disabled_dir} != "FAILED" ]]; then
1071 echo "${testname} : ${reason}" >> "${mysql_disabled_dir}/disabled.def"
1073 ewarn "Could not find testsuite disabled.def location for ${rawtestname}"
1079 # @FUNCTION: mysql-cmake_use_plugin
1081 # Helper function to enable/disable plugins by use flags
1082 # cmake-utils_use_with is not enough as some references check WITH_ (0|1)
1083 # and some check WITHOUT_. Also, this can easily extend to non-storage plugins.
1084 mysql-cmake_use_plugin() {
1085 [[ -z $2 ]] && die "mysql-cmake_use_plugin <USE flag> <flag name>"
1086 if in_iuse $1 && use $1 ; then
1087 echo "-DWITH_$2=1 -DPLUGIN_$2=YES"
1089 echo "-DWITHOUT_$2=1 -DWITH_$2=0 -DPLUGIN_$2=NO"
1093 # @FUNCTION: mysql_init_vars
1095 # void mysql_init_vars()
1096 # Initialize global variables
1097 # 2005-11-19 <vivo@gentoo.org>
1098 if [[ "${EAPI}x" != "5x" ]]; then
1101 MY_SHAREDSTATEDIR=${MY_SHAREDSTATEDIR="${EPREFIX}/usr/share/mysql"}
1102 MY_SYSCONFDIR=${MY_SYSCONFDIR="${EPREFIX}/etc/mysql"}
1103 MY_LOCALSTATEDIR=${MY_LOCALSTATEDIR="${EPREFIX}/var/lib/mysql"}
1104 MY_LOGDIR=${MY_LOGDIR="${EPREFIX}/var/log/mysql"}
1105 MY_INCLUDEDIR=${MY_INCLUDEDIR="${EPREFIX}/usr/include/mysql"}
1106 MY_LIBDIR=${MY_LIBDIR="${EPREFIX}/usr/$(get_libdir)/mysql"}
1108 if [[ -z "${MY_DATADIR}" ]] ; then
1110 if [[ -f "${MY_SYSCONFDIR}/my.cnf" ]] ; then
1111 MY_DATADIR=`"my_print_defaults" mysqld 2>/dev/null \
1112 | sed -ne '/datadir/s|^--datadir=||p' \
1114 if [[ -z "${MY_DATADIR}" ]] ; then
1115 MY_DATADIR=`grep ^datadir "${MY_SYSCONFDIR}/my.cnf" \
1116 | sed -e 's/.*=\s*//' \
1120 if [[ -z "${MY_DATADIR}" ]] ; then
1121 MY_DATADIR="${MY_LOCALSTATEDIR}"
1122 einfo "Using default MY_DATADIR"
1124 elog "MySQL MY_DATADIR is ${MY_DATADIR}"
1126 if [[ -z "${PREVIOUS_DATADIR}" ]] ; then
1127 if [[ -e "${MY_DATADIR}" ]] ; then
1128 # If you get this and you're wondering about it, see bug #207636
1129 elog "MySQL datadir found in ${MY_DATADIR}"
1130 elog "A new one will not be created."
1131 PREVIOUS_DATADIR="yes"
1133 PREVIOUS_DATADIR="no"
1135 export PREVIOUS_DATADIR
1138 if [[ ${EBUILD_PHASE} == "config" ]]; then
1139 local new_MY_DATADIR
1140 new_MY_DATADIR=`"my_print_defaults" mysqld 2>/dev/null \
1141 | sed -ne '/datadir/s|^--datadir=||p' \
1144 if [[ ( -n "${new_MY_DATADIR}" ) && ( "${new_MY_DATADIR}" != "${MY_DATADIR}" ) ]]; then
1145 ewarn "MySQL MY_DATADIR has changed"
1146 ewarn "from ${MY_DATADIR}"
1147 ewarn "to ${new_MY_DATADIR}"
1148 MY_DATADIR="${new_MY_DATADIR}"
1153 if [ "${MY_SOURCEDIR:-unset}" == "unset" ]; then
1154 MY_SOURCEDIR=${SERVER_URI##*/}
1155 MY_SOURCEDIR=${MY_SOURCEDIR%.tar*}
1158 export MY_SHAREDSTATEDIR MY_SYSCONFDIR
1159 export MY_LIBDIR MY_LOCALSTATEDIR MY_LOGDIR
1160 export MY_INCLUDEDIR MY_DATADIR MY_SOURCEDIR