# Makefile for the wristwatch example, a large Esterel program
#
# Stephen Edwards
#
# To compile, this requires the Esterel compiler "est," its runtime libraries,
# and the commandline library, available from
#  ftp://ic.eecs.berkeley.edu/pub/sedwards
#
# Additionally, to compile the graphical X interface, you will need the Tcl/Tk
# toolkits, available from
#  ftp://ftp.cs.berkeley.edu/ucb/tcl
#
# "make watch" makes an executable called "watch" with a tcl/tk-based
# graphical interface to the watch.
#
# "make watchc" makes an executable called "watchc" which contains
# a command-line interface for the watch
#

# This should point to where "tcl.h" and "tk.h" reside
# (part of the tcl/tk installation)
INCLUDEDIRS = -I/home/tcltk/include

# This should point to where libtcl.a and libtk.a reside
# (part of the tcl/tk installation)
LIBDIRS = -L/home/tcltk/lib

# This needs to be an ANSI-compatible C compiler, e.g., GNU's gcc
CC = gcc
CFLAGS = -g

# This should point to where the esterel compiler (and its libraries) resides
ESTDIR = ../src

RUNTIMELIB = $(ESTDIR)/runtime.o
COMMANDLINELIB = $(ESTDIR)/commandline.o
EST = $(ESTDIR)/est

# The name of a "good" m4 macro preprocessor.  GNU's gm4 works correctly.
M4 = gm4

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

TARFILES = README watch.strl watch.c watch.tcl Makefile
LIBS = -ltcl -ltk -lm -lX11
ESTFLAGS = -S -g

.SUFFIXES: .strl .t

# Make an assembly code file from an .strl (Esterel source) file

.strl.s:
	$(M4) $< | $(EST) $(ESTFLAGS) -o $@

# Translate an Esterel source file (.strl) into the intermediate format

.strl.t:
	$(M4) $< | $(EST) -t > $@

# The full Tcl/Tk graphical interface to the watch

watch : watch.o watch.s $(RUNTIMELIB)
	$(CC) $(CFLAGS) -o watch watch.o watch.s \
		$(RUNTIMELIB) $(LIBDIRS) $(LIBS)

# A simpler command-line interface to the watch

watchc : watch.s $(RUNTIMELIB) $(COMMANDLINELIB)
	$(CC) $(CFLAGS) -o watchc watch.s \
		$(RUNTIMELIB) $(COMMANDLINELIB)

# C code for the graphical watch

watch.o : watch.c
	$(CC) $(CFLAGS) -c watch.c $(INCLUDEDIRS)

# Runs the watch code through the macro preprocessor

watchout : watch.strl
	$(M4) watch.strl > watchout

# Runs the watch through the preprocessor and translates it into the
# intermediate format for debugging purposes

watchout2 : watch.strl
	$(M4) watch.strl | $(EST) -t > watchout2

tar : watch.tar.gz

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

clean :
	rm -f *~ *.s *.o *.t watch watchc watchout watchout2 watchcntl

