.NOPARALLEL:

LIBS=
PKGS=
OCAMLBUILD=ocamlbuild -j 0 -cflags $(ocamlcflags) -lflags $(ocamllflags) $(ocamldocflags) -ocamlopt $(ocamloptflags) $(mpi) 

MLLFILES=$(filter-out $(wildcard _build/*), $(wildcard */*.mll) $(wildcard *.mll)) Utils/math_functions.c
MLYFILES=$(filter-out $(wildcard _build/*), $(wildcard */*.mly) $(wildcard *.mly))
MLFILES= $(filter-out $(wildcard Parallel_*/*) $(wildcard _build/*), $(wildcard */*.ml)  $(wildcard *.ml) )
MLIFILES=$(filter-out $(wildcard Parallel_*/*) $(wildcard _build/*), $(wildcard */*.mli) $(wildcard *.mli) )

ALL_NATIVE=$(patsubst %.ml,%.native,$(wildcard run_*.ml)) 
ALL_BYTE=$(patsubst %.ml,%.byte,$(wildcard run_*.ml)) 
ALL_EXE=$(ALL_BYTE) $(ALL_NATIVE) lib

.PHONY: default doc


default: $(ALL_EXE) 

tests: run_tests.native

lib: _build/Utils/Util.cma

_build/Utils/Util.cma: _build/Utils/Util.cmo _build/Utils/math_functions.o
	ocamlmklib -o _build/Utils/Util _build/Utils/Util.cmo _build/Utils/math_functions.o 

QCaml.odocl: $(MLIFILES)
	ls $(MLIFILES) | sed "s/\.mli//" > QCaml.odocl

doc: QCaml.odocl
	$(OCAMLBUILD) QCaml.docdir/index.html -use-ocamlfind  $(PKGS)  

%.inferred.mli: $(MLFILES)
	$(OCAMLBUILD) $*.inferred.mli -use-ocamlfind  $(PKGS) 
	mv _build/$*.inferred.mli .

%.byte: $(MLFILES) $(MLIFILES) $(MLLFILES) $(MLYFILES)
	rm -f -- $*
	$(OCAMLBUILD) $*.byte  -use-ocamlfind  $(PKGS) 

%.native: $(MLFILES) $(MLIFILES) $(MLLFILES) $(MLYFILES) 
	rm -f -- $*
	$(OCAMLBUILD) $*.native -use-ocamlfind $(PKGS)
	ln -s $*.native $*

%.p.native: $(MLFILES) $(MLIFILES) $(MLLFILES) $(MLYFILES) 
	rm -f -- $*
	$(OCAMLBUILD) $*.p.native -use-ocamlfind $(PKGS)

%.p.byte: $(MLFILES) $(MLIFILES) $(MLLFILES) $(MLYFILES) 
	rm -f -- $*
	$(OCAMLBUILD) -ocamlc ocamlcp $*.byte -use-ocamlfind $(PKGS)

clean: 
	rm -f QCaml.odocl *.byte *.native && $(OCAMLBUILD) -clean

debug: run_integrals.native
	./debug.sh

install: $(ALL_NATIVE) 
	cp run_hartree_fock.native $(bin)/run_hartree_fock

uninstall:
	rm -f $(bin)/run_hartree_fock
