#!/bin/sh

. /etc/flenv

mkdir -p $flinstpath

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

pushd $targetdir

#patch -p0 -N < $flpath/patch/libpng-1.2.37_mingwPORT_felidlabo.patch
perl -pe 's:^\tinstall:\t/bin/install:' scripts/makefile.mingw > makefile

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

make prefix=$flinstpath \
|| { echo "ERROR: make failed" ; popd; exit 1 ; }

make install prefix=$flinstpath \
|| { echo "ERROR: 'make install' failed" ; popd; exit 1 ; }

pushd $flinstpath/lib/
mv -f libpng.dll.a libpng.dll.a.esc
mv -f libpng12.dll.a libpng12.dll.a.esc
popd

popd

echo "INFO: libpng is now installed"
