Makefile 2.75 KB
Newer Older
1 2
# ocamlbuild options.
OCAMLBUILD := ocamlbuild -use-ocamlfind -classic-display
3

4 5 6
# For consistency with doc/Makefile, which relies on the same set of
# %.processed.ml files, we set this variable to true.
export VISITORS_BUILDING_DOCUMENTATION=true
POTTIER Francois's avatar
POTTIER Francois committed
7

8 9
# The source files.
TESTS := $(shell ls *.ml | grep -v processed)
POTTIER Francois's avatar
POTTIER Francois committed
10

11
# ------------------------------------------------------------------------------
POTTIER Francois's avatar
POTTIER Francois committed
12

13
.PHONY: test reinstall coverage bench mli processed clean
POTTIER Francois's avatar
POTTIER Francois committed
14

15 16 17 18 19
# Because ocamlbuild is not good at parallel builds, we have broken up the set
# of test sources into several subsets, each of which is described by an
# [.mllib] file. For each such file, we make a separate ocamlbuild invocation,
# and we let [make] run these invocations in parallel. (Each of them must use
# a distinct build directory, and ignore everyone else's build directory.)
POTTIER Francois's avatar
POTTIER Francois committed
20

21
test: reinstall
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
	@ echo Compiling...
	@ make -j4 $(patsubst %.mllib,%.cma,$(shell ls *.mllib))

%.cma:
	@ $(OCAMLBUILD) -build-dir _build_$* $@

# To ensure that we always have the current version of [visitors], we
# reinstall it before compiling.

reinstall:
	@ echo Re-installing...
	@ make -C ../src reinstall >/dev/null 2>/dev/null

# Checking that every .ml file is covered by one .mllib file.

coverage:
	@ for i in $(TESTS) ; do \
	  if ! grep -iw `basename $$i .ml` *.mllib >/dev/null ; then \
	    echo [ERROR] $$i is not covered by any .mllib file. ; \
	  fi \
	done

# ------------------------------------------------------------------------------
POTTIER Francois's avatar
POTTIER Francois committed
45

46
# A tiny speed benchmark.
47

48
bench: reinstall
49
	@ $(OCAMLBUILD) -build-dir _build_bench bench.native
50
	@ echo Running...
51 52
	@ _build_bench/bench.native

53 54 55 56 57 58 59
# Building an executable.

%.native:
	@ $(OCAMLBUILD) -build-dir \
	    _build_$(shell grep -iw $* *.mllib | sed -e 's/\([^.]*\).mllib:.*/\1/') \
	    $@

60 61 62
# ------------------------------------------------------------------------------

# Building inferred .mli files.
63

64
mli: reinstall
65 66 67 68 69 70 71 72 73 74 75 76 77
	make -j4 $(patsubst %.ml,%.inferred.mli,$(TESTS))

# This one is a bit tricky, as we must specify the right build directory.
# We grep to find out which .mllib file covers the desired .mli file,
# then construct the name of the build directory from the name of the
# .mllib file.

%.inferred.mli:
	@ $(OCAMLBUILD) -build-dir \
	    _build_$(shell grep -iw $* *.mllib | sed -e 's/\([^.]*\).mllib:.*/\1/') \
	    $@

# ------------------------------------------------------------------------------
POTTIER Francois's avatar
POTTIER Francois committed
78

79
# Preprocessing all source files.
80

81 82 83 84 85 86 87
processed: reinstall
	make -j4 -f ../src/Makefile.preprocess \
	  $(patsubst %.ml,%.processed.ml,$(TESTS))

# ------------------------------------------------------------------------------

# Cleaning up.
88

POTTIER Francois's avatar
POTTIER Francois committed
89
clean:
POTTIER Francois's avatar
POTTIER Francois committed
90
	@ rm -f *~
91
	@ rm -f *.processed.ml
92
	@ rm -rf _build*
93

94
# ------------------------------------------------------------------------------