#!/bin/sh

. /etc/flenv

mkdir -p $flinstpath

targetdir=`find $srcpath -maxdepth 1 -type d -name zlib-\*`
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 ; }

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

# normal build
# make -f win32/Makefile.gcc CFLAGS="-O3 -s -mms-bitfields -march=i686"
# asm build
cp -f contrib/asm686/match.S .
make -f win32/Makefile.gcc LOC=-DASMV OBJA=match.o CFLAGS="-O3 -s -mms-bitfields -march=i686" \
|| { echo "ERROR: make failed" ; popd; exit 1 ; }

# zlib's install does not use common way (assumes win32 command prompt?)
make -f win32/Makefile.gcc install prefix=$flinstpath \
|| { echo "ERROR: 'make install' failed" ; popd; exit 1 ; }

popd

$flpath/bin/dllz.sh static

echo "INFO: zlib is now installed"
