Makefile 2.91 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
stage1:
56
	@$(OCAMLBUILD) -build-dir _stage1 menhir.$(TARGET)
57

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

62 63 64 65 66
# Do not use . to refer to the current directory, because ocamlbuild
# descends into another directory when executing commands.
SRC   := $(shell pwd)

FLAGS := -v -lg 1 -la 1 -lc 1 --comment --infer --stdlib $(SRC) --strict --fixed-exception
67

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

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

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

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