A cross-referencing OCamldoc HTML documentation generator

root / Makefile

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#
# Variables
#

LIB = odoc_xref

SRC = $(LIB).mli $(LIB).ml
MLI = $(LIB).mli
INC = -I +ocamldoc

DOC_DIR = ./api
DOC_TITLE = Odoc_xref

ODOC_FLAGS = -colorize-code -d $(DOC_DIR) -t $(DOC_TITLE)

LIB_FILES = $(LIB).cma $(LIB).cmi $(LIB).cmx $(LIB).o $(LIB).cmxs
ALL_FILES = META $(LIB_FILES)

OCAML_MAJOR = $(shell ocaml -vnum | awk 'BEGIN {FS="."} {print $$1}')
OCAML_MINOR = $(shell ocaml -vnum | awk 'BEGIN {FS="."} {print $$2}')

CPPO_FLAGS = -D "OCAML_MAJOR $(OCAML_MAJOR)" -D "OCAML_MINOR $(OCAML_MINOR)"

#
# Rules
#

lib: $(LIB_FILES)

all: lib doc

%: %.cppo
	@cppo $(CPPO_FLAGS) -o $@ $<

$(LIB).cmi: $(MLI)
	@ocamlfind ocamlc $(INC) -c $(MLI)

$(LIB).cma: $(SRC)
	@ocamlfind ocamlc $(INC) -a -o $(LIB).cma $(SRC)

$(LIB).cmx $(LIB).o : $(SRC)
	@ocamlfind ocamlopt $(INC) -c $(SRC)

$(LIB).cmxs : $(SRC)
	@ocamlfind ocamlopt $(INC) -shared -o $(LIB).cmxs $(SRC)

doc: $(DOC_DIR)/index.html

$(DOC_DIR)/index.html: $(SRC) $(DOC_DIR) $(LIB).cma
	@ocamlfind ocamldoc $(INC) -g $(LIB).cma $(ODOC_FLAGS) $(SRC)

$(DOC_DIR):
	@mkdir $(DOC_DIR)

clean:
	@rm -f $(LIB).cmo

distclean: clean
	@rm -rf $(LIB_FILES) $(DOC_DIR) $(SRC)

install: $(LIB_FILES)
	@if ocamlfind query $(LIB) > /dev/null 2>&1; then \
	    ocamlfind remove $(LIB); \
	fi
	@ocamlfind install $(LIB) $(ALL_FILES)

uninstall:
	@ocamlfind remove $(LIB)

.PHONY: all lib doc clean distclean install uninstall