#!/bin/sh
# Copyright (C) 2002, 2005 MySQL AB
# 
# 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; version 2 of the License.
# 
# 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 this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

if [ -f prepare_done ]
then
    exit
fi

cd ..
SRCDIR=`pwd`

(
find $SRCDIR -name *.dsw -and -not -path \*SCCS\* -print
find $SRCDIR -name *.dsp -and -not -path \*SCCS\* -print
)|(
while read v 
do
    sed 's/$'"/`echo -e \\\r`/" $v > $v.tmp
    rm $v
    mv $v.tmp $v
done
)

ln -s $SRCDIR/include $SRCDIR/VC++Files/include

link_dir_files()
{
    for arg do

    cd $SRCDIR/$arg/
    (
     ls -A1|grep \\.[ch]$
     ls -A1|grep \\.ih$
     ls -A1|grep \\.asm$
    )|(
    while read v 
    do
	ln -s $SRCDIR/$arg/$v $SRCDIR/VC++Files/$arg/$v
    done
    )

    cd $SRCDIR/$arg/
    (ls -A1|grep \\.cc$|sed 's/.cc$//g')|(
    while read v 
    do
	ln -s $SRCDIR/$arg/$v.cc $SRCDIR/VC++Files/$arg/$v.cpp
    done
    )
    
    done
}

link_dir_dirs()
{
    for arg do
    
    cd $SRCDIR/$arg/
    (
      ls -l |grep "^d"|awk '{print($9)}' -
    )|(
    while read v 
    do
	ln -s $SRCDIR/$arg/$v $SRCDIR/VC++Files/$arg/
    done
    )
    
    done
}

link_dir_files 'heap'
link_dir_files 'mysys'
link_dir_files 'zlib'
link_dir_files 'regex'
link_dir_files 'strings'
link_dir_files 'dbug'
link_dir_files 'vio'
link_dir_files 'client'
link_dir_files 'libmysql'
link_dir_files 'extra'
link_dir_files 'myisam'
link_dir_files 'myisammrg'
link_dir_files 'innobase'
link_dir_files 'bdb'
link_dir_files 'sql'
link_dir_files 'bdb/build_win32'
link_dir_files 'libmysqld'

link_dir_dirs 'bdb'
link_dir_dirs 'innobase'

ln -s $SRCDIR/myisam/myisampack.c $SRCDIR/VC++Files/myisampack/
ln -s $SRCDIR/client/mysqlbinlog.cc $SRCDIR/VC++Files/mysqlbinlog/mysqlbinlog.cpp

echo '/* added for win : */' >> $SRCDIR/config.h
echo '#undef HAVE_SCHED_H' >> $SRCDIR/config.h
echo '#USE_QUERY_CACHE_INTEGRITY_CHECK 1' >> $SRCDIR/config.h

echo '/* added for win : */' >> $SRCDIR/innobase/ib_config.h
echo '#undef HAVE_SCHED_H' >> $SRCDIR/innobase/ib_config.h

cd $SRCDIR/VC++Files
echo '1' > prepare_done