The ocamldsort command scans a set of Objective Caml source files (.ml  
and .mli files), sorts them according to their dependencies and prints  
the sorted files in order to link their corresponding .cmo files.

For ocamldsort to work it must get a list of dependencies generated by
ocamldep, if the standard input to ocamldsort has been redirected
then ocamldsort assumes that this is a dependency file generated by
ocamldep. Otherwise ocamldsort calls ocamldep to generate the dependency
list itself. In either case the source files to be sorted should be
given as arguments to the ocamldsort command.

ocamldsort can be used to compile and link simple projects with one 
command, such as: 

ocamlc $(ocamldsort *.ml)

if your project doesn't contain .mli files or:

ocamlc -c $(ocamldsort -mli *.ml *.mli) && ocamlc $(ocamldsort -byte *.ml)

if it contains .mli files.

However for larger projects where separate compilation is desirable,
ocamldsort can also be used from within a makefile. Here is a typical
makefile example:

TARGET=my_program
OCAMLC=ocamlc
OCAMLOPT=ocamlopt
OCAMLDEP=ocamldep
OCAMLDSORT=ocamldsort
PPFLAGS=-pp camlp4o

CMO_FILES=$(shell < .depend ocamldsort $(PPFLAGS) -byte *.ml || echo ERROR)
CMX_FILES=$(shell < .depend ocamldsort $(PPFLAGS) -opt *.ml || echo ERROR)


$(TARGET): $(CMO_FILES)
	$(OCAMLC) -o $@ $^

$(TARGET).opt: $(CMX_FILES)
	$(OCAMLOPT) -o $@ $^

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

.SUFFIXES: .mli .ml .cmi .cmo .cmx

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

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

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

clean:
	rm *.cmo *.cmi *.cmx

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

include .depend
