#!/bin/sh

CXX=${CXX:-g++}

if [ "$1" = "clean" ]
then
	( cd `dirname $0`; rm -f *.cxx *.so *.o mlt.i ../.tcl )
	exit 0
fi

path=`which tclsh 2>/dev/null`

if [ "$path" != "" ]
then
	ln -sf ../mlt.i

	# Invoke swig
	swig -c++ -I../../mlt++ -I../.. -tcl mlt.i || exit 1

	# Compile the wrapper
	${CXX} -fPIC -D_GNU_SOURCE ${CXXFLAGS} -c -rdynamic -pthread -I../.. mlt_wrap.cxx || exit 1

	# Create the module
	${CXX} ${CXXFLAGS} -shared mlt_wrap.o -L../../mlt++ -lmlt++ -o mlt.so || exit 1
else
	echo "Unable to locate tclsh."
	exit 1
fi
