# Makefile for an Esterel compiler
#
# Stephen Edwards
#
# "make all" makes the Esterel compiler "est," its runtime library "runtime.o,"
# and its command-line library, "commandline.o."
#
# This compiler generates assembly code for the SPARC architecture from
# Esterel source files (.strl).  It can also produce a non-executable
# intermediate format useful for debugging.
#
# Requires a C++ compiler such as g++ and flex and bison
# (lex and yacc may suffice)
#
# The latest version of this compiler, along with an extensive description
# (85 pages), and a lengthy wristwatch example can be found in
#
#  ftp://ic.eecs.berkeley.edu/pub/sedwards/
#

LEX = flex
# -t: write output to stdout, rather than lex.yy.c
LFLAGS = -t

YACC = bison
# -d: write the definitions file y.tab.h (used by scan.cc as gram.h)
# -y: force the output files to be y.tab.c and y.tab.h, equivalent to yacc
YFLAGS = -dy

CCC = g++
# CCCFLAGS = -O
CCCFLAGS = -g

CC = gcc
CFLAGS = -g

# You normally do not need to modify anything below this point.
# -------------------------------------------------------------

.SUFFIXES: .cc .o

HEADERS = est.h array.h ast.h parse.h am.h set.h
CCSOURCES = ast.cc main.cc am.cc sparc.cc
OTHERSOURCES = README $(HEADERS) scan.l gram.y Makefile runtime.c commandline.c

TARFILES =  $(OTHERSOURCES) $(CCSOURCES)

OBJECTS = $(CCSOURCES:cc=o) scan.o gram.o

.cc.o:
	$(CCC) -c $(CCCFLAGS) $<

all : est runtime.o commandline.o

est : $(OBJECTS)
	$(CCC) $(CCCFLAGS) -o est $(OBJECTS)

scan.cc : scan.l
	$(LEX) $(LFLAGS) -t scan.l > scan.cc

gram.cc gram.h : gram.y
	$(YACC) $(YFLAGS) gram.y
	mv y.tab.c gram.cc
	mv y.tab.h gram.h

scan.o : scan.cc $(HEADERS) gram.h
gram.o : gram.cc $(HEADERS)
ast.o : ast.cc $(HEADERS)
am.o : am.cc $(HEADERS)
main.o : main.cc $(HEADERS)
sparc.o : sparc.cc $(HEADERS)

runtime.o : runtime.c

commandline.o : commandline.c

tar : est.tar.gz

est.tar.gz : $(TARFILES)
	tar cf - $(TARFILES) | gzip > est.tar.gz

clean :
	rm -f $(OBJECTS) gram.cc gram.h scan.cc

veryclean : clean
	rm -f est *~
