#!/bin/sh

# Cross-compile from Linux to Win32 using the MinGW cross-compiler as
# provided by Debian.  This also requires the location of the MinGW
# libSDL headers and libraries to be provided below.  *** Now I've
# copied the SDL files directly into the /usr/i586-mingw32msvc/ tree,
# so these are no longer required in my case.

#SDLINC=-I/home/jim/win/msys/1.0/mingw/include
#SDLLIB=-L/home/jim/win/msys/1.0/mingw/lib
SDLINC=
SDLLIB=

GCC=i586-mingw32msvc-gcc
OPT="-O6 -s -c -Wall"
OPT="$OPT -DT_MINGW -Dmain=SDL_main -I /usr/i586-mingw32msvc/include $SDLINC"

for xx in bavsa-view.c display.c graphics.c
do
    echo "=== $xx"
    OUT="${xx%.c}.mingw.o"
    OBJ="$OBJ $OUT"
    $GCC $OPT $xx -o $OUT || { echo "FAILED"; exit 1; }
done

LIBS="-L/usr/i586-mingw32msvc/lib $SDLLIB"

$GCC main_redir.c $OBJ $LIBS -lmingw32 -lSDLmain -lwinmm -lSDL -lm -o ../bavsa-view.exe || 
{ echo "FAILED"; exit 1; }

