########################################
#
#	Build the NEC2++ parser using the
#	ANTLR compiler construction toolkit
#	
#	On Debian Systems just type:
#	aptitude install antlr libantlr-dev
#

.SUFFIXES: .parse .nec



NECPP_SRC 	= ../src/c_evlcom.cpp ../src/c_geometry.cpp ../src/c_ggrid.cpp \
	../src/c_plot_card.cpp ../src/matrix_algebra.cpp ../src/misc.cpp \
	../src/nec_context.cpp ../src/nec_ground.cpp ../src/nec_output.cpp \
	../src/nec_radiation_pattern.cpp ../src/nec_exception.cpp
NECPP_OBJ 	= $(NECPP_SRC:.cpp=.o)

ANTLR_SRC 	= antlr_test.cpp NECLexer.cpp NECParser.cpp
ANTLR_OBJ 	= $(ANTLR_SRC:.cpp=.o)
ANTLR		= java -classpath /usr/share/java/antlr.jar antlr.Tool

all:	antlr test

echo:
	echo ${NECPP_SRC}
	
antlr:	nec.g
	${ANTLR} nec.g
	
clean:
	rm -f ${ANTLR_OBJ} ${NECPP_OBJ} NEC* antlr_test

LDFLAGS = -lstdc++ -lantlr -lm
CXXFLAGS = -I ../src/ -g3 -O0

test: ${ANTLR_OBJ} ${ANTLR_SRC} ${NECPP_OBJ} ${NECPP_SRC}
	g++ -o antlr_test ${ANTLR_OBJ} ${NECPP_OBJ} ${LDFLAGS}
	./antlr_test < ../test_data/example2.nec
	./antlr_test < ../test_data/example3.nec

TEST_FILES := $(shell find ../test_data/ -name "*.nec")
TEST_OUT	= $(TEST_FILES:.nec=.parse)

.nec.parse:
	- ./antlr_test < $<
	
test_all: ${TEST_OUT}
	echo "DONE"
