#!/usr/bin/env bash

set -e

root=`git rev-parse --show-toplevel`
if [ "$1" == 32 ]; then
    prefix=${root}/build-win32
    host=i686-w64-mingw32
elif [ "$1" == 64 ]; then
    prefix=${root}/build-win64
    host=x86_64-w64-mingw32
else
    echo "Usage: $0 (32|64) [make flags]"
    exit 1
fi
shift

mkdir -p ${prefix}

cd ${prefix}
cmake \
    -D CMAKE_SYSTEM_NAME=Windows \
    -D CMAKE_C_COMPILER=${host}-gcc \
    -D CMAKE_INSTALL_PREFIX=${prefix} \
    -D USE_SSE=ON \
    -D USE_STATIC=ON \
    -D USE_SYSTEM_LIBUSB=OFF \
    -D USE_SYSTEM_RTLSDR=OFF \
    -D USE_SYSTEM_LIBAO=OFF \
    -D USE_SYSTEM_FFTW=OFF \
    ..
make $*
make install
