#!/bin/sh

. /etc/profile
. /etc/flenv

mkdir -p $flinstpath

targetdir=`find $srcpath -maxdepth 1 -type d -name pthreads-\*`
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 flpthreads-\*.diff`
if [ -z "$patchfile" ] || [ ! -f "$patchfile" ]; then
	echo "ERROR: patch file not found"
	popd; exit 1
fi
patch -p1 -N < $patchfile \
|| echo "ERROR: patch failed"
# continue even if patch failed, in that case, no cp932 relative modification

make clean GC-static \
|| { echo "ERROR: make failed" ; popd; exit 1 ; }

cp -f sched.h $mingwpath/include
cp -f pthread.h $mingwpath/include
cp -f libpthreadGC2.a $mingwpath/lib
cp -f libpthreadGC2.a $mingwpath/lib/libpthread.a

popd

echo "INFO: pthread(clear-static) is now installed"
