/[gentoo-x86]/eclass/mysql.eclass
Gentoo

Contents of /eclass/mysql.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations) (download)
Wed Jan 4 20:25:14 2006 UTC (8 years, 11 months ago) by vivo
Branch: MAIN
Changes since 1.1: +2 -2 lines
Added pkg_config to EXPORT

1 vivo 1.1 # Copyright 1999-2005 Gentoo Foundation
2     # Distributed under the terms of the GNU General Public License v2
3 vivo 1.2 # $Header: /var/cvsroot/gentoo-x86/eclass/mysql.eclass,v 1.1 2006/01/01 18:45:38 vivo Exp $
4 vivo 1.1
5     # Author: Francesco Riosa <vivo at gentoo.org>
6     # Maintainer: Francesco Riosa <vivo at gentoo.org>
7    
8     inherit eutils flag-o-matic gnuconfig mysql_fx
9    
10     #major, minor only in the slot
11     SLOT=$(( ${MYSQL_VERSION_ID} / 10000 ))
12    
13     # shorten the path because the socket path length must be shorter than 107 chars
14     # and we will run a mysql server during test phase
15     S="${WORKDIR}/${PN}"
16    
17     DESCRIPTION="A fast, multi-threaded, multi-user SQL database server"
18     HOMEPAGE="http://www.mysql.com/"
19     NEWP="${PN}-${PV/_/-}"
20     SRC_URI="mirror://mysql/Downloads/MySQL-${PV%.*}/${NEWP}.tar.gz
21     mirror://gentoo/mysql-extras-20051220.tar.bz2"
22    
23     LICENSE="GPL-2"
24     KEYWORDS="-*"
25     IUSE="big-tables berkdb debug minimal perl selinux ssl static"
26     RESTRICT="primaryuri"
27    
28     mysql_version_is_at_least "4.01.03.00" \
29     && IUSE="${IUSE} cluster utf8 extraengine"
30    
31     mysql_version_is_at_least "5.00.18.00" \
32     && IUSE="${IUSE} max-idx-128"
33    
34     mysql_version_is_at_least "5.01.00.00" \
35     && IUSE="${IUSE} innodb"
36    
37 vivo 1.2 EXPORT_FUNCTIONS pkg_setup src_unpack src_compile src_install pkg_preinst pkg_postinst pkg_config pkg_postrm
38 vivo 1.1
39     mysql_pkg_setup() {
40    
41     enewgroup mysql 60 || die "problem adding group mysql"
42     enewuser mysql 60 -1 /dev/null mysql \
43     || die "problem adding user mysql"
44     }
45    
46     mysql_src_unpack() {
47    
48     mysql_init_vars
49    
50     if useq static && useq ssl; then
51     local msg="MySQL does not support building statically with SSL support"
52     eerror "${msg}"
53     die "${msg}"
54     fi
55    
56     if mysql_version_is_at_least "4.01.03.00" \
57     && useq cluster \
58     || useq extraengine \
59     && useq minimal ; then
60     die "USEs cluster, extraengine conflicts with \"minimal\""
61     fi
62    
63     unpack ${A} || die
64    
65     mv "${WORKDIR}/${NEWP}" "${S}"
66     cd "${S}"
67    
68     EPATCH_SUFFIX="patch"
69     mkdir -p "${EPATCH_SOURCE}" || die "unable to create epatch directory"
70     mysql_mv_patches
71     epatch || die "failed to apply all patches"
72    
73     # additional check, remove bundled zlib
74     rm -f "${S}/zlib/"*.[ch]
75     sed -i -e "s/zlib\/Makefile dnl/dnl zlib\/Makefile/" "${S}/configure.in"
76     rm -f scripts/mysqlbug
77    
78     # Multilib issue with zlib detection
79     mysql_version_is_at_least "5.00.15.00" \
80     && sed -i -e "s:zlib_dir/lib:zlib_dir/$(get_libdir):g" \
81     "${S}/config/ac-macros/zlib.m4"
82    
83     # Make charsets install in the right place
84     find . -name 'Makefile.am' \
85     -exec sed --in-place -e 's!$(pkgdatadir)!'${MY_SHAREDSTATEDIR}'!g' {} \;
86    
87     # Manage mysqlmanager
88     mysql_version_is_at_least "5.00.15.00" \
89     && sed -i -e "s!@GENTOO_EXT@!${MY_SUFFIX}!g" \
90     -e "s!@GENTOO_SOCK_PATH@!var/run/mysqld!g" \
91     "${S}/server-tools/instance-manager/Makefile.am"
92    
93     # remove what need to be recreated, so we are sure it's actually done
94     find . -name Makefile -o -name Makefile.in -o -name configure -exec rm -f {} \;
95     rm ltmain.sh
96    
97     local rebuilddirlist d buildstep bdbdir
98    
99     if mysql_version_is_at_least "5.01.00.00" ; then
100     rebuilddirlist=". storage/innobase"
101     bdbdir='storage/bdb/dist'
102     else
103     rebuilddirlist=". innobase"
104     bdbdir='bdb/dist'
105     fi
106    
107     for d in ${rebuilddirlist}; do
108     einfo "reconfiguring dir \"${d}\""
109     pushd "${d}"
110     for buildstep in \
111     'libtoolize --copy --force' \
112     'aclocal --force' \
113     'autoheader --force -Wnone' \
114     'autoconf --force -Wnone' \
115     'automake --force --force-missing -Wnone' \
116     'gnuconfig_update'
117     do
118     einfo "performing ${buildstep}"
119     ${buildstep} || die "failed ${buildstep/ */} dir \"${d}\""
120     done
121     popd
122     done
123    
124     if ! mysql_check_version_range "5.01.00.00 to 5.01.06.99" ; then
125     [[ -w "${bdbdir}/ltmain.sh" ]] && cp ltmain.sh "${bdbdir}/ltmain.sh"
126     pushd "${bdbdir}" && sh s_all || die "failed bdb reconfigure"
127     popd
128     fi
129    
130     }
131    
132     src_compile() {
133    
134     mysql_init_vars
135     local myconf
136    
137     if useq static ; then
138     myconf="${myconf} --with-mysqld-ldflags=-all-static"
139     myconf="${myconf} --with-client-ldflags=-all-static"
140     myconf="${myconf} --disable-shared"
141     else
142     myconf="${myconf} --enable-shared --enable-static"
143     fi
144    
145     #myconf="${myconf} `use_with tcpd libwrap`"
146     myconf="${myconf} --without-libwrap"
147    
148     if useq ssl ; then
149     # --with-vio is not needed anymore, it's on by default and
150     # has been removed from configure
151     mysql_version_is_at_least "5.00.04.00" || myconf="${myconf} --with-vio"
152     if mysql_version_is_at_least "5.00.06.00" ; then
153     # yassl-0.96 is young break with gcc-4.0 || amd64
154     #myconf="${myconf} --with-yassl"
155     myconf="${myconf} --with-openssl"
156     else
157     myconf="${myconf} --with-openssl"
158     fi
159     else
160     myconf="${myconf} --without-openssl"
161     fi
162    
163     if useq debug; then
164     myconf="${myconf} --with-debug=full"
165     else
166     myconf="${myconf} --without-debug"
167     mysql_version_is_at_least "4.01.03.00" && useq cluster && myconf="${myconf} --without-ndb-debug"
168     fi
169    
170     # benchmarking stuff needs perl
171     # and shouldn't be bothered with on minimal builds
172     if useq perl && ! useq minimal; then
173     myconf="${myconf} --with-bench"
174     else
175     myconf="${myconf} --without-bench"
176     fi
177    
178     # these are things we exclude from a minimal build
179     # note that the server actually does get built and installed
180     # but we then delete it before packaging.
181     local minimal_exclude_list="server embedded-server extra-tools innodb"
182     if ! useq minimal; then
183     for i in ${minimal_exclude_list}; do
184     myconf="${myconf} --with-${i}"
185     done
186    
187     if useq static ; then
188     myconf="${myconf} --without-raid"
189     ewarn "disabling raid support, has problem with static"
190     else
191     myconf="${myconf} --with-raid"
192     fi
193    
194     if ! mysql_version_is_at_least "5.00.00.00" ; then
195     if mysql_version_is_at_least "4.01.00.00" && useq utf8; then
196     myconf="${myconf} --with-charset=utf8"
197     myconf="${myconf} --with-collation=utf8_general_ci"
198     else
199     myconf="${myconf} --with-charset=latin1"
200     myconf="${myconf} --with-collation=latin1_swedish_ci"
201     fi
202     fi
203    
204     # optional again from 2005-12-05
205     if mysql_version_is_at_least "5.01.00.00" ; then
206     myconf="${myconf} $(use_with innodb)"
207     else
208     myconf="${myconf} --with-innodb"
209     fi
210    
211     # lots of chars
212     myconf="${myconf} --with-extra-charsets=all"
213    
214     #The following fix is due to a bug with bdb on sparc's. See:
215     #http://www.geocrawler.com/mail/msg.php3?msg_id=4754814&list=8
216     # it comes down to non-64-bit safety problems
217     if useq sparc || useq alpha || useq hppa || useq mips || useq amd64 \
218     || mysql_check_version_range "5.01.00.00 to 5.01.06.99"
219     then
220     ewarn "bdb berkeley-db disabled due to arch or version"
221     myconf="${myconf} --without-berkeley-db"
222     else
223     useq berkdb \
224     && myconf="${myconf} --with-berkeley-db=./bdb" \
225     || myconf="${myconf} --without-berkeley-db"
226     fi
227    
228     if mysql_version_is_at_least "4.01.03.00" ; then
229     #myconf="${myconf} $(use_with geometry)"
230     myconf="${myconf} --with-geometry"
231     myconf="${myconf} $(use_with cluster ndbcluster)"
232     fi
233    
234     mysql_version_is_at_least "4.01.11.00" && myconf="${myconf} `use_with big-tables`"
235     else
236     for i in ${minimal_exclude_list}; do
237     myconf="${myconf} --without-${i}"
238     done
239     myconf="${myconf} --without-berkeley-db"
240     myconf="${myconf} --with-extra-charsets=none"
241     fi
242    
243     if mysql_version_is_at_least "4.01.03.00" && useq extraengine; then
244     # http://dev.mysql.com/doc/mysql/en/archive-storage-engine.html
245     myconf="${myconf} --with-archive-storage-engine"
246     # http://dev.mysql.com/doc/mysql/en/csv-storage-engine.html
247    
248     mysql_version_is_at_least "4.01.04.00" \
249     && myconf="${myconf} --with-csv-storage-engine"
250    
251     mysql_version_is_at_least "4.01.11.00" \
252     && myconf="${myconf} --with-blackhole-storage-engine"
253    
254     # http://dev.mysql.com/doc/mysql/en/federated-description.html
255     # http://dev.mysql.com/doc/mysql/en/federated-limitations.html
256     if mysql_version_is_at_least "5.00.03.00" ; then
257     einfo "before to use federated engine be sure to read"
258     einfo "http://dev.mysql.com/doc/refman/5.0/en/federated-limitations.html"
259     myconf="${myconf} --with-federated-storage-engine"
260    
261     # http://dev.mysql.com/doc/refman/5.1/en/partitioning-overview.html
262     if mysql_version_is_at_least "5.01.00.00" ; then
263     myconf="${myconf} --with-partition"
264     fi
265     fi
266    
267     mysql_version_is_at_least "5.00.18.00" \
268     && useq "max-idx-128" \
269     && myconf="${myconf} --with-max-indexes=128"
270     fi
271    
272     #Bug #114895,Bug #110149
273     filter-flags "-O" "-O[01]"
274     #glibc-2.3.2_pre fix; bug #16496
275     append-flags "-DHAVE_ERRNO_AS_DEFINE=1"
276    
277     #the compiler flags are as per their "official" spec ;)
278     #CFLAGS="${CFLAGS/-O?/} -O3" \
279     export CXXFLAGS="${CXXFLAGS} -felide-constructors -fno-exceptions -fno-rtti"
280     mysql_version_is_at_least "5.00.00.00" \
281     && export CXXFLAGS="${CXXFLAGS} -fno-implicit-templates"
282    
283     econf \
284     --program-suffix="${MY_SUFFIX}" \
285     --libexecdir="/usr/sbin" \
286     --sysconfdir="${MY_SYSCONFDIR}" \
287     --localstatedir="${MY_LOCALSTATEDIR}" \
288     --sharedstatedir="${MY_SHAREDSTATEDIR}" \
289     --libdir="${MY_LIBDIR}" \
290     --includedir="${MY_INCLUDEDIR}" \
291     --with-low-memory \
292     --enable-assembler \
293     --enable-local-infile \
294     --with-mysqld-user=mysql \
295     --with-client-ldflags=-lstdc++ \
296     --enable-thread-safe-client \
297     --with-comment="Gentoo Linux ${PF}" \
298     --with-unix-socket-path="/var/run/mysqld/mysqld${MY_SUFFIX}.sock" \
299     --with-zlib-dir=/usr \
300     --with-lib-ccflags="-fPIC" \
301     --without-readline \
302     --without-docs \
303     ${myconf} || die "bad ./configure"
304    
305     # TODO Move this before autoreconf !!!
306     find . -name 'Makefile' \
307     -exec sed --in-place \
308     -e 's|^pkglibdir\s*=\s*$(libdir)/mysql|pkglibdir = $(libdir)|' \
309     -e 's|^pkgincludedir\s*=\s*$(includedir)/mysql|pkgincludedir = $(includedir)|' \
310     {} \;
311    
312     emake || die "compile problem"
313     }
314    
315     mysql_src_install() {
316    
317     mysql_init_vars
318     make install DESTDIR="${D}" benchdir_root="${MY_SHAREDSTATEDIR}" || die
319    
320     insinto "${MY_INCLUDEDIR}"
321     doins "${MY_INCLUDEDIR}"/my_{config,dir}.h
322    
323     # convenience links
324     dosym "/usr/bin/mysqlcheck${MY_SUFFIX}" "/usr/bin/mysqlanalyze${MY_SUFFIX}"
325     dosym "/usr/bin/mysqlcheck${MY_SUFFIX}" "/usr/bin/mysqlrepair${MY_SUFFIX}"
326     dosym "/usr/bin/mysqlcheck${MY_SUFFIX}" "/usr/bin/mysqloptimize${MY_SUFFIX}"
327    
328     # various junk (my-*.cnf moved elsewhere)
329     rm -rf "${D}/usr/share/info"
330     for removeme in "mysql-log-rotate" mysql.server* \
331     binary-configure* my-*.cnf mi_test_all*
332     do
333     rm -f ${D}/usr/share/mysql/${removeme}
334     done
335    
336     # oops
337     mysql_check_version_range "5.00.16.00 to 5.00.18.99" \
338     && cp "${WORKDIR}/mysql-extras/fill_help_tables.sql-5.0.15" "${D}/usr/share/mysql${MY_SUFFIX}/"
339    
340     # TODO change at Makefile-am level
341     for moveme in "mysql_fix_privilege_tables.sql" \
342     "fill_help_tables.sql" "ndb-config-2-node.ini"
343     do
344     mv "${D}/usr/share/mysql/${moveme}" "${D}/usr/share/mysql${MY_SUFFIX}/" 2>/dev/null
345     done
346    
347     if [[ -n "${MY_SUFFIX}" ]] ; then
348     local notcatched=$(ls "${D}/usr/share/mysql"/*)
349     if [[ -n "${notcatched}" ]] ; then
350     ewarn "QA notice"
351     ewarn "${notcatched} files in /usr/share/mysql"
352     ewarn "bug mysql-herd to manage them"
353     fi
354     rm -rf "${D}/usr/share/mysql"
355     fi
356    
357     # clean up stuff for a minimal build
358     # this is anything server-specific
359     if useq minimal; then
360     rm -rf ${D}${MY_SHAREDSTATEDIR}/{mysql-test,sql-bench}
361     rm -f ${D}/usr/bin/{mysql{_install_db,manager*,_secure_installation,_fix_privilege_tables,hotcopy,_convert_table_format,d_multi,_fix_extensions,_zap,_explain_log,_tableinfo,d_safe,_install,_waitpid,binlog,test},myisam*,isam*,pack_isam}
362     rm -f "${D}/usr/sbin/mysqld${MY_SUFFIX}"
363     rm -f ${D}${MY_LIBDIR}/lib{heap,merge,nisam,my{sys,strings,sqld,isammrg,isam},vio,dbug}.a
364     fi
365    
366     # config stuff
367     insinto "${MY_SYSCONFDIR}"
368     doins scripts/mysqlaccess.conf
369     newins "${FILESDIR}/my.cnf-4.1" my.cnf
370     insinto "/etc/conf.d"
371     newins "${FILESDIR}/mysql-slot.conf.d-r1" "mysql"
372     mysql_version_is_at_least "5.00.11.00" \
373     && newins "${FILESDIR}/mysqlmanager-slot.conf.d" "mysqlmanager"
374    
375     local charset='utf8'
376     ! useq utf8 && local charset='latin1'
377     sed --in-place \
378     -e "s/@MY_SUFFIX@/${MY_SUFFIX}/" \
379     -e "s/@CHARSET@/${charset}/" \
380     "${D}/etc/mysql${MY_SUFFIX}/my.cnf"
381    
382     # minimal builds don't have the server
383     if ! useq minimal; then
384     exeinto /etc/init.d
385     newexe "${FILESDIR}/mysql-slot.rc6-r1" "mysql"
386     mysql_version_is_at_least "5.00.11.00" \
387     && newexe "${FILESDIR}/mysqlmanager-slot.rc6" "mysqlmanager"
388     insinto /etc/logrotate.d
389     # TODO
390     newins "${FILESDIR}/logrotate.mysql" "mysql${MY_SUFFIX}"
391    
392     #empty dirs...
393     diropts "-m0750"
394     if [[ "${PREVIOUS_DATADIR}" != "yes" ]] ; then
395     dodir "${DATADIR}"
396     keepdir "${DATADIR}"
397     chown -R mysql:mysql "${D}/${DATADIR}"
398     fi
399    
400     diropts "-m0755"
401     for folder in "${MY_LOGDIR}" "/var/run/mysqld" ; do
402     dodir "${folder}"
403     keepdir "${folder}"
404     chown -R mysql:mysql "${D}/${folder}"
405     done
406     fi
407    
408     # docs
409     dodoc README COPYING ChangeLog EXCEPTIONS-CLIENT INSTALL-SOURCE
410     # minimal builds don't have the server
411     if ! useq minimal; then
412     docinto "support-files"
413     for script in \
414     support-files/my-*.cnf \
415     support-files/magic \
416     support-files/ndb-config-2-node.ini
417     do
418     dodoc "${script}"
419     done
420    
421     docinto "scripts"
422     for script in \
423     $(ls scripts/mysql* | grep -v '.sh$')
424     do
425     dodoc "${script}"
426     done
427     fi
428     }
429    
430     mysql_pkg_preinst() {
431    
432     enewgroup mysql 60 || die "problem adding group mysql"
433     enewuser mysql 60 -1 /dev/null mysql \
434     || die "problem adding user mysql"
435     }
436    
437     mysql_pkg_postinst() {
438    
439     mysql_init_vars
440     mysql_lib_symlinks
441    
442     # mind at FEATURES=collision-protect before to remove this
443     [ -d "${ROOT}/var/log/mysql" ] \
444     || install -d -m0750 -o mysql -g mysql "${ROOT}${MY_LOGDIR}"
445    
446     #secure the logfiles... does this bother anybody?
447     touch "${ROOT}${MY_LOGDIR}"/mysql.{log,err}
448     chown mysql:mysql "${ROOT}${MY_LOGDIR}"/mysql*
449     chmod 0660 "${ROOT}${MY_LOGDIR}"/mysql*
450    
451     if ! useq minimal; then
452     # your friendly public service announcement...
453     einfo
454     einfo "You might want to run:"
455     einfo "\"emerge --config =${CATEGORY}/${PF}\""
456     einfo "if this is a new install."
457     einfo
458     fi
459    
460     einfo "InnoDB is not optional as of MySQL-4.0.24, at the request of upstream."
461     }
462    
463     mysql_pkg_config() {
464     mysql_init_vars
465     [[ -z "${DATADIR}" ]] && die "sorry, unable to find DATADIR"
466    
467     if built_with_use dev-db/mysql minimal; then
468     die "Minimal builds do NOT include the MySQL server"
469     fi
470    
471     local pwd1="a"
472     local pwd2="b"
473     local maxtry=5
474    
475     if [[ -d "${ROOT}/${DATADIR}/mysql" ]] ; then
476     ewarn "You have already a MySQL database in place."
477     ewarn "(${ROOT}/${DATADIR}/*)"
478     ewarn "Please rename or delete it if you wish to replace it."
479     die "MySQL database already exists!"
480     fi
481    
482     einfo "Creating the mysql database and setting proper"
483     einfo "permissions on it..."
484    
485     einfo "Insert a password for the mysql 'root' user"
486     ewarn "Avoid [\"'\\_%] characters in the password"
487    
488     read -rsp " >" pwd1 ; echo
489     einfo "Check the password"
490     read -rsp " >" pwd2 ; echo
491    
492     if [[ "x$pwd1" != "x$pwd2" ]] ; then
493     die "Passwords are not the same"
494     fi
495    
496     local options=""
497     local sqltmp="$(emktemp)"
498    
499     local help_tables="${ROOT}/usr/share/doc/mysql-${PVR}/scripts/fill_help_tables.sql.gz"
500     [[ -r "${help_tables}" ]] \
501     && zcat "${help_tables}" > "${TMPDIR}/fill_help_tables.sql" \
502     || touch "${TMPDIR}/fill_help_tables.sql"
503     help_tables="${TMPDIR}/fill_help_tables.sql"
504    
505     pushd "${TMPDIR}"
506     ${ROOT}/usr/bin/mysql_install_db${MY_SUFFIX} | grep -B5 -A999 -i "ERROR"
507     popd
508     [[ -f ${ROOT}/${DATADIR}/mysql/user.frm ]] || die "MySQL databases not installed"
509     chown -R mysql:mysql ${ROOT}/${DATADIR} 2> /dev/null
510     chmod 0750 ${ROOT}/${DATADIR} 2> /dev/null
511    
512     if mysql_version_is_at_least "4.01.03.00" ; then
513     options="--skip-ndbcluster"
514    
515     # Filling timezones, see
516     # http://dev.mysql.com/doc/mysql/en/time-zone-support.html
517     ${ROOT}/usr/bin/mysql_tzinfo_to_sql${MY_SUFFIX} ${ROOT}/usr/share/zoneinfo \
518     > "${sqltmp}" 2>/dev/null
519    
520     if [[ -r "${help_tables}" ]] ; then
521     cat "${help_tables}" >> "${sqltmp}"
522     fi
523     fi
524    
525     local socket=${ROOT}/var/run/mysqld/mysqld${MY_SUFFIX}${RANDOM}.sock
526     local pidfile=${ROOT}/var/run/mysqld/mysqld${MY_SUFFIX}${RANDOM}.sock
527     local mysqld="${ROOT}/usr/sbin/mysqld${MY_SUFFIX} \
528     ${options} \
529     --user=mysql \
530     --skip-grant-tables \
531     --basedir=${ROOT}/usr \
532     --datadir=${ROOT}/${DATADIR} \
533     --skip-innodb \
534     --skip-bdb \
535     --skip-networking \
536     --max_allowed_packet=8M \
537     --net_buffer_length=16K \
538     --socket=${socket} \
539     --pid-file=${pidfile}"
540     $mysqld &
541     while ! [[ -S "${socket}" || "${maxtry}" -lt 1 ]] ; do
542     maxtry=$(($maxtry-1))
543     echo -n "."
544     sleep 1
545     done
546    
547     # do this from memory we don't want clear text password in temp files
548     local sql="UPDATE mysql.user SET Password = PASSWORD('${pwd1}') WHERE USER='root'"
549     ${ROOT}/usr/bin/mysql${MY_SUFFIX} \
550     --socket=${socket} \
551     -hlocalhost \
552     -e "${sql}"
553    
554     einfo "Loading \"zoneinfo\" this step may require few seconds"
555    
556     ${ROOT}/usr/bin/mysql${MY_SUFFIX} \
557     --socket=${socket} \
558     -hlocalhost \
559     -uroot \
560     -p"${pwd1}" \
561     mysql < "${sqltmp}"
562    
563     # server stop and cleanup
564     kill $(< "${pidfile}" )
565     rm "${sqltmp}"
566     einfo "stopping the server,"
567     wait %1
568     einfo "done"
569     }
570    
571     mysql_pkg_postrm() {
572     mysql_lib_symlinks
573     }

  ViewVC Help
Powered by ViewVC 1.1.20