# program names and other paths; they have to be adapted for your environment:
# CSC		C# compiler
# JAY		path and name of the jay parser generator
# JAYSKEL	path and name of jay's C# skeleton file
# RM		command to delete a file
# RMDIR		command to delete files and directories recursively
# DOCDIR	directory where to put the generated HTML documentation
# BINDIR	directory where to put the compiled executables
# COMPDIR	directory with the CCM components (for test targets)

# Environment for MS .NET (Windows)
# ---------------------------------
# CSC = csc
# JAY = jay
# JAYSKEL = jay-skeleton.cs
# RM  = del
# RMDIR = del /S
# DOCDIR= ..\html\
# BINDIR= ..\bin\
# COMPDIR=..\components\

# Environment for Mono (Unix)
# ---------------------------
CSC = mcs
JAY = jay
JAYSKEL = /usr/local/share/jay/skeleton.cs
RM  = rm -f
RMDIR = rm -rf
DOCDIR= ../html/
BINDIR= ../bin/
COMPDIR=../components/

# source files for cs2ccmb and the csmodel library
C2CSRC = report.cs location.cs cs-tokenizer.cs cs-parser.cs cs2ccmb.cs
LIBSRC = decls.cs iterator.cs expr.cs block.cs class.cs process.cs eqrel.cs

# file names for generated programs and libraries
LIB = csmodel.dll
LIBD = csmodeld.dll
C2C = cs2ccmb.exe
C2CD = cs2ccmbd.exe
BINDUMP = bindump.exe
SIM = sim.exe

.SUFFIXES: .cs .jay

# implicit rules

.jay.cs:
	$(JAY) -c $< < $(JAYSKEL) > $@

# build targets

release: $(BINDIR)$(C2C) $(BINDIR)$(SIM) $(BINDIR)$(BINDUMP)
debug: $(BINDIR)$(C2CD) $(BINDIR)$(SIM) $(BINDIR)$(BINDUMP)

$(BINDIR)$(LIB) : $(LIBSRC)
	$(CSC) /out:$(BINDIR)$(LIB) /target:library $(LIBSRC)

$(BINDIR)$(LIBD) : $(LIBSRC)
	$(CSC) /debug /define:DEBUG /out:$(BINDIR)$(LIBD) /target:library $(LIBSRC) 

$(BINDIR)$(C2C) : $(C2CSRC) $(BINDIR)$(LIB)
	$(CSC) /r:$(BINDIR)$(LIB) /out:$(BINDIR)$(C2C) $(C2CSRC) 

$(BINDIR)$(C2CD) : $(C2CSRC) $(BINDIR)$(LIBD)
	$(CSC) /debug /define:DEBUG /r:$(LIBD) /out:$(BINDIR)$(C2CD) $(C2CSRC) 

$(BINDIR)$(BINDUMP) : $(BINDIR)$(LIB) bindump.cs
	$(CSC) /r:$(BINDIR)$(LIB) /out:$(BINDIR)$(BINDUMP) bindump.cs 

$(BINDIR)$(SIM) : $(BINDIR)$(LIB) sim.cs pairset.cs statepredicate.cs debugging.cs
	$(CSC) /r:$(BINDIR)$(LIB) /out:$(BINDIR)$(SIM) sim.cs pairset.cs statepredicate.cs debugging.cs 

# the tail +4 strips the first three lines of the jay output to put the doc
# comment at the top of the file; this rule will not work under Windows since
# there is no tail command
doc: cs-parser.cs
	tail +4 cs-parser.cs > cs-parser.cs.stripped
	mv -f cs-parser.cs.stripped cs-parser.cs
	doxygen Doxyfile

# test targets

testswitch: $(BINDIR)$(C2C)
	$(BINDIR)$(C2C) -ccmb - $(COMPDIR)VFS.cs $(COMPDIR)Switch.cs -- true

testspeed: $(BINDIR)$(C2C)
	$(BINDIR)$(C2C) -ccmb - $(COMPDIR)VFS.cs $(COMPDIR)Speed.cs

testprolog: $(BINDIR)$(C2C)
	$(BINDIR)$(C2C) -prolog - $(COMPDIR)VFS.cs $(COMPDIR)Speed.cs

testbisim: $(BINDIR)$(C2C) $(BINDIR)$(SIM) $(BINDIR)$(BINDUMP)
	$(BINDIR)$(C2C) -bin speed.bin $(COMPDIR)VFS.cs $(COMPDIR)Speed.cs
	$(BINDIR)$(C2C) -bin speedabst.bin $(COMPDIR)VFS.cs $(COMPDIR)SpeedAbstr.cs
	$(BINDIR)$(BINDUMP) speedabst.bin
	$(BINDIR)$(BINDUMP) speed.bin
	$(BINDIR)$(SIM) speedabst.bin speed.bin
	$(BINDIR)$(SIM) -b speedabst.bin speed.bin
	$(RM) speed.bin speedabst.bin

# clean targets

clean:
	$(RM) $(BINDIR)$(LIB) $(BINDIR)$(LIBD) 
	$(RM) $(BINDIR)$(C2C) $(BINDIR)$(C2CD)
	$(RM) $(BINDIR)$(BINDUMP) $(BINDIR)$(SIM)

cleandoc:
	$(RMDIR) $(DOCDIR)

distclean: clean cleandoc
	$(RM) cs-parser.cs 

.PHONY: debug release clean cleandoc distclean testswitch testspeed testprolog testbisim
