Makefile 3.46 KB
Newer Older
1
.PHONY: everyday bootstrap stage1 stage2 stage3 sdk 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
	@ rm -rf _versioncheck
41
	@ $(OCAMLBUILD) -build-dir _versioncheck checkOCamlVersion.byte
42 43
	@ _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
stage2:
68 69 70
	@ $(OCAMLBUILD) -build-dir _stage2 -tag fancy_parser \
	    -use-menhir -menhir "$(SRC)/_stage1/menhir.$(TARGET) $(FLAGS)" \
	    menhir.$(TARGET)
71 72

# ----------------------------------------------------------------------------
fpottier's avatar
fpottier committed
73 74 75 76
# 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:
77 78 79 80 81 82 83 84 85
	@ $(OCAMLBUILD) -build-dir _stage3 -tag fancy_parser \
	    -use-menhir -menhir "$(SRC)/_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."
86

87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
# -------------------------------------------------------------------------

# The ocamlbuild targets that should be used to build menhirSdk.

MENHIRSDK       := menhirSdk.cmo
ifneq ($(TARGET),byte)
MENHIRSDK       := $(MENHIRSDK) menhirSdk.cmx
endif

# ----------------------------------------------------------------------------
# Building menhirSdk.

sdk:
	@ $(OCAMLBUILD) \
	    -build-dir _sdk \
	    -tag sdk \
	    $(MENHIRSDK)

fpottier's avatar
fpottier committed
105 106
# ----------------------------------------------------------------------------
# Cleaning up.
107

fpottier's avatar
fpottier committed
108
clean::
109
	rm -rf .versioncheck _stage1 _stage2 _stage3 _sdk