Makefile 2.79 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

POTTIER Francois's avatar
POTTIER Francois committed
22
OCAMLBUILD := ocamlbuild -classic-display -j 0 -cflags "-safe-string -bin-annot"
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

fpottier's avatar
fpottier committed
45 46 47
.versioncheck:
	@ echo Checking that Objective Caml is recent enough...
	@$(OCAMLBUILD) -build-dir _stage1 checkOCamlVersion.byte
48
	@ _stage1/checkOCamlVersion.byte --verbose --gt "4.02"
fpottier's avatar
fpottier committed
49
	@ touch $@
50

fpottier's avatar
fpottier committed
51 52 53
# ----------------------------------------------------------------------------
# Stage 1.
# Build Menhir using ocamlyacc.
54

fpottier's avatar
fpottier committed
55 56 57
stage1:
	@$(OCAMLBUILD) -build-dir _stage1 -tag yacc_parser \
	  menhir.$(TARGET)
58

fpottier's avatar
fpottier committed
59 60 61
# ----------------------------------------------------------------------------
# Stage 2.
# Build Menhir using Menhir (from stage 1).
62

63
FLAGS := -v -lg 1 -la 1 -lc 1 --comment --infer --stdlib . --strict --fixed-exception
64

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

# ----------------------------------------------------------------------------
fpottier's avatar
fpottier committed
71 72 73 74 75 76 77 78 79 80 81 82 83
# 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 \
	  -use-menhir -menhir "$(shell pwd)/_stage2/menhir.$(TARGET) $(FLAGS)" \
	  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."
84

fpottier's avatar
fpottier committed
85 86
# ----------------------------------------------------------------------------
# Cleaning up.
87

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