#!/bin/sh

CXX=${CXX:-g++}

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

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

if [ $? = 0 ]
then
	ln -sf ../mlt.i

	# Invoke swig
	swig -c++ -I../../mlt++ -I../.. -lua mlt.i || exit $?

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

	# Create the module
	${CXX} ${CXXFLAGS} -shared mlt_wrap.o -L../../mlt++ -lmlt++ -o mlt.so || exit $?
else
	echo Lua not installed.
	exit 1
fi
