#!/bin/sh

. config/options

$SCRIPTS/build toolchain
$SCRIPTS/build zlib
$SCRIPTS/build ncurses
$SCRIPTS/build mysql-hosttools

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 \
            --disable-static \
            --enable-shared \
            --with-low-memory \
            --enable-largefile \
            --with-big-tables \
            --with-mysqld-user=mysqld \
            --with-extra-charsets=all \
            --with-charset=utf8 \
            --with-collation=utf8_unicode_ci \
            --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 \
            --without-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 -C include
make -C libmysql

make -C scripts
  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 $ROOT/$TOOLCHAIN/bin

$MAKEINSTALL -C include
$MAKEINSTALL -C libmysql

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