# Compilers
OCAMLC=ocamlc -I +flowcamlrun
OCAMLOPT=ocamlopt -I +flowcamlrun
FLOWCAMLC=flowcamlc

OCAMLDEP=ocamldep
FLOWCAMLDEP=flowcamldep

# The list of compilation units of the program
UNITS=passwd shadow verbose main

all: passwd2shadow pol

# To check the security policy
pol: $(UNITS:%=%.fcmi)
	flowcamlpol $^

polgr: $(UNITS:%=%.fcmi)
	flowcamlpol -graph $^


# To build the program
passwd2shadow: $(UNITS:%=%.cmo)
	$(OCAMLC) -o $@ flowcamlrun.cma $^


# Clean up
clean:
	rm -f passwd2shadow
	rm -f *.cm[iox] *.fcmi
	for i in *.mli; do \
	if test -f `basename $$i .mli`.fmli; then rm -f $$i; fi \
	done
	for i in *.ml; do \
	if test -f `basename $$i .ml`.fml; then rm -f $$i; fi \
	done

# Common rules
.SUFFIXES: .ml .mli .fml .fmli .cmi .cmo .cmx .fcmi 

.ml.cmo:
	$(OCAMLC) -c $<

.mli.cmi:
	$(OCAMLC) -c $<

.ml.cmx:
	$(OCAMLOPT) -c $<

.fmli.mli:
	$(FLOWCAMLC) $<

.fml.ml:
	$(FLOWCAMLC) $<

# Dependencies
depend-flowcaml:
	$(FLOWCAMLDEP) *.fml *.fmli > Depend.flowcaml

depend-ocaml: $(patsubst %.fml,%.ml,$(wildcard *.fml))\
              $(patsubst %.fml,%.ml,$(wildcard *.fml))
	$(OCAMLDEP) *.ml *.mli > Depend.ocaml

include Depend.flowcaml
include Depend.ocaml
