TOP=..
CAMLC=camlc
COMPFLAGS=-stdlib $(TOP)/lib -W

CAMLLINK=$(TOP)/linker/camllink
LINKFLAGS=-stdlib $(TOP)/lib stdlib.zo
CPP=/lib/cpp -P

all: hw.prc fib.prc testlst.prc

hw.prc: hw.zo hw.rcp $(TOP)/lib/stdlib.zo
	rm -f *.bin
	ln -sf $(TOP)/runtime/*.camlruns.grc .
	ln -sf $(TOP)/shared/*.bin .
	pilrc hw.rcp
	$(CAMLLINK) $(LINKFLAGS) -exec camlcode hw.zo
	$(TOP)/runtime/pfix camlcode
	build-prc $@ "Caml HW" ClHW *.grc *.bin

fib.prc: fib.zo fib.rcp $(TOP)/lib/stdlib.zo
	rm -f *.bin
	ln -sf $(TOP)/runtime/*.camlruns.grc .
	ln -sf $(TOP)/shared/*.bin .
	pilrc fib.rcp
	$(CAMLLINK) $(LINKFLAGS) -exec camlcode fib.zo
	$(TOP)/runtime/pfix camlcode
	build-prc $@ "Fib demo" ClFI *.grc *.bin

testlst.prc: testlst.zo testlst.rcp $(TOP)/lib/stdlib.zo
	rm -f *.bin
	ln -sf $(TOP)/runtime/*.camlruns.grc .
	ln -sf $(TOP)/shared/*.bin .
	pilrc testlst.rcp
	$(CAMLLINK) $(LINKFLAGS) -exec camlcode testlst.zo
	$(TOP)/runtime/pfix camlcode
	build-prc $@ "Lst test" ClLL *.grc *.bin

.SUFFIXES :
.SUFFIXES : .ml .mli .zi .zo .mlp

.mli.zi:
	$(CAMLC) $(COMPFLAGS) -c $<
.ml.zo:
	$(CAMLC) $(COMPFLAGS) -c $<
.mlp.ml:
	@rm -f $@
	$(CPP) $< > $@
	@chmod a-w $@

clean:
	rm -f *.zi *.zix *.zo *.bin hw.prc fib.prc lst.prc
	rm -f camlcode
