###############################################################################
# $Id:$
###############################################################################

##xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
@stdvars@
##xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

## do not change this value 
subdir=examples/cpp/calc


srcdir = @abs_top_srcdir@/examples/cpp/calc
objdir = @abs_this_builddir@/examples/cpp/calc

this : test
test : test1 test2 test3

all: calc1 calc2 calc3 test

g_FILES = \
	$(srcdir)/calc.g \
	$(eol)

g_cxx_FILES = \
  $(objdir)/CalcLexer.cpp \
	$(objdir)/CalcParser.cpp \
	$(objdir)/CalcTreeWalker.cpp \
  $(eol)

g_hpp_FILES = \
	$(objdir)/CalcLexer.hpp \
  $(objdir)/CalcParser.hpp \
  $(objdir)/CalcParserTokenTypes.hpp \
  $(objdir)/CalcTreeWalker.hpp \
  $(eol)

g_txt_FILES = \
	$(objdir)/CalcParserTokenTypes.txt \
	$(eol)

g_gen_FILES = \
	$(g_cxx_FILES) \
	$(g_hpp_FILES) \
	$(g_txt_FILES) \
	$(eol)

g_obj_FILES = \
	$(objdir)/CalcLexer@OBJEXT@ \
	$(objdir)/CalcParser@OBJEXT@ \
	$(objdir)/CalcTreeWalker@OBJEXT@ \
  $(eol)

## Source files
calc1_cxx_FILES = \
	$(g_cxx_FILES) \
	$(srcdir)/Main.cpp  \
	$(eol)

calc2_cxx_FILES = \
	$(g_cxx_FILES) \
	$(srcdir)/Main2.cpp \
	$(eol)

calc3_cxx_FILES = \
	$(g_cxx_FILES) \
	$(srcdir)/Main3.cpp \
	$(eol)

## Object files
calc1_obj_FILES = \
	$(g_obj_FILES) \
	$(objdir)/Main@OBJEXT@  \
	$(eol)

calc2_obj_FILES = \
	$(g_obj_FILES) \
	$(objdir)/Main2@OBJEXT@ \
	$(eol)

calc3_obj_FILES = \
	$(g_obj_FILES) \
	$(objdir)/Main3@OBJEXT@ \
	$(eol)

## Test commands ..
test1_cmd = $(objdir)/calc1 < $(srcdir)/test.in
test2_cmd = $(objdir)/calc2 '1+1;'
test3_cmd = $(objdir)/calc3 '1+2;'


## Tests to be executed
test1 : calc1
	@ v="$(verbose)"; \
    if test $$v -gt 0 ; then \
      @ECHO@ "$(test1_cmd)" ; \
    else \
      @ECHO@ "exec test1 .."; \
    fi
	@ $(test1_cmd)

test2 : calc2	
	@ v="$(verbose)"; \
    if test $$v -gt 0 ; then \
      @ECHO@ "$(test2_cmd)" ; \
    else \
      @ECHO@ "exec test2 .."; \
    fi
	@ $(test2_cmd)

test3 : calc3
	@ v="$(verbose)"; \
    if test $$v -gt 0 ; then \
      @ECHO@ "$(test3_cmd)" ; \
    else \
      @ECHO@ "exec test3 .."; \
    fi
	@ $(test3_cmd)


## How to make binaries
calc1 : $(calc1_obj_FILES) @ANTLR_LIB@
	@ @CXX_LINK_CMD@ $@ $(calc1_obj_FILES)

calc2 : $(calc2_obj_FILES) @ANTLR_LIB@
	@ @CXX_LINK_CMD@ $@ $(calc2_obj_FILES)

calc3 : $(calc3_obj_FILES) @ANTLR_LIB@
	@ @CXX_LINK_CMD@ $@ $(calc3_obj_FILES)

## How to compile ANTLR grammar files
$(g_gen_FILES) : $(g_FILES) @ANTLR_JAR@
	@ANTLR_COMPILE_CMD@  $(g_FILES)

## GNU make - how to make object file
$(objdir)/%@OBJEXT@ : $(srcdir)/%.cpp
	@ @CXX_COMPILE_CMD@ $<

## GNU make - how to make object file
$(objdir)/%@OBJEXT@ : $(objdir)/%.cpp
	@ @CXX_COMPILE_CMD@ $<

## GNU make - how to make object file
%@OBJEXT@ : $(srcdir)/%.cpp
	@ @CXX_COMPILE_CMD@ $<

## GNU make - how to make object file
%@OBJEXT@ : $(objdir)/%.cpp
	@ @CXX_COMPILE_CMD@ $<

## Housecleaning
clean:
	@RMF@ *.o *.obj *.exe calc1 calc2 calc3  $(g_gen_FILES) test1 test2 test3

distclean: clean
	@RMF@ Makefile

# Dependencies
$(objdir)/CalcLexer@OBJEXT@ :       \
 $(objdir)/CalcLexer.hpp            \
 $(objdir)/CalcParserTokenTypes.hpp

$(objdir)/CalcParser@OBJEXT@     :  \
 $(objdir)/CalcParser.hpp           \
 $(objdir)/CalcParserTokenTypes.hpp

$(objdir)/CalcTreeWalker@OBJEXT@ :  \
 $(objdir)/CalcTreeWalker.hpp       \
 $(objdir)/CalcParserTokenTypes.hpp

$(objdir)/Main@OBJEXT@           :  \
 $(objdir)/CalcLexer.hpp            \
 $(objdir)/CalcParserTokenTypes.hpp \
 $(objdir)/CalcParser.hpp \
 $(objdir)/CalcTreeWalker.hpp

$(objdir)/Main2@OBJEXT@          :  \
 $(objdir)/CalcLexer.hpp            \
 $(objdir)/CalcParserTokenTypes.hpp \
 $(objdir)/CalcParser.hpp           \
 $(objdir)/CalcTreeWalker.hpp

$(objdir)/Main3@OBJEXT@          :  \
 $(objdir)/CalcLexer.hpp            \
 $(objdir)/CalcParserTokenTypes.hpp \
 $(objdir)/CalcParser.hpp           \
 $(objdir)/CalcTreeWalker.hpp

## If cxx.sh script changed ..
$(calc1_obj_FILES) : @abs_this_builddir@/scripts/cxx.sh
$(calc2_obj_FILES) : @abs_this_builddir@/scripts/cxx.sh
$(calc3_obj_FILES) : @abs_this_builddir@/scripts/cxx.sh

## If link.sh script changed ..
$(calc1_obj_FILES) : @abs_this_builddir@/scripts/link.sh
$(calc2_obj_FILES) : @abs_this_builddir@/scripts/link.sh
$(calc3_obj_FILES) : @abs_this_builddir@/scripts/link.sh

### get configured dependencies - for example, just list
### autoconf variable ANTLR_JAR as reference and it will
### be  done  automatically  as stddeps contains appropr.
### rule. For details, checkout scripts/config.vars[.in] 
@stddeps@


