ocamldsort (dsort stands for dependency sorting) is a tiny command line 
tool to sort .ml files according to their dependencies in order
to link the corresponding .cmo files.

ocamldsort was thought to be used in makefiles. Here is a typical makefile:

OCAMLC=ocamlc
OCAMLDEP=ocamldep
OCAMLDSORT=ocamldsort
PPFLAGS=-pp camlp4o
SORTED_ML_FILES=$(shell cat .depsort 2>/dev/null || echo ERROR)
CMO_FILES=$(SORTED_ML_FILES:.ml=.cmo)

a.out: $(CMO_FILES)
	$(OCAMLC) ...	

ERROR:
	@echo Did you run \`make depend\'?
	@false

depend:
	$(OCAMLDEP) $(PPFLAGS) *.ml *.mli > .depend
	< .depend $(OCAMLDSORT) *.ml *.mli > .depsort

In fact, ocamldep doesn't need any .depend. It can be used this way:

$ ocamldsort *.ml *.mli > .depsort

Beware: if your program relies on linking order because of side effects,
ocamldsort can't help you.


