# $Id: PKGBUILD 88432 2010-08-23 17:32:08Z pierre $
# Maintainer: Andrea Scarpino <andrea@archlinux.org>
# Contributor: Douglas Soares de Andrade <douglas@archlinux.org>
# Contributor: judd <jvinet@zeroflux.org>

pkgbase=mysql
pkgname=('libmysqlclient' 'mysql-clients' 'mysql')
pkgver=5.1.59
pkgrel=1
arch=('i686' 'x86_64')
license=('GPL')
url="http://www.mysql.com/"
makedepends=('tcp_wrappers' 'zlib' 'perl' 'openssl' 'libtool' 'patch')
options=('!libtool')
source=("http://ftp.gwdg.de/pub/misc/mysql/Downloads/MySQL-5.1/${pkgbase}-${pkgver}.tar.gz"
        'mysqld'
        'my.cnf'
        'skip-abi-check.patch')

build() {
  cd "${srcdir}/${pkgbase}-${pkgver}"
  patch -Np0 -i "${srcdir}/skip-abi-check.patch"
  # CFLAGS/CXXFLAGS as suggested upstream
  CFLAGS="-fPIC ${CFLAGS} -fno-strict-aliasing -DBIG_JOINS=1 -fomit-frame-pointer" \
  CXXFLAGS="-fPIC ${CXXFLAGS} -fno-strict-aliasing -DBIG_JOINS=1 -felide-constructors -fno-rtti" \
  ./configure --prefix=/usr \
    --libexecdir=/usr/sbin \
    --localstatedir=/var \
    --sysconfdir=/etc/mysql \
    --without-docs \
    --without-readline \
    --with-ssl \
    --with-libwrap \
    --with-charset=utf8 \
    --with-collation=utf8_general_ci \
    --with-extra-charsets=complex \
    --with-embedded-server \
    --with-unix-socket-path=/var/run/mysqld/mysqld.sock \
    --enable-local-infile \
    --with-plugins=partition,ftexample,archive,blackhole,federated,heap,innobase,innodb_plugin,ndbcluster
  make || return 1
}

package_libmysqlclient(){
  pkgdesc="MySQL client libraries"
  depends=('openssl' 'zlib' 'gcc-libs' 'tcp_wrappers')
  
  cd "${srcdir}/${pkgbase}-${pkgver}"
  for dir in include libmysql libmysql_r libmysqld; do
    make -C ${dir} DESTDIR="${pkgdir}" install
  done
  install -m644 include/*.h "${pkgdir}/usr/include/mysql/"

  install -d "${pkgdir}/usr/bin"
  install -m755 scripts/mysql_config "${pkgdir}/usr/bin/"
  
  # create library symlinks in /usr/lib
  ln -sf mysql/libmysqlclient.so.16 ${pkgdir}/usr/lib/libmysqlclient.so.16
  ln -sf libmysqlclient.so.16 ${pkgdir}/usr/lib/libmysqlclient.so
  ln -sf libmysqlclient.so.16 ${pkgdir}/usr/lib/libmysqlclient.so.1
  ln -sf mysql/libmysqlclient_r.so.16  ${pkgdir}/usr/lib/libmysqlclient_r.so.16
  ln -sf libmysqlclient_r.so.16 ${pkgdir}/usr/lib/libmysqlclient_r.so
  ln -sf libmysqlclient_r.so.16 ${pkgdir}/usr/lib/libmysqlclient_r.so.1
}

package_mysql-clients(){
  pkgdesc="MySQL client tools"
  depends=('libmysqlclient')
  
  cd "${srcdir}/${pkgbase}-${pkgver}/client"
  make DESTDIR="${pkgdir}" install

  # provided by libmysqlclient
  rm -rf "${pkgdir}/usr/lib/"

  # provided by mysql
  rm -f "${pkgdir}"/usr/bin/{mysql_upgrade,mysqlbinlog,mysqltest}
}

package_mysql(){
  pkgdesc="A fast SQL database server"
  backup=('etc/my.cnf' 'etc/mysql/my.cnf')
  install=mysql.install
  depends=('mysql-clients')
  optdepends=('perl-dbi' 'perl-dbd-mysql')

  cd "${srcdir}/${pkgbase}-${pkgver}"
  make DESTDIR=${pkgdir} install

  install -Dm644 ${srcdir}/my.cnf ${pkgdir}/etc/mysql/my.cnf
  install -Dm755 ${srcdir}/mysqld ${pkgdir}/etc/rc.d/mysqld

  # provided by libmysqlclient
  rm -f ${pkgdir}/usr/bin/{mysql_config,mysql_client_test_embedded,mysqltest_embedded}
  rm -f ${pkgdir}/usr/lib/mysql/libmysqlclient*
  rm -f ${pkgdir}/usr/lib/mysql/libmysqld.a
  rm -f ${pkgdir}/usr/include/mysql/*.h
  
  # provided by mysql-clients
  rm -f ${pkgdir}/usr/bin/{mysql,mysqladmin,mysqlcheck,mysqldump,mysqlimport,mysqlshow,mysqlslap}

  # not needed
  rm -rf ${pkgdir}/usr/{mysql-test,sql-bench}
  rm -f ${pkgdir}/usr/lib/mysql/plugin/*.a
}
md5sums=('1e89816164692f44f768024db4bc05f6'
         '2234207625baa29b2ff7d7b4f088abce'
         'd60099985e68e36b156423fca6b50924'
         'a97e574945e19de3908575b956241026')