#!/bin/sh

# Cross-compile from Linux to Win32 using mingw32 cross-compiler as
# provided by Debian.  For Ogg and MP3 support, you need to compile
# those libraries separately and put them in libs/.  If the libraries
# are absent, sbagen is compiled without Ogg/MP3 support.
#
# Compiling these libraries is not the easiest thing to do, and doing
# it the way I did it requires a MinGW and MSYS setup running on
# Windows (or under emulation), under which you can use the
# 'mk-libmad-mingw' and 'mk-tremor-mingw' scripts to build the
# libraries in a rather improvised manner.  You only have to do this
# once, after which you can copy them to libs/ and rebuild endlessly
# on Linux without trouble.

COPT="-O6 -s -Wall"
OPT="$COPT -DT_MINGW -I /usr/i586-mingw32msvc/include -I./libs"
GCC=i586-mingw32msvc-gcc
LIBDIR=/usr/i586-mingw32msvc/lib
LIBS=''

[ -f libs/xmingw-libmad.a ] && {
    OPT="-DMP3_DECODE $OPT"
    LIBS="$LIBS libs/xmingw-libmad.a"
}
[ -f libs/xmingw-libvorbisidec.a ] && {
    OPT="-DOGG_DECODE $OPT"
    LIBS="$LIBS libs/xmingw-libvorbisidec.a"
}

$GCC $OPT sbagen.c $LIBS -L$LIBDIR -lmingw32 -lwinmm -o sbagen.exe || 
{ echo "FAILED"; exit 1; }

