#!/bin/sh

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 'isam'
link_dir_files 'merge'
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
ln -s $SRCDIR/isam/pack_isam.c $SRCDIR/VC++Files/pack_isam/pack_isam.c

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