#!/bin/sh
# The default path should be /usr/local

# Get some info from configure
chmod +x ./scripts/setsomevars
. ./scripts/setsomevars

#make

# This should really be integrated with automake and not duplicate the
# installation list.

BASE=mysql-$version-$system-$machine
mkdir $BASE $BASE/bin $BASE/data $BASE/data/mysql $BASE/data/test \
 $BASE/include $BASE/lib $BASE/mysqlperl \
 $BASE/share $BASE/share/mysql $BASE/tests $BASE/scripts

for i in BUGS NEWS CREDITS sql/ChangeLog EXAMPLE \
 INSTALL-BINARY INSTALL-SOURCE PORTING PUBLIC README TODO \
 FAQs/mysql-faq.html FAQs/mysql-faq.txt FAQs/mysql-faq_toc.html
do
  ln $i $BASE
done

for i in extra/comp_err client/mysql sql/mysqld client/mysqlshow \
 extra/replace isam/isamchk client/mysqladmin client/mysqldump \
 extra/perror
do
  ln $i $BASE/bin
done

ln include/* $BASE/include; rm $BASE/include/Makefile*; rm $BASE/include/*.in
ln tests/*.res tests/*.tst tests/*.pl $BASE/tests
ln data/mysql/*.frm $BASE/data/mysql 
ln client/libmysqlclient.a $BASE/lib
cd perl/mysqlperl/; cp -r . ../../$BASE/mysqlperl; cd ../.. 
sh -c "cd $BASE/mysqlperl ; make clean"
rm $BASE/mysqlperl/*.sh
cp -r sql/share/* $BASE/share/mysql; rm -f $BASE/share/mysql/Makefile* $BASE/share/mysql/*/*.OLD

ln scripts/* $BASE/bin
rm -f $BASE/bin/Makefile* $BASE/bin/*.in $BASE/bin/*.sh $BASE/bin/mysql_install_db $BASE/bin/make_binary_distribution $BASE/bin/setsomevars
$BASE/bin/replace @localstatedir@ ./data @bindir@ ./bin @scriptdir@ ./bin < scripts/mysql_install_db.sh > $BASE/scripts/mysql_install_db
chmod a+x $BASE/bin/* $BASE/scripts/*

tar cvf - $BASE | gzip > $BASE.tgz 

rm -rf $BASE

echo "$BASE.tgz created"
