#--------------------------------------------------------------------------------
#
# Makefile for the OQL optimizer
# Programmer: Leonidas Fegaras
# Date: 2/27/97
#
#--------------------------------------------------------------------------------

# The optgen directory (the optimizer generator)
OPTDIR = /export/home/fegaras/C++/optgen

# The GC directory (the garbage collector)
GCDIR = /export/home/fegaras/gc

# Old g++ compilers need this option to handle exceptions
EXCEPTIONS = -fhandle-exceptions

# Note: remove the following line
#   %option noyywrap
# from oql.lex if flex complains

GCC = g++
CXXFLAGS = -g
YACC = bison
LEX = flex
INCLUDE = $(OPTDIR)/basic.h
OPTGEN = $(OPTDIR)/optgen

oql:	main.cc external.h typecheck.h evaluation.h constant.h oql.o typecheck.o evaluation.o optimizer.o constant.o
	$(GCC) $(CXXFLAGS) $(EXCEPTIONS) main.cc oql.o optimizer.o typecheck.o evaluation.o constant.o $(OPTDIR)/basic.o $(GCDIR)/gc.a -o oql

external.h: $(GCDIR)/gc_cpp.h $(OPTDIR)/basic.h
	    echo "#include"'"'$(GCDIR)"/gc_cpp.h"'"' > external.h
	    echo "#include"'"'$(OPTDIR)"/basic.h"'"' >> external.h

common.h: $(OPTDIR)/common.cc
	  echo "#include"'"'$(OPTDIR)"/common.cc"'"' > common.h

oql.o:	oql.cc oql.yy.c $(INCLUDE)
	$(GCC) $(CXXFLAGS) -c oql.cc

oql.cc: oql.y
	$(YACC) -v oql.y
	mv oql.tab.c oql.cc

oql.yy.c: oql.lex
	  $(LEX) oql.lex
	  mv lex.yy.c oql.yy.c

typecheck_out.cc: typecheck.gen $(OPTGEN)
	          $(OPTGEN) typecheck

typecheck.o: typecheck_out.cc $(INCLUDE) typecheck.h evaluation.h
	     $(GCC) $(CXXFLAGS) $(EXCEPTIONS) -c typecheck_out.cc -o typecheck.o

evaluation_out.cc: evaluation.gen $(OPTGEN)
	           $(OPTGEN) evaluation

evaluation.o: evaluation_out.cc $(INCLUDE) typecheck.h evaluation.h
	      $(GCC) $(CXXFLAGS) $(EXCEPTIONS) -c evaluation_out.cc -o evaluation.o

optimizer_out.cc: optimizer.gen $(OPTGEN)
	          $(OPTGEN) optimizer

optimizer.o: optimizer_out.cc common.h $(INCLUDE)
	     $(GCC) $(CXXFLAGS) -c optimizer_out.cc -o optimizer.o

constant.o: constant.cc $(INCLUDE) constant.h typecheck.h  evaluation.h
	    $(GCC) $(CXXFLAGS) -c constant.cc -o constant.o

clean: 
	/bin/rm -f *.o *~ external.h common.h oql.output oql.yy.c oql.cc *_out.cc *_str.h core
