#!/bin/sh
# Build and install MySQL on Slackware
# by:  David Cantrell <david@slackware.com>
# Currently maintained by:  Patrick Volkerding <volkerdi@slackware.com>

CWD=`pwd`
TMP=/tmp
ARCH=i386
VERSION=3.23.54a

cd $TMP
tar xvzf $CWD/mysql-$VERSION.tar.gz
cd mysql-$VERSION
chown -R root.root .
find . -perm 777 -exec chmod 755 {} \;
find . -perm 775 -exec chmod 755 {} \;
find . -perm 666 -exec chmod 644 {} \;
find . -perm 664 -exec chmod 644 {} \;
find . -perm 444 -exec chmod 644 {} \;
CFLAGS="-O3 -march=i486 -mcpu=i686" CXX=gcc CXXFLAGS="-O3 -march=i486 -mcpu=i686 -felide-constructors -fno-exceptions -fno-rtti" \
./configure --prefix=/usr \
            --with-mysqld-user=mysql \
            --with-unix-socket-path=/var/run/mysql/mysql.sock \
            --localstatedir=/var/lib/mysql \
            --enable-assembler \
            --with-raid \
            --without-debug \
            --without-readline \
            --enable-thread-safe-client \
            --without-bench \
            --with-extra-charsets=complex \
  --program-prefix="" --program-suffix="" \
            i386-slackware-linux
make
make install
( cd support-files
  cp my-huge.cnf my-large.cnf my-medium.cnf my-small.cnf /etc )

# install docs
mkdir -p /usr/doc/mysql-$VERSION/Docs
# Don't need the (huge) INSTALL-SOURCE... the source is installed already.
#cp -a COPYING* INSTALL-SOURCE MIRRORS README /usr/doc/mysql-$VERSION
cp -a COPYING* MIRRORS README /usr/doc/mysql-$VERSION
( cd Docs
  cp -a INSTALL-BINARY *.html *.txt Flags \
     /usr/doc/mysql-$VERSION/Docs )
# Also too large to justify since the .html version is right there:
rm /usr/doc/mysql-$VERSION/Docs/manual.txt
find /usr/doc/mysql-$VERSION -type f -exec chmod 644 {} \;

# this is the directory where databases are stored
mkdir -p /var/lib/mysql
chown mysql.mysql /var/lib/mysql
chmod 750 /var/lib/mysql

# this is where the socket is stored
mkdir -p /var/run/mysql
chown mysql.mysql /var/run/mysql
chmod 755 /var/run/mysql

# Do not include the test suite:
rm -r /usr/mysql-test

# Install script:
mkdir -p /install
zcat $CWD/doinst.sh.gz > /install/doinst.sh
cat $CWD/slack-desc > /install/slack-desc

# Add some handy library symlinks:
if [ -r /usr/lib/mysql/libmysqlclient.so.10 ]; then
  ( cd /usr/lib
    rm -f libmysqlclient.so libmysqlclient.so.10
    ln -sf mysql/libmysqlclient.so .
    ln -sf mysql/libmysqlclient.so.10 .
  )
fi
if [ -r /usr/lib/mysql/libmysqlclient_r.so.10 ]; then
  ( cd /usr/lib
    rm -f libmysqlclient_r.so libmysqlclient_r.so.10
    ln -sf mysql/libmysqlclient_r.so .
    ln -sf mysql/libmysqlclient_r.so.10 .
  )
fi

# done
echo
echo "Done!  Don't forget to pack up the empty /var/lib/mysql and /var/run/mysql directories!"
echo

if [ "$1" == "--cleanup" ]; then
   cd $TMP
   rm -rf mysql-$VERSION
fi
