#! /bin/sh
# Here are the steps to install the tools under Debian:
#
# Contributed by Martin Quinson

TARGET=i586-mingw32msvc

set -e

echo "XXX Install the dependencies"
if test -x /usr/bin/i586-mingw32msvc-g++ ; then 
  echo Mingw32 cross compile suite already installed.
else
  echo Installing the mingw32 cross compile suite.
  sudo apt-get install mingw32 
fi

if test -x /usr/i586-mingw32msvc/lib/SDL_image.dll ; then 
  echo mingw32-libsdl-image already installed.
else
  echo Installing mingw32-libsdl-image.
  sudo apt-get install mingw32-libsdl-image
fi

if test -x /usr/i586-mingw32msvc/bin/SDL.dll ; then 
  echo mingw32-libsdl already installed.
else
  echo Installing mingw32-libsdl.
  sudo apt-get install mingw32-libsdl
fi

echo "XXX Update from CVS"
if [ -d widelands ]; then
   ( cd widelands ; cvs update -Pd )
else
   cvs -z3 -d:pserver:anonymous@cvs.widelands.sourceforge.net:/cvsroot/widelands co widelands
fi

echo "XXX Build the binaries"
CROSS=YES BUILD=release make -C widelands

echo "XXX Setup the libraries"
cp widelands/widelands widelands/widelands.exe
cp /usr/$TARGET/bin/{png12,SDL,zlib1}.dll widelands/

cp /usr/$TARGET/lib/SDL_image.dll widelands/
for n in widelands/*.dll widelands/widelands.exe ; do 
  /usr/bin/$TARGET-strip --strip-unneeded $n
done

echo "XXX Build the archive"
zip -r widelands-cvs-`date +%g%m%e`.zip \
  widelands/{AUTHORS,COPYING,README} \
  widelands/widelands.exe \
  widelands/*.dll \
  `find widelands/{fonts,maps,pics,tribes,worlds}/ -type f |grep -v CVS` \
  >/dev/null
  
exit 0
