OCAML = /sw/lib

CMA = cma
CMO = cmo

CCFLAGS =
OFLAGS = -g

BASE_DIR = .
PROJ_DIR = $(BASE_DIR)

INCDIR = -I $(OCAML)/caml $(PROJ_DIR:%=-I %)
LIBDIR =

CC = gcc $(CCFLAGS) $(INCDIR)
OC = ocamlc $(OFLAGS) $(INCDIR)

all : cooper

cooper : cooper.$(CMO) global.$(CMO) lexr.mll parsr.mly main.ml
	ocamllex lexr.mll;
	ocamlyacc parsr.mly;
	$(OC) -c parsr.mli;
	$(OC) -c lexr.ml;
	$(OC) -c parsr.ml;
	rm lexr.ml;
	rm parsr.mli;
	rm parsr.ml;
	$(OC) -c main.ml;
	$(OC) -o cooper \
		nums.$(CMA) \
		cooper.$(CMO) \
		global.$(CMO) lexr.$(CMO) parsr.$(CMO) \
		main.$(CMO)

.SECONDARY :

%.$(CMO) : %.ml %.cmi
	$(OC) -c $<

%.cmi : %.mli
	$(OC) -c $<

clean : 
	rm $(PROJ_DIR:%=%/*.cmi) $(PROJ_DIR:%=%/*.cmo) $(PROJ_DIR:%=%/*.cma) \
		$(PROJ_DIR:%=%/*.cmx) $(PROJ_DIR:%=%/*.o) \
		cooper
