-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
76 lines (59 loc) · 2.31 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
# Makefile to build all standalone programs.
#
# A make file consists of a set of rules that tells you how to build
# certain programs. It consists of the following format
#
# target: dep1 dep2 dep3
# CMD1
# CMD2
# CMD3
#
# The target is usually a file that you want to build (say an
# executable or an intermediate source file like foo.grm.sml) and the
# dependencies (dep1, dep2, etc) are other files on which target
# depends. The make command will build the above target if and only if
# it is _out of date_ i.e. target is older than any one of dep1 dep2
# dep3 and will use shell commands CMD1 CMD2... for it.
#
# For more details https://www.gnu.org/software/make/manual/make.html
# We have two executables that are generated by this make file; ec,
# the expression compiler, and rp, the reverse polish machine. Both of
# these programs depend on the following sml files. So I have defined
# a variable COMMON for this.
COMMON=ast.sml machine.sml
# Default rules for lex and yacc
# ------------------------------
#
# I need rp.lex.sml for rp and expr.lex.sml for the ec program. These
# files are generated from their corresponding .lex file. I could have
# written two different rules for each of these. However, it is
# simpler to write the following default rules.
#
#
%.lex.sml: %.lex
mllex $<
# The rule above says that all `.lex.sml` files depend on the
# corresponding `.lex and they can be achieved by running mllex on
# them. This means that if you have foo.lex.sml then its dependency
# is foo.lex and the corresponding update command is mllex foo.lex
# Similarly for the grammar files.
%.grm.sml: %.grm
mlyacc $<
all: rp ec
# Usually targets are files that you need to create and the make
# command will refuse to build if such a file exists in the directory
# and it is more recent than its dependencies. A phony target is a
# target that is not a file and if any of its dependency is out of
# date it will be built. A phony target with no dependency is always
# out of date which means it will always be run.
.PHONY: all clean test
clean:
rm -f *.lex.sml rp
rm -f *.grm.sml *.grm.desc *.grm.sig ec
rp: rp.lex.sml rp.mlb rp.sml ${COMMON}
mlton rp.mlb
ec: ec.sml ec.mlb expr.grm.sml expr.lex.sml ${COMMON} translate.sml
mlton ec.mlb
test: all
${CURDIR}/rp test.inp
${CURDIR}/ec test.expr | ${CURDIR}/rp