
#
# Build C++ tests generated by python tests, configured to get access to gtest and ufc.
#

# These are the commands we assume
CXX=g++ # TODO: Allow overriding
RM=rm
PYTEST=py.test

# Local filenames
TESTBINARY=run_gtest
TESTSRCDIR=generated
TESTSUPPORTDIR=cppsupport
TESTMAINSRC=${TESTSRCDIR}/main.cpp

# Configure ufc
UFCINCDIR=`pkg-config ufc-1 --cflags`
#UFCINCDIR=-I${UFC_INCLUDE_DIR}

# Configure gtest
GTEST_DIR?=../../../libs/gtest-1.7.0
GTESTINCDIR=-I${GTEST_DIR}/include
GTESTLIBS=-L${GTEST_DIR}/lib -lgtest -lpthread

# Flags set for easy debugging # TODO: Allow overriding
CXXFLAGS=-g -O0


.PHONY: clean

.SECONDARY:

default: ${TESTBINARY}

run: ${TESTBINARY}
	./${TESTBINARY}

# Also depends on ${TESTSRCDIR}/*.h but this rule seems to be sufficient
# because the test binary is touched every time the python tests run
${TESTBINARY}: ${TESTMAINSRC} ${TESTSUPPORTDIR}/*.h
	${CXX} ${CXXFLAGS} -o ${TESTBINARY} \
		${TESTMAINSRC} -I${TESTSRCDIR} -I${TESTSUPPORTDIR} \
		${UFCINCDIR} ${GTESTINCDIR} ${GTESTLIBS}

# Enable this to run py.test to regenerate main.cpp each time python tests are changed.
# Currently disabled because I think py.test should call make and not the other way around.
#${TESTMAINSRC}: test_*.py
#	py.test

clean:
	${RM} -f `find -name \*.pyc`
	${RM} -f `find -name \*.py~`
	${RM} -rf ${TESTSRCDIR}
	${RM} -rf __pycache__
	${RM} -f *.log
	${RM} -f ${TESTBINARY}
