#!/bin/sh

CXX=${CXX:-g++}
PYTHON=${PYTHON:-python3}
path=`which "$PYTHON" 2> /dev/null`

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

if [ $? = 0 ]
then
	# Change this as needed
	export PYTHON_INCLUDE="$("${PYTHON}-config" --includes)"
	[ -z "$PYTHON_INCLUDE" ] && echo "$PYTHON" development missing && exit 1

	ln -sf ../mlt.i

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

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

	# Create the module
	${CXX} ${CXXFLAGS} -shared mlt_wrap.o -L../../mlt++ -lmlt++ -L../../framework -lmlt $("${PYTHON}-config" --ldflags) -o _mlt.so || exit $?
else
	echo Python not installed.
	exit 1
fi
