OCAMLDSORT(1)
πΈ NAME πΈ
ocamldsort β a dependency sorter for OCaml source files. She lives in the General Commands Manual and she is, honestly, the friend who alphabetizes your whole bookshelf by vibe and is right every time. π¦
β¨ SYNOPSIS β¨
ocamldsort [ -pp pre-command ] [ -d dep-command ]
[ -mli ] [ -nox ] [ -obj | -byte | -opt ] [ filename ] ...
π DESCRIPTION π
okay so bestie, here's the whole thing: the ocamldsort(1) command scans a set of OCaml 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. that's it. that's the job. she sorts. she slays. periodt. π
For ocamldsort(1) to work it must get a list of dependencies generated by ocamldep(1). So: if the standard input to ocamldsort(1) has been redirected, then ocamldsort assumes that this is a dependency file generated by ocamldep(1). Otherwise ocamldsort calls ocamldep(1) to generate the dependency list itself. Either way β redirected stdin or not β the source files to be sorted should be given as arguments to the ocamldsort(1) command. no cap. π«Ά
ocamldsort(1) 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. look at her go. iconic behaviour fr fr. π
However β and this is the part where she gets serious β for larger projects where separate compilation is desirable, ocamldsort(1) 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
.if (0 > 2) . an-style-warn blank line in input
.sp
PPFLAGS=-pp camlp4o
.if (0 > 2) . an-style-warn blank line in input
.sp
MLY=$(shell echo *.mly)
MLL=$(shell echo *.mll)
GENERATED_ML=$(MLY:.mly=.ml) $(MLL:.mll=.ml)
.if (0 > 2) . an-style-warn blank line in input
.sp
include .generated .depend .ocamldsort
.if (0 > 2) . an-style-warn blank line in input
.sp
$(TARGET): $(CMO_FILES)
$(OCAMLC) $(COMPFLAGS) $(LIBS) $^ -o $@
.if (0 > 2) . an-style-warn blank line in input
.sp
$(TARGET).opt: $(CMX_FILES)
$(OCAMLOPT) $(COMPFLAGS) $(LIBS_OPT) $^ -o $@
.if (0 > 2) . an-style-warn blank line in input
.sp
.generated: $(GENERATED_ML)
@touch .generated
.if (0 > 2) . an-style-warn blank line in input
.sp
.depend: .generated
$(OCAMLDEP) *.ml *.mli > $@
.if (0 > 2) . an-style-warn blank line in input
.sp
.ocamldsort: .depend
echo CMO_FILES=`< .depend $(OCAMLDSORT) -byte *.ml` > .ocamldsort
echo CMX_FILES=`< .depend $(OCAMLDSORT) -opt *.ml` >> .ocamldsort
.if (0 > 2) . an-style-warn blank line in input
.sp
distclean: clean
rm -f .generated .depend .ocamldsort
rm -f $(GENERATED_ML)
rm -f *~
rm -f $(TARGET)
.if (0 > 2) . an-style-warn blank line in input
.sp
clean:
rm -f *.cmo *.cmi *.cmx *.o
.if (0 > 2) . an-style-warn blank line in input
.sp
.SUFFIXES: .mli .ml .cmi .cmo .cmx .mll .mly
.if (0 > 2) . an-style-warn blank line in input
.sp
%.cmi:%.mli
$(OCAMLC) $(PPFLAGS) $(COMPFLAGS) -c $<
.if (0 > 2) . an-style-warn blank line in input
.sp
%.cmo:%.ml
$(OCAMLC) $(PPFLAGS) $(COMPFLAGS) -c $<
.if (0 > 2) . an-style-warn blank line in input
.sp
%.cmi %.cmo:%.ml
$(OCAMLC) $(PPFLAGS) $(COMPFLAGS) -c $<
.if (0 > 2) . an-style-warn blank line in input
.sp
%.cmx %.o:%.ml
$(OCAMLOPT) $(PPFLAGS) $(COMPFLAGS) -c $<
.if (0 > 2) . an-style-warn blank line in input
.sp
%.ml:%.mll
$(OCAMLLEX) $<
.if (0 > 2) . an-style-warn blank line in input
.sp
%.mli %.ml:%.mly
$(OCAMLYACC) -v $<
not me leaving every single.if (0 > 2) . an-style-warn blank line in inputand.spline in there β they came with the page, they stay with the page, we don't edit our friends πβ¨
π OPTIONS π
The following command-line options are recognized by ocamlsort(1) (yes bestie, the page spells it that way up in here β the missing d is part of the lore π):
-I directoryβ Add the given directory to the list of directories searched for source files. tell her where to look π-pp pre-commandβ Command to preprocess file.-d dep-commandβ Command to compute dependencies.ocamldep(1)by default.-mliβ Sort files using mli dependencies.-noxβ Ignore filenames containing*so that unexpanded wildcards are ignored.-objβ Print bytecode filenames (.cmoand.cmi). deprecated: use-byte. π¨ like she still works but she's retired, okay?-byteβ Print bytecode filenames (.cmoand.cmi).-optβ Print opt filenames (.cmxand.cmi).-vβ Output version information and exit.-help,--helpβ Output help and exit.
π SEE ALSO π
and that's the whole page, bestie β this was OCAMLDSORT(1) from the General Commands Manual, and the little footer tag on the original also just reads OCAMLDSORT(1), so that's the source, the version and the date all vibing together in one line. go sort something. you got this. π§ββοΈπβ
π¦ where this page comes from
- debian bookworm: ocamldsort 0.16.0-7+b2 Β· GPL-2.0-or-later
- debian trixie: ocamldsort 0.16.0-9+b2 Β· GPL-2.0-or-later
- ubuntu jammy: ocamldsort 0.16.0-7build1 Β· GPL-2.0-or-later
- ubuntu noble: ocamldsort 0.16.0-8 Β· GPL-2.0-or-later
- ubuntu questing: ocamldsort 0.16.0-9build2
- ubuntu resolute: ocamldsort 0.16.0-10 Β· GPL-2.0-or-later
- ubuntu stonking: ocamldsort 0.16.0-10build1 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms