-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
96 lines (71 loc) · 1.91 KB
/
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
PROGRAM=lambda
OBJS=${shell cat .objs}
XOBJS=${OBJS:.cmo=.cmx}
TEST_OBJS=${shell cat .test_objs}
TEST_XOBJS=${TEST_OBJS:.cmo=.cmx}
# Commands
OCAMLC=ocamlfind ocamlc
OCAMLOPT=ocamlfind ocamlopt
OCAMLDEP=ocamlfind ocamldep
OCAMLOBJS=ocamlobjs
OCAMLLEX=ocamllex
OCAMLYACC=ocamlyacc
INCLUDES=-I src
TEST_INCLUDES=-package oUnit -linkpkg -I tests
OCAMLFLAGS=${INCLUDES}
OCAMLOPTFLAGS=${INCLUDES}
# Definitions for building byte-compiled executables
all: bin/byte/${PROGRAM}
test: bin/byte/tests
bin/byte/tests
bin/byte:
mkdir -p bin/byte
bin/byte/${PROGRAM}: bin/byte ${OBJS}
${OCAMLC} -o $@ ${OCAMLFLAGS} ${OBJS}
bin/byte/tests: INCLUDES += ${TEST_INCLUDES}
bin/byte/tests: bin/byte ${TEST_OBJS}
${OCAMLC} -o $@ ${OCAMLFLAGS} ${TEST_OBJS}
# Targets for building native-compiled executables
opt: bin/opt/${PROGRAM}
test-opt: bin/opt/tests
bin/opt/tests
bin/opt:
mkdir -p bin/opt
bin/opt/${PROGRAM}: bin/opt ${XOBJS}
${OCAMLOPT} -o $@ ${OCAMLOPTFLAGS} ${XOBJS}
bin/opt/tests: INCLUDES += ${TEST_INCLUDES}
bin/opt/tests: bin/opt ${TEST_XOBJS}
${OCAMLOPT} -o $@ ${OCAMLOPTFLAGS} ${TEST_XOBJS}
# Common rules
.SUFFIXES: .ml .mli .mll .mly .cmo .cmi .cmx
.ml.cmo:
${OCAMLC} ${OCAMLFLAGS} -c $<
.mli.cmi:
${OCAMLC} ${OCAMLFLAGS} -c $<
.ml.cmx:
${OCAMLOPT} ${OCAMLOPTFLAGS} -c $<
.mly.ml:
${OCAMLYACC} $<
.mly.mli:
${OCAMLYACC} $<
.mll.ml:
${OCAMLLEX} $<
# Clean up
.PHONY: clean clobber
clean:
rm -f bin/byte/* bin/opt/*
find . -name '*.cm[iox]' -exec rm {} \;
find . -name '*.o' -exec rm {} \;
clobber: clean
rm -f src/grammar.ml src/grammar.mli
rm -f src/syntax.ml
# Dependencies
.PHONY: depend objs
depend: FIND_COMMAND=find . -name '*.ml' -print -o -name '*.mli' -print
depend: SOURCES=${shell ${FIND_COMMAND} | sed -e s#./##}
depend:
${OCAMLDEP} ${INCLUDES} -I src -I tests ${SOURCES} > .depend
objs:
${OCAMLOBJS} src/main.cmo < .depend > .objs
${OCAMLOBJS} tests/suite.cmo < .depend > .test_objs
include .depend