Makefile 3.88 KB
Newer Older
1
# ----------------------------------------------------------------------------
fpottier's avatar
fpottier committed
2
# Choose a target.
3

fpottier's avatar
fpottier committed
4 5 6
ifndef TARGET
  TARGET := native
endif
7

8 9 10 11 12
# Build .cmxs in case of native compilation.
ifneq ($(TARGET),byte)
MENHIRLIBCMXS := menhirLib.cmxs
endif

fpottier's avatar
fpottier committed
13 14
# ----------------------------------------------------------------------------
# Ocamlbuild tool and settings.
15

16
OCAMLBUILD := ocamlbuild -classic-display -j 0
17 18 19
ifeq ($(TARGET),byte)
  OCAMLBUILD := $(OCAMLBUILD) -byte-plugin
endif
20

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

26
.PHONY: everyday
fpottier's avatar
fpottier committed
27
everyday: installation.ml stage1
28

fpottier's avatar
fpottier committed
29 30
# ----------------------------------------------------------------------------
# Building Menhir from scratch (a.k.a. bootstrapping).
31

32
.PHONY: bootstrap
33
bootstrap:
34 35 36
	@ $(MAKE) stage1
	@ $(MAKE) stage2
	@ $(MAKE) stage3
37

fpottier's avatar
fpottier committed
38 39 40
# ----------------------------------------------------------------------------
# Stage 1.
# Build Menhir using ocamlyacc.
41

42
.PHONY: stage1
fpottier's avatar
fpottier committed
43
stage1:
44 45
	@ $(OCAMLBUILD) -build-dir _stage1 \
	    $(MENHIRLIBCMXS) menhir.$(TARGET)
46

47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
# ----------------------------------------------------------------------------
# Updating the auto-generated comments in parserMessages.messages.
# We use Menhir (from stage 1).

.PHONY: update
update: stage1
	cp parserMessages.messages parserMessages.messages.bak
	_stage1/menhir.$(TARGET) $(BASEFLAGS) --stdlib . \
	  --update-errors parserMessages.messages.bak \
	  fancy-parser.mly \
	  > parserMessages.messages
	rm parserMessages.messages.bak

# ----------------------------------------------------------------------------
# Stripping away the auto-generated comments in parserMessages.messages.

.PHONY: strip
strip:
	sed -e "/^##/d" -i.bak parserMessages.messages
	rm parserMessages.messages.bak

fpottier's avatar
fpottier committed
68 69 70
# ----------------------------------------------------------------------------
# Stage 2.
# Build Menhir using Menhir (from stage 1).
71

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

80 81 82 83 84 85 86 87 88 89 90
BASEFLAGS := \
  -lg 1 -la 1 -lc 1 \
  --canonical \
  --table \
  --strict \
  --fixed-exception \

FLAGS := \
  $(BASEFLAGS) \
  -v \
  --stdlib $(SRC) \
91

92
.PHONY: stage2
fpottier's avatar
fpottier committed
93
stage2:
94 95
	@ $(OCAMLBUILD) -build-dir _stage2 -tag fancy_parser \
	    -use-menhir -menhir "$(SRC)/_stage1/menhir.$(TARGET) $(FLAGS)" \
96
	    $(MENHIRLIBCMXS) menhir.$(TARGET)
97 98

# ----------------------------------------------------------------------------
fpottier's avatar
fpottier committed
99 100 101
# Stage 3 (optional).
# Re-generate Menhir's parser using Menhir (from stage 2) and check that it
# is identical to the stage 2 parser.
102 103

.PHONY: stage3
fpottier's avatar
fpottier committed
104
stage3:
105 106 107 108 109 110 111 112 113
	@ $(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."
114

115
# ----------------------------------------------------------------------------
116 117 118 119 120

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

MENHIRSDK       := menhirSdk.cmo
ifneq ($(TARGET),byte)
121
MENHIRSDK       := $(MENHIRSDK) menhirSdk.cmx menhirSdk.cmxs
122 123 124 125 126
endif

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

127
.PHONY: sdk
128 129 130 131 132 133
sdk:
	@ $(OCAMLBUILD) \
	    -build-dir _sdk \
	    -tag sdk \
	    $(MENHIRSDK)

fpottier's avatar
fpottier committed
134 135
# ----------------------------------------------------------------------------
# Cleaning up.
136

137
.PHONY: clean
fpottier's avatar
fpottier committed
138
clean::
139
	rm -rf _stage1 _stage2 _stage3 _sdk