#!/bin/sh

################################################################################
#      This file is part of OpenELEC - http://www.openelec.tv
#      Copyright (C) 2009-2012 Stephan Raue (stephan@openelec.tv)
#
#  This Program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2, or (at your option)
#  any later version.
#
#  This Program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with OpenELEC.tv; see the file COPYING.  If not, write to
#  the Free Software Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110, USA.
#  http://www.gnu.org/copyleft/gpl.html
################################################################################

. config/options $1

CFLAGS="$CFLAGS -fPIC -DPIC"

cd $PKG_BUILD
ac_cv_c_stack_direction=-1 \
ac_cv_sys_restartable_syscalls=yes \
./configure --host=$TARGET_NAME \
            --build=$HOST_NAME \
            --target=$TARGET_NAME \
            --prefix=/usr \
            --sysconfdir=/etc \
            --sbindir=/usr/sbin \
            --libdir=/usr/lib \
            --libexecdir=/usr/sbin \
            --localstatedir=/storage/.mysql \
            --with-unix-socket-path=/var/tmp/mysql.socket \
            --with-tcp-port=3306 \
            --enable-static \
            --disable-shared \
            --with-low-memory \
            --enable-largefile \
            --with-big-tables \
            --with-mysqld-user=mysqld \
            --with-extra-charsets=all \
            --with-pthread \
            --with-named-thread-libs=-lpthread \
            --enable-thread-safe-client \
            --enable-assembler \
            --enable-local-infile \
            --without-debug \
            --without-docs \
            --without-man \
            --with-readline \
            --without-libwrap \
            --without-pstack \
            --without-server \
            --without-embedded-server \
            --without-libedit \
            --with-query-cache \
            --without-plugin-partition \
            --without-plugin-daemon_example \
            --without-plugin-ftexample \
            --without-plugin-archive \
            --without-plugin-blackhole \
            --without-plugin-example \
            --without-plugin-federated \
            --without-plugin-ibmdb2i \
            --without-plugin-innobase \
            --without-plugin-innodb_plugin \
            --without-plugin-ndbcluster \

make
$MAKEINSTALL

sed -i "s|pkgincludedir=.*|pkgincludedir=\'$SYSROOT_PREFIX/usr/include/mysql\'|" scripts/mysql_config
sed -i "s|pkglibdir=.*|pkglibdir=\'$SYSROOT_PREFIX/usr/lib/mysql\'|" scripts/mysql_config
cp scripts/mysql_config $SYSROOT_PREFIX/usr/bin
ln -sf $SYSROOT_PREFIX/usr/bin/mysql_config $ROOT/$TOOLCHAIN/bin/mysql_config

for i in `ls -d $SYSROOT_PREFIX/usr/lib/mysql/*.a`; do 
  ln -v -sf $i $SYSROOT_PREFIX/usr/lib
done
