# $Id: Portfile 56425 2009-08-27 10:45:13Z ryandesign@macports.org $

PortSystem              1.0

name                    mysql5
version                 5.0.85
set branch              [join [lrange [split ${version} .] 0 1] .]
homepage                http://www.mysql.com/
categories              databases
platforms               darwin
maintainers             ryandesign
distname                mysql-${version}
use_parallel_build      yes

description \
    Multithreaded SQL database server

long_description \
    MySQL is an open-source, multi-threaded SQL database \
    with a command syntax very similar to mSQL.

master_sites \
    http://mysql.mirrors.pair.com/Downloads/MySQL-${branch}/ \
    http://mysql.he.net/Downloads/MySQL-${branch}/ \
    http://mysql.orst.edu/Downloads/MySQL-${branch} \
    http://mysql.oss.eznetsols.org/Downloads/MySQL-${branch}/ \
    http://mirrors.sunsite.dk/mysql/Downloads/MySQL-${branch}/ \
    http://sunsite.informatik.rwth-aachen.de/mysql/Downloads/MySQL-${branch}/ \
    http://ftp.plusline.de/mysql/Downloads/MySQL-${branch}/

checksums \
    md5     f672ec5154f8ea3db87fec5e0b227f4c \
    sha1    11f25ef4f120cba97dd921deb202c58adffd93eb \
    rmd160  2af093664af2b365f68a2ca05d3d5564d2ebbc97

depends_lib \
    port:zlib \
    port:openssl

set major_version       [strsed ${version} {s/\..*$//}]
set mysql               mysql${major_version}
set libdir              ${prefix}/lib/${mysql}
set bindir              ${libdir}/bin
set dbdir               ${prefix}/var/db/${mysql}
set sysconfdir          ${prefix}/etc/${mysql}
set mysqluser           mysql

patchfiles \
    patch-mysql_secure_installation.sh.diff

post-patch {
    reinplace s%@BINDIR@%${bindir}%g ${worksrcpath}/scripts/mysql_secure_installation.sh
}

configure.args \
    --mandir=${prefix}/share/man \
    --infodir=${prefix}/share/info \
    --localstatedir=${dbdir} \
    --libdir=${libdir} \
    --bindir=${bindir} \
    --includedir=${prefix}/include/${mysql} \
    --datadir=${prefix}/share/${mysql} \
    --sysconfdir=${sysconfdir} \
    --with-zlib-dir=${prefix} \
    --with-openssl=${prefix} \
    --with-extra-charsets=complex \
    --with-federated-storage-engine \
    --with-unix-socket-path=${prefix}/var/run/${mysql}/mysqld.sock \
    --with-mysqld-user=${mysqluser} \
    --without-bench \
    --enable-thread-safe-client

# Add readline support.
# "--without-readline" has the peculiar meaning "do not use the bundled copy
# of readline but use the system's (i.e. MacPorts') copy of readline"
depends_lib-append      port:readline
configure.args-append   --without-readline

variant server description "Obsolete; install ${mysql}-server port instead" {
    pre-configure {
        ui_msg "The +server variant is obsolete. Please install the ${mysql}-server port instead."
    }
}

pre-destroot {
    xinstall -m 755 -d ${destroot}${sysconfdir}
    destroot.keepdirs-append ${destroot}${sysconfdir}
}

post-destroot {
    delete ${destroot}${prefix}/mysql-test
    
    # Fix paths in manpages and sample configuration files
    foreach manpage [glob -type f ${destroot}${prefix}/share/man/man\[1-9\]/*] {
        reinplace "s|/etc/my.cnf|${sysconfdir}/my.cnf|g" ${manpage}
    }
    foreach samp_conffile [glob -type f ${destroot}${prefix}/share/${mysql}/mysql/my-*.cnf] {
        reinplace "s|/etc/my.cnf|${sysconfdir}/my.cnf|g" ${samp_conffile}
    }
    
    # Symlink mysql binaries into bin directory, with ${major_version} appended to the name
    foreach f [glob -tails -directory ${destroot}${bindir} my*] {
        ln -sf ${bindir}/${f} ${destroot}${prefix}/bin/${f}${major_version}
    }
}

livecheck.check         regex
livecheck.url           http://dev.mysql.com/doc/refman/${branch}/en/releasenotes-cs-[strsed ${branch} {s/\./-/}].html
livecheck.regex         {Changes in MySQL ([0-9.]+)}
