#######################################################################
# Makefile for chicken test-suite
#######################################################################

LANGUAGE     = chicken
VARIANT      = 
SCRIPTSUFFIX = _runme.ss
PROXYSUFFIX  = _runme_proxy.ss
srcdir       = .
top_srcdir   = ../../..
top_builddir = ../../..
CHICKEN_CSI  =  -quiet -batch -no-init
SO           = .so

#C_TEST_CASES = long_long list_vector pointer_in_out multivalue

# Skip the STD cases for now, except for li_std_string.i
SKIP_CPP_STD_CASES = Yes

CPP_TEST_CASES += li_std_string 

EXTRA_TEST_CASES += chicken_ext_test.externaltest

include $(srcdir)/../common.mk

# Overridden variables here
SWIGOPT += -nounit

# Custom tests - tests with additional commandline options
# If there exists a PROXYSUFFIX runme file, we also generate the wrapper
# with the -proxy argument
%.cppproxy: SWIGOPT += -proxy
%.cppproxy: SCRIPTSUFFIX = $(PROXYSUFFIX)

%.cproxy: SWIGOPT += -proxy
%.cproxy: SCRIPTSUFFIX = $(PROXYSUFFIX)

%.multiproxy: SWIGOPT += -proxy -noclosuses
%.multiproxy: SCRIPTSUFFIX = $(PROXYSUFFIX)

# Rules for the different types of tests
%.cpptest: 
	$(setup)
	+$(swig_and_compile_cpp)
	$(run_testcase)
	if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(PROXYSUFFIX) ]; then \
	  $(MAKE) $*.cppproxy; \
	fi

%.ctest:
	$(setup)
	+$(swig_and_compile_c)
	$(run_testcase)
	if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(PROXYSUFFIX) ]; then \
	  $(MAKE) $*.cproxy; \
	fi

%.multicpptest: 
	$(setup)
	+$(swig_and_compile_multi_cpp)
	$(run_testcase)
	if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(PROXYSUFFIX) ]; then \
	  $(MAKE) $*.multiproxy; \
	fi

%.externaltest:
	$(setup)
	+$(swig_and_compile_external)
	$(run_testcase)

%.cppproxy:
	echo "$(ACTION)ing testcase $* (with run test) under chicken with -proxy"
	+$(swig_and_compile_cpp)
	$(run_testcase)

%.cproxy:
	echo "$(ACTION)ing testcase $* (with run test) under chicken with -proxy"
	+$(swig_and_compile_c)
	$(run_testcase)

%.multiproxy:
	echo "$(ACTION)ing testcase $* (with run test) under chicken with -proxy"
	+$(swig_and_compile_multi_cpp)
	$(run_testcase)

# Runs the testcase. A testcase is only run if
# a file is found which has _runme.scm appended after the testcase name.
run_testcase = \
	if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \
	  env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) $(CHICKEN_CSI) $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); \
	fi

# Clean
%.clean:
	

clean:
	$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile chicken_clean
	rm -f *.scm
