#!/bin/sh

. /etc/flenv

mkdir -p $flinstpath

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

pushd $targetdir

patchfile=`find $flpath/patch -maxdepth 1 -type f -name jpeg-\*.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 \
#|| { echo "ERROR: configure failed" ; popd ; exit 1 ; }

cp -f jconfig.mgw jconfig.h
cp -f makefile.mgw Makefile
make \
|| { echo "ERROR: make failed" ; popd; exit 1 ; }

#make install-lib

cp -f libjpeg.a $flinstpath/lib
cp -f jpeglib.h $flinstpath/include
cp -f jerror.h $flinstpath/include
cp -f jconfig.h $flinstpath/include
cp -f jmorecfg.h $flinstpath/include

popd

echo "INFO: jpeg6bx is now installed"
