Makefile 3.34 KB
Newer Older
fpottier's avatar
fpottier committed
1
.PHONY: everyday library 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 10

# ----------------------------------------------------------------------------
fpottier's avatar
fpottier committed
11
# Define the files that form the library.
12

fpottier's avatar
fpottier committed
13 14 15 16 17
ifeq ($(TARGET),byte)
  LIBFILES := menhirLib.cmo
else
  LIBFILES := menhirLib.cmo menhirLib.cmx
endif
18

fpottier's avatar
fpottier committed
19 20
# ----------------------------------------------------------------------------
# Ocamlbuild tool and settings.
21

22
OCAMLBUILD := ocamlbuild -classic-display -j 0
23

fpottier's avatar
fpottier committed
24 25 26 27
# ----------------------------------------------------------------------------
# For everyday development.
# Typing "make" will perform just stage 1. This is enough to ensure that
# the source code is correct.
28

fpottier's avatar
fpottier committed
29
everyday: installation.ml stage1
30

fpottier's avatar
fpottier committed
31 32
# ----------------------------------------------------------------------------
# Building MenhirLib.
33

fpottier's avatar
fpottier committed
34 35
library:
	$(OCAMLBUILD) $(LIBFILES)
36

fpottier's avatar
fpottier committed
37 38
# ----------------------------------------------------------------------------
# Building Menhir from scratch (a.k.a. bootstrapping).
39

fpottier's avatar
fpottier committed
40
bootstrap: .versioncheck stage1 stage2 stage3
41

fpottier's avatar
fpottier committed
42 43
# ----------------------------------------------------------------------------
# Checking the version of the OCaml compiler.
44

45 46 47 48 49
# 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
50
.versioncheck:
51
	@ echo Checking that OCaml is recent enough...
52 53 54 55
	@ rm -rf _versioncheck
	@$(OCAMLBUILD) -build-dir _versioncheck checkOCamlVersion.byte
	@ _versioncheck/checkOCamlVersion.byte --verbose --gt "4.02"
	@ rm -rf _versioncheck
fpottier's avatar
fpottier committed
56
	@ touch $@
57

fpottier's avatar
fpottier committed
58 59 60
# ----------------------------------------------------------------------------
# Stage 1.
# Build Menhir using ocamlyacc.
61

fpottier's avatar
fpottier committed
62
stage1:
63
	@$(OCAMLBUILD) -build-dir _stage1 menhir.$(TARGET)
64

fpottier's avatar
fpottier committed
65 66 67
# ----------------------------------------------------------------------------
# Stage 2.
# Build Menhir using Menhir (from stage 1).
68

69 70
# Do not use . to refer to the current directory, because ocamlbuild
# descends into another directory when executing commands.
71 72 73 74 75
# 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   := ..
76

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

fpottier's avatar
fpottier committed
79 80
stage2:
	@$(OCAMLBUILD) -build-dir _stage2 -tag fancy_parser \
81
	  -use-menhir -menhir "$(SRC)/_stage1/menhir.$(TARGET) $(FLAGS)" \
fpottier's avatar
fpottier committed
82
	  menhir.$(TARGET)
83 84

# ----------------------------------------------------------------------------
fpottier's avatar
fpottier committed
85 86 87 88 89
# 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 \
90
	  -use-menhir -menhir "$(SRC)/_stage2/menhir.$(TARGET) $(FLAGS)" \
fpottier's avatar
fpottier committed
91 92 93 94 95 96 97
	  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."
98

fpottier's avatar
fpottier committed
99 100
# ----------------------------------------------------------------------------
# Cleaning up.
101

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