#--------------------------------------------------------------------------------
#
# Makefile for the SQL 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

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

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

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

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

sql.o:	sql.cc sql.yy.c $(INCLUDE) evaluation.h
	$(GCC) $(CXXFLAGS) -c sql.cc

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

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

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

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

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

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

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

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

company:
	 /bin/rm -f database
	 sql <company.sql

clean: 
	/bin/rm -f *.o *~ external.h common.h sql.output sql.yy.c sql.cc typecheck_out.cc typecheck_str.h evaluation_out.cc evaluation_str.h optimizer_out.cc optimizer_str.h core
