-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmakefile
More file actions
101 lines (84 loc) · 3.04 KB
/
makefile
File metadata and controls
101 lines (84 loc) · 3.04 KB
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
97
98
99
100
101
# Compile MiniOOL
# Written by Zachary Ferguson
# Compiler flags
CFLAGS = -g
SDIR = src
DDIR = docs
ODIR = bin
EDIR = examples
_OBJ_PARSER = utils.cmx flags.cmx abstractSyntaxTree.cmx programString.cmx \
abstractSyntaxTreeString.cmx staticSemantics.cmx semanticDomains.cmx \
operationalSemantics.cmx lexer.cmx
_OBJ = $(_OBJ_PARSER) parser.cmx MiniOOL.cmx
OBJ_PARSER = $(patsubst %,$(ODIR)/%,$(_OBJ_PARSER))
OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))
OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))
_DEPS = utils.ml flags.ml abstractSyntaxTree.ml programString.ml \
abstractSyntaxTreeString.ml staticSemantics.ml semanticDomains.ml \
operationalSemantics.ml lexer.ml
DEPS = $(patsubst %,$(SDIR)/%,$(_DEPS))
# Print some helpful usage information
.PHONY: all
all: $(ODIR) MiniOOL
@echo "\033[1;32mSuccessfully compiled MiniOOL!\033[0m"
@echo "To use MiniOOL run '\033[1;36m./MiniOOL\033[0m'."
@echo "Optionally run '\033[1;36m./MiniOOL --verbose\033[0m' to print the\n\
abstract syntax tree and additional information."
$(ODIR):
@echo "\033[1;32mMaking a bin directory to store object files\033[0m"
mkdir -p $(ODIR)
@echo ""
# Wrap MiniOOL_raw with rlwrap so it has a history and arrow key usage
MiniOOL: $(ODIR)/MiniOOL_raw
@echo "\033[1;32mCreating a script to wrap MiniOOL with rlwrap\033[0m"
# printf "#!/bin/bash\nrlwrap ./$(ODIR)/MiniOOL_raw \"$$%s\"" "@" > MiniOOL
printf "#!/bin/bash\nif hash rlwrap 2>/dev/null; then\n rlwrap \
./bin/MiniOOL_raw \"$$%s\"\nelse\n ./bin/MiniOOL_raw \"$$%s\"\nfi" \
"@" "@" > MiniOOL
chmod +x MiniOOL
@echo ""
# Link all compiled files together
$(ODIR)/MiniOOL_raw: $(OBJ)
@echo "\033[1;32mLinking the lexer, parser, and interpreter\033[0m"
ocamlopt -o $@ $^ $(CFLAGS)
@echo ""
# Lexer
$(ODIR)/lexer.ml: $(SDIR)/lexer.mll
@echo "\033[1;32mCreating lexer\033[0m"
ocamllex -o $@ $<
@echo ""
$(ODIR)/lexer.cmx: $(ODIR)/lexer.ml $(ODIR)/parser.cmi
@echo "\033[1;32m\nCompiling the lexer\033[0m"
ocamlopt -c -o $@ -I $(ODIR) $(ODIR)/lexer.ml $(CFLAGS)
@echo ""
# Parser
$(ODIR)/parser.ml: $(SDIR)/parser.mly
@echo "\033[1;32mCreating parser\033[0m"
menhir -v --explain -b $(ODIR)/parser $(SDIR)/parser.mly
$(ODIR)/parser.cmi: $(ODIR)/parser.ml
ocamlopt -c -o $@ -I $(ODIR) $(ODIR)/parser.mli $(CFLAGS)
$(ODIR)/parser.cmx: $(ODIR)/parser.ml $(OBJ_PARSER)
@echo "\033[1;32mCompiling the parser\033[0m"
ocamlopt -c -o $@ -I $(ODIR) $< $(CFLAGS)
@echo ""
$(ODIR)/MiniOOL.cmx: $(SDIR)/MiniOOL.ml $(SDIR)/utils.ml $(SDIR)/flags.ml $(ODIR)/parser.cmx
@echo "\033[1;32mCompiling the MiniOOL.ml\033[0m"
ocamlopt -c -o $@ -I $(ODIR) $< $(CFLAGS)
@echo ""
$(ODIR)/%.cmx: $(SDIR)/%.ml
@echo "\033[1;32mCompiling $<\033[0m"
ocamlopt -c -o $@ -I $(ODIR) $< $(CFLAGS)
@echo ""
.PHONY: docs
docs: all
@echo "\033[1;32mCreating documentation files\033[0m"
mkdir -p $(DDIR)
ocamldoc -html -charset "utf-8" -I $(ODIR) -d $(DDIR) $(SDIR)/*.ml $(ODIR)/*.ml
# Clean up build files
.PHONY: clean
clean:
@echo "\033[1;32mCleaning up build files\033[0m"
/bin/rm -rf $(ODIR) MiniOOL makefile~
.PHONY: examples
examples: all
/bin/bash $(EDIR)/run_examples.sh