#!/bin/sh

. /etc/profile
. /etc/flenv

escape=$flpath/bin/escape.sh

if [ -n "$2" -a -d "$2" ]; then
	gccdir=$2
else
	gccdir="$mingwpath"
fi

libs="$gccdir/lib libpthreadGC2-dll.a libpthreadGC2-static.a libpthreadGCE2.a"
headers="$gccdir/include pthread.h sched.h semaphore.h"

restore(){
	suffix=$1
	$escape restore $libs
	$escape restore $headers
	pushd $gccdir/lib
	cp -f "libpthreadGC2$suffix" libpthreadGC2.a
	cp -f "libpthreadGC2$suffix" libpthread.a
	popd
}

case $1 in
	static|s)
		restore '-static.a'
		echo "pthread is now for static library."
		;;
	dll|d)
		restore '-dll.a'
		echo "pthread is now for dll."
		;;
	disable)
		$escape escape $libs
		$escape escape $headers
		pushd $gccdir/lib
		rm -f libpthreadGC2.a
		rm -f libpthread.a
		popd
		echo "pthread is now disabled."
		;;
	*)
		echo "usage1: $0 static"
		echo "usage2: $0 dll"
		exit 1
esac
