#!/bin/sh

PREFIX=$1
shift

HOST_CC=gcc; export HOST_CC; 
  PKG_CONFIG_PATH="/usr/i686-pc-mingw32/sys-root/mingw/lib/pkgconfig"; export PKG_CONFIG_PATH; 
  CC="${MINGW32_CC:-i686-pc-mingw32-gcc}"; export CC; 
  CXX="${MINGW32_CXX:-i686-pc-mingw32-g++}"; export CXX; 
  CFLAGS="${MINGW32_CFLAGS:--O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4 -mms-bitfields}"; export CFLAGS; 
  CXXFLAGS="${MINGW32_CXXFLAGS:--O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4 -mms-bitfields}"; export CXXFLAGS; 
  _PREFIX="/usr/bin/i686-pc-mingw32-"; 
  for i in `ls ${_PREFIX}*|egrep -v "gcc-"`; do 
    x=`echo $i|sed "s,${_PREFIX},,"|tr "a-z+-" "A-ZX_"`; 
    declare -x $x="$i" ; export $x; 
  done; 
  unset _PREFIX; 
  for i in `ls /usr/i686-pc-mingw32/sys-root/mingw/bin/*|grep -- "-config$"` ; do 
    x=`basename $i|tr "a-z+-" "A-ZX_"`; 
    declare -x $x="$i" ; export $x; 
  done; 
  unset x i ; 
  ../configure --cache-file=mingw32-config.cache \
	--host=i686-pc-mingw32 \
	--build=i686-pc-linux-gnu \
	--target=i686-pc-mingw32 \
	--prefix=${PREFIX} \
	--exec-prefix=${PREFIX} \
	--bindir=${PREFIX}/bin \
	--sbindir=${PREFIX}/sbin \
	--sysconfdir=${PREFIX}/etc \
	--datadir=${PREFIX}/share \
	--includedir=${PREFIX}/include \
	--libdir=${PREFIX}/lib \
	--libexecdir=${PREFIX}/libexec \
	--localstatedir=${PREFIX}/var \
	--sharedstatedir=${PREFIX}/com \
	--mandir=${PREFIX}/share/man \
	--infodir=${PREFIX}/share/info \
	"$@"
