#!/bin/sh

. /etc/flenv

mkdir -p $flinstpath

targetdir=`find $srcpath -maxdepth 1 -type d -name wget-\*`
if [ -z "$targetdir" ] || [ ! -d "$targetdir" ]; then
	echo "ERROR: target source directory not found"
	exit 1
fi

pushd $targetdir

patch -p1 -N < mingwPORT/mingwPORT.patch \
|| { echo "ERROR: patch failed" ; popd ; exit 1 ; }

patchfile=`find $flpath/patch -maxdepth 1 -type f -name wget-\*.patch`
if [ -z "$patchfile" ] || [ ! -f "$patchfile" ]; then
	echo "ERROR: patch file not found"
	popd; exit 1
fi
patch -p0 -N < $patchfile \
|| { echo "ERROR: patch failed" ; popd ; exit 1 ; }

./configure --prefix=$flinstpath --disable-nls \
|| { echo "ERROR: configure failed" ; popd ; exit 1 ; }

BLDDIR=.
. mingwPORT/mingwPORT.afterconfigure

make LIBS=-lws2_32 exeext=.exe CFLAGS="-O3 -s -mms-bitfields -march=i686" \
|| { echo "ERROR: make failed" ; popd; exit 1 ; }

make install exeext=.exe \
|| { echo "ERROR: 'make install' failed" ; popd; exit 1 ; }

popd

echo "INFO: wget is now installed"
