Makefile 3 KB
Newer Older
1
.PHONY: everyday bootstrap stage1 stage2 stage3 clean
2 3

# ----------------------------------------------------------------------------
fpottier's avatar
fpottier committed
4
# Choose a target.
5

fpottier's avatar
fpottier committed
6 7 8
ifndef TARGET
  TARGET := native
endif
9

fpottier's avatar
fpottier committed
10 11
# ----------------------------------------------------------------------------
# Ocamlbuild tool and settings.
12

13
OCAMLBUILD := ocamlbuild -classic-display -j 0
14

fpottier's avatar
fpottier committed
15 16 17 18
# ----------------------------------------------------------------------------
# For everyday development.
# Typing "make" will perform just stage 1. This is enough to ensure that
# the source code is correct.
19

fpottier's avatar
fpottier committed
20
everyday: installation.ml stage1
21

fpottier's avatar
fpottier committed
22 23
# ----------------------------------------------------------------------------
# Building Menhir from scratch (a.k.a. bootstrapping).
24

25 26 27 28
bootstrap: .versioncheck
	@ $(MAKE) stage1
	@ $(MAKE) stage2
	@ $(MAKE) stage3
29

fpottier's avatar
fpottier committed
30 31
# ----------------------------------------------------------------------------
# Checking the version of the OCaml compiler.
32

33 34 35 36 37
# We explicitly build checkOCamlVersion as an OCaml binary program,
# instead of running it as a script, because that would require
# #loading str.cma, which is not supported on (some versions of?)
# Windows.

fpottier's avatar
fpottier committed
38
.versioncheck:
39
	@ echo Checking that OCaml is recent enough...
40 41 42 43
	@ rm -rf _versioncheck
	@$(OCAMLBUILD) -build-dir _versioncheck checkOCamlVersion.byte
	@ _versioncheck/checkOCamlVersion.byte --verbose --gt "4.02"
	@ rm -rf _versioncheck
fpottier's avatar
fpottier committed
44
	@ touch $@
45

fpottier's avatar
fpottier committed
46 47 48
# ----------------------------------------------------------------------------
# Stage 1.
# Build Menhir using ocamlyacc.
49

fpottier's avatar
fpottier committed
50
stage1:
51
	@$(OCAMLBUILD) -build-dir _stage1 menhir.$(TARGET)
52

fpottier's avatar
fpottier committed
53 54 55
# ----------------------------------------------------------------------------
# Stage 2.
# Build Menhir using Menhir (from stage 1).
56

57 58
# Do not use . to refer to the current directory, because ocamlbuild
# descends into another directory when executing commands.
59 60 61 62 63
# Do not use $(shell pwd) either, because this assumes we are running
# on a Unix platform, and can fail on Windows.
# So, use .., which works fine if ocamlbuild has effectively descended
# into a subdirectory.
SRC   := ..
64

65
FLAGS := -v -lg 1 -la 1 -lc 1 --table --infer --stdlib $(SRC) --strict --fixed-exception --canonical
66

fpottier's avatar
fpottier committed
67 68
stage2:
	@$(OCAMLBUILD) -build-dir _stage2 -tag fancy_parser \
69
	  -use-menhir -menhir "$(SRC)/_stage1/menhir.$(TARGET) $(FLAGS)" \
fpottier's avatar
fpottier committed
70
	  menhir.$(TARGET)
71 72

# ----------------------------------------------------------------------------
fpottier's avatar
fpottier committed
73 74 75 76 77
# Stage 3 (optional).
# Re-generate Menhir's parser using Menhir (from stage 2) and check that it
# is identical to the stage 2 parser.
stage3:
	@$(OCAMLBUILD) -build-dir _stage3 -tag fancy_parser \
78
	  -use-menhir -menhir "$(SRC)/_stage2/menhir.$(TARGET) $(FLAGS)" \
fpottier's avatar
fpottier committed
79 80 81 82 83 84 85
	  parser.ml parser.mli
	@for i in parser.ml parser.mli ; do \
	  if ! diff _stage2/$$i _stage3/$$i 2>&1 >/dev/null ; then \
	    echo "Bootstrap FAILED: $$i did not reach a fixed point."; exit 1 ; \
	  fi ; \
	done; \
	echo "Bootstrap successful."
86

fpottier's avatar
fpottier committed
87 88
# ----------------------------------------------------------------------------
# Cleaning up.
89

fpottier's avatar
fpottier committed
90
clean::
fpottier's avatar
fpottier committed
91
	rm -rf .versioncheck _build _stage1 _stage2 _stage3