I downloaded thisMakefile and I'm having a hard time understanding how it works.

I am programming in Ocaml and for some module, I implemented an interface (.mli). Strangely, even when I add the .mli file before the corresponding .ml file, the Makefile seems to skip it; so I'm getting the error

could not find the X.cmi for the module X.

Worse, I added some file without the required .mli and strangely again the Makefile automatically added them to the list of sources.
I'm saying strangely but perhaps its perfectly normal to Makefiles expert.

I'm not an expert when it comes to Makefile, can anyone help me understanding how this Makefile works?

This may take a few iterations. What happens when you make X.cmi?
–
BetaJul 31 '12 at 14:06

X.cmi doesn't exist at that moment, when I compile X.ml separatly with ocamlc, and make, the compilation is successful. X.cmi is the result of ocamlc -c X.mli
–
Joseph ElcidJul 31 '12 at 14:08

Exactly; when you make X.cmi, you are telling Make to build X.cmi. Make sees that X.cmi does not exist, so it looks for a rule to build it, sees that X.mli is present, and runs ocamlc -c X.mli. (That's what should happen.)
–
BetaJul 31 '12 at 14:17