# Maintainer: Phillip Smith <fukawi2@NOSPAM.gmail.com>
# Maintainer: Douglas Soares de Andrade <douglas@archlinux.org>
# Contributor: judd <jvinet@zeroflux.org>

pkgname=mysql
pkgver=5.1.39
pkgrel=1
pkgdesc="A fast SQL database server"
arch=(i686 x86_64)
groups=('lamp')
backup=(etc/my.cnf etc/conf.d/mysqld)
depends=('tcp_wrappers' 'zlib' 'perl')
makedepends=('libtool' 'patch')
url=('http://www.mysql.com/')
options=('!libtool')
optdepends=('perl-dbi' 'perl-dbd-mysql')
license=('GPL')
source=("http://downloads.mysql.com/archives/$pkgname-5.1/$pkgname-${pkgver}.tar.gz"
        'mysql-no-clients.patch'
        'mysql-fix-libs.patch'
        'rc.mysqld'
        'my.cnf'
        'mysqld.conf.d')
md5sums=('55a398daeb69a778fc46573623143268'
         '8dce7e2b9f1f6ed6eca8bd62144bad0a'
         'd1921e85821a66196c24ef6e5346b572'
         'c093cc7eef5934f56f8bc775b559904b'
         '0ee035590ffc61d32de994f461fd2bd2'
         '4a9077fc95ec6db1d5420e0cdc74d31c')

build() {
  cd $srcdir/${pkgname}-${pkgver}

  # fix build with gcc 4.4
  # see http://bugs.archlinux.org/task/15242
  # and http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38562
  CFLAGS="-fPIC ${CFLAGS} -fno-strict-aliasing"
  CXXFLAGS="-fPIC ${CXXFLAGS} -fno-strict-aliasing"

  patch -Np1 -i $srcdir/mysql-no-clients.patch || return 1
  patch -Np1 -i $srcdir/mysql-fix-libs.patch || return 1

  ./configure \
    --prefix=/usr \
    --libexecdir=/usr/sbin \
    --localstatedir=/var \
    --sysconfdir=/etc \
    --without-debug \
    --without-docs \
    --without-readline \
    --enable-local-infile \
    --with-ssl \
    --with-charset=latin1 \
    --with-collation=latin1_general_ci \
    --with-extra-charsets=complex \
    --enable-thread-safe-client \
    --with-libwrap \
    --with-plugins=partition,ftexample,archive,blackhole,federated,heap,innobase,ndbcluster || return 1
  
  pushd include || return
  make || return 1
  popd
    
  pushd libmysql
  make link_sources get_password.lo || return
  popd
  
  make || return 1
}

package() {
  cd $srcdir/${pkgname}-${pkgver}

  # install the main package
  make DESTDIR=$pkgdir install

  # cleanup
  rm -rf $pkgdir/usr/{mysql-test,sql-bench,lib,include}

  # install config files
  install -D -m644 $srcdir/my.cnf $pkgdir/etc/my.cnf
  install -D -m644 $srcdir/mysqld.conf.d $pkgdir/etc/conf.d/mysqld

  # install rc script
  install -D -m755 $srcdir/rc.mysqld $pkgdir/etc/rc.d/mysqld
  rm -f $pkgdir/usr/bin/mysql_config
}
# vim:set ts=2 sw=2 et:
