Skip to content

Commit 2e06493

Browse files
committed
Refactor Makefiles for Ocaml backend and parser to improve readability and enable native code compilation
1 parent 48ca29e commit 2e06493

3 files changed

Lines changed: 34 additions & 39 deletions

File tree

examples/ocaml/Makefile

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
include Makefile-generic-ocaml-rules.include
12
include ../../Makefile.include
23

34
########
@@ -28,9 +29,12 @@ MLANG=$(MLANG_BIN) $(MLANG_DEFAULT_OPTS) $(OPTIMIZE_FLAG)
2829
SPEC_DEP=$(MPP_FILE)
2930
endif
3031

31-
.PHONY : clean cleangen cleancalc cleanstat cleantest cleanresult
32+
# Include parser lib directory to make its module available
33+
OCAMLC_INCLUDE_LIST= -I parser
3234

33-
clean: cleancalc cleanstat cleanresult
35+
.PHONY : clean cleangen cleancalc cleanstat cleantest cleanresult run_tests
36+
37+
clean: cleancalc cleanstat cleanresult cleanparser
3438

3539
cleangen:
3640
rm -f ir.ml
@@ -45,16 +49,6 @@ cleanresult:
4549
cleanparser:
4650
$(MAKE) -C parser/ clean
4751

48-
##################################################
49-
# Implicit rules for OCaml modules
50-
##################################################
51-
52-
%.cmo: %.ml
53-
ocamlc.opt -c $(DEBUG_FLAG) $^
54-
55-
%.cmx: %.ml
56-
ocamlopt -c $(DEBUG_FLAG) $^
57-
5852
##################################################
5953
# Generating and running OCaml files from Mlang
6054
##################################################
@@ -65,26 +59,20 @@ ir.ml: $(SPEC_DEP)
6559
--backend ocaml --output ir.ml \
6660
$(SOURCE_FILES)
6761

68-
test_harness.cmo : test_harness.ml
69-
ocamlc.opt -c $(DEBUG_FLAG) -I parser $^
70-
7162
.INTERMEDIATE : test_harness.cmo test_harness.cmi test_harness.o test_harness.cmx
7263
# Compiling bytecode
73-
types_module.cmo:
74-
$(MAKE) -C parser/ types_module.cmo
75-
test_lexer.cmo :
76-
$(MAKE) -C parser/ test_lexer.cmo
77-
test_parser.cmo :
78-
$(MAKE) -C parser/ test_parser.cmo
79-
fip.cmo :
64+
types_module.cmo test_lexer.cmo test_parser.cmo fip.cmo:
8065
$(MAKE) -C parser/ fip.cmo
8166

8267
test.bc: types_module.cmo test_lexer.cmo test_parser.cmo fip.cmo mvalue.cmo ir.cmo test_harness.cmo
83-
ocamlc.opt $(DEBUG_FLAG) -o $@ -I parser unix.cma $^
68+
ocamlc.opt $(DEBUG_FLAG) -o $@ $(OCAMLC_INCLUDE_LIST) unix.cma $^
8469

8570
# Compiling native code
86-
test.exe: parser/fip.cmx mvalue.cmx ir.cmx test_harness.cmx
87-
ocamlopt $(DEBUG_FLAG) -o $@ unix.cmxa $^
71+
types_module.cmx test_lexer.cmx test_parser.cmx fip.cmx:
72+
$(MAKE) -C parser/ fip.cmx
73+
74+
test.exe: types_module.cmx test_lexer.cmx test_parser.cmx fip.cmx mvalue.cmx ir.cmx test_harness.cmx
75+
ocamlopt $(DEBUG_FLAG) -o $@ $(OCAMLC_INCLUDE_LIST) unix.cmxa $^
8876

8977
# Running test suite
9078
run: test.bc
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
##################################################
2+
# Implicit rules for OCaml modules
3+
##################################################
4+
5+
%.cmi: %.mli
6+
ocamlc.opt -c $(DEBUG_FLAG) $^
7+
8+
%.cmo: %.ml
9+
ocamlc.opt -c $(DEBUG_FLAG) $(OCAMLC_INCLUDE_LIST) $^
10+
11+
%.cmx: %.ml
12+
ocamlopt -c $(DEBUG_FLAG) $(OCAMLC_INCLUDE_LIST) $^

examples/ocaml/parser/Makefile

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
1+
include ../Makefile-generic-ocaml-rules.include
2+
13
clean:
2-
rm -f *.cmo *.cmi test_lexer.ml test_parser.ml test_parser.mli
4+
rm -f *.cmo *.cmi *.cmx *.o test_lexer.ml test_parser.ml test_parser.mli
35

46
# Compiling test file parser
5-
types_module.cmo:
6-
ocamlc.opt -c $(DEBUG_FLAG) types_module.ml
77

8-
test_parser.ml: types_module.cmo
8+
test_parser.mli test_parser.ml: types_module.cmo types_module.cmx
99
menhir --infer-write-query mock.ml test_parser.mly
1010
ocamlc.opt -i mock.ml > reply
1111
menhir --infer-read-reply reply test_parser.mly
1212
rm mock.ml reply
1313

14-
test_parser.cmo: test_parser.ml
15-
ocamlc.opt -c $(DEBUG_FLAG) test_parser.mli test_parser.ml
16-
17-
test_lexer.ml: test_parser.cmo
14+
test_lexer.ml: test_parser.cmi test_parser.cmo test_parser.cmx
1815
ocamllex test_lexer.mll
19-
20-
test_lexer.cmo: test_lexer.ml
21-
ocamlc.opt -c $(DEBUG_FLAG) test_lexer.ml
22-
23-
fip.cmo: test_lexer.cmo test_parser.cmo
24-
ocamlc.opt -c $(DEBUG_FLAG) fip.ml
16+
17+
fip.cmo: test_lexer.cmo
18+
19+
fip.cmx: test_lexer.cmx

0 commit comments

Comments
 (0)