Makefile 6.55 KB
Newer Older
1
# This is the main Makefile that is shipped as part of the source package.
2

3
# Keep in mind that the hierarchy that is shipped is not identical to the
4
5
6
7
8
# hierarchy within the git repository. Some sub-directories are not shipped.
# The documentation (manual.pdf, menhir.1) is pre-built and stored at the root.

# This Makefile can also be used directly in the repository. In that case,
# the documentation and demos are not installed.
9
10
11
12
13
14
15
16
17
18

# The hierarchy that is shipped includes:
#   demos
#   menhir.1
#   manual.pdf
#   src
#   Makefile (this one)

# ----------------------------------------------------------------------------

fpottier's avatar
fpottier committed
19
20
21
22
23
24
25
26
27
28
29
30
# The following variables must/can be configured.

ifndef PREFIX
  $(error Please define PREFIX)
endif

ifndef TARGET
  TARGET := native
endif

# ----------------------------------------------------------------------------

POTTIER Francois's avatar
Typo.    
POTTIER Francois committed
31
# By default, we attempt to use ocamlfind (if present in the PATH), but it
32
33
34
35
36
37
# is possible to prevent that externally by setting USE_OCAMLFIND to false.

ifndef USE_OCAMLFIND
  USE_OCAMLFIND = ocamlfind ocamlc -v >/dev/null 2>&1
endif

38
39
# ----------------------------------------------------------------------------
# Installation paths.
40
41
# These may be overridden from outside; e.g., our opam package description
# provides its own values of docdir, libdir, and mandir.
42

43
44
45
46
bindir          := $(PREFIX)/bin
docdir		:= $(PREFIX)/share/doc/menhir
libdir	        := $(PREFIX)/share/menhir
mandir          := $(PREFIX)/share/man/man1
47
48
49
50
MANS            := menhir.1
DOCS            := manual.pdf demos
MLYLIB          := src/standard.mly

51
52
53
54
# ----------------------------------------------------------------------------

# A few settings differ on Windows versus Unix.

55
56
57
# If the compiler is MSVC, then the name of the executable file ends in .exe,
# and object file names end in .obj instead of .o.

58
ifneq (,$(shell ocamlc -config | grep -E "ccomp_type: msvc"))
59
60
  MENHIREXE    := menhir.exe
  OBJ          := obj
fpottier's avatar
fpottier committed
61
62
# LIBSUFFIX    := lib
else
63
64
  MENHIREXE    := menhir
  OBJ          := o
fpottier's avatar
fpottier committed
65
66
# LIBSUFFIX    := a
endif
67

68
69
# The path $(installation_libdir), which is recorded in src/installation.ml (see
# below), must sometimes be translated using cygpath.
70
71
72
73
74
75
76
77
78
79

# This one is tricky. To summarize, if I understood correctly, we can assume
# that Cygwin always exists when Menhir is compiled and installed (because
# executing a Makefile, like this one, requires Cygwin), but we cannot assume
# that Menhir will be executed under Cygwin. If the OCaml compiler is
# configured to produce a Cygwin executable, then, yes, Cygwin is there at
# execution time, so path translation is not necessary (and should not be
# performed). On the other hand, if the OCaml compiler is configured to
# produce a native Windows executable, then Cygwin is not there at execution
# time and path translation is required. In summary, path translation must be
POTTIER Francois's avatar
Typo.    
POTTIER Francois committed
80
# performed if "os_type" is "Win32" or "Win64", and must not be performed if
81
82
# "os_type" is "Cygwin" or "Unix".

83
ifneq (,$(shell ocamlc -config | grep -E "os_type: (Win32|Win64)"))
84
85
86
installation_libdir := $(shell cygpath -m $(libdir))
else
installation_libdir := $(libdir)
87
endif
88

89
90
91
92
93
94
95
# -------------------------------------------------------------------------

# The names of the modules in MenhirLib are obtained by reading the
# non-comment lines in menhirLib.mlpack.

MENHIRLIB_MODULES := $(shell grep -ve "^[ \t\n\r]*\#" src/menhirLib.mlpack)

96
97
# ----------------------------------------------------------------------------

98
# The directory where things are built.
99

100
101
BUILDDIR := src/_stage2

102
103
104
# ----------------------------------------------------------------------------

# Compilation.
105
106
107
108

.PHONY: all install uninstall

all:
109
110
# Installation time settings are recorded within src/installation.ml.
# This file is recreated every time so as to avoid becoming stale.
111
	@ rm -f src/installation.ml
112
	@ echo "let libdir = \"$(installation_libdir)\"" > src/installation.ml
113
	@ if $(USE_OCAMLFIND) ; then \
114
115
116
117
	  echo "let ocamlfind = true" >> src/installation.ml ; \
	else \
	  echo "let ocamlfind = false" >> src/installation.ml ; \
	fi
118
# Compile the library modules and the Menhir executable.
119
120
121
122
123
124
	@ $(MAKE) -C src library bootstrap
# The source file menhirLib.ml is created by concatenating all of the source
# files that make up MenhirLib. This file is not needed to compile Menhir or
# MenhirLib. It is installed at the same time as MenhirLib and is copied by
# Menhir when the user requests a self-contained parser (one that is not
# dependent on MenhirLib).
125
126
	@ echo "Creating menhirLib.ml"
	@ rm -f $(BUILDDIR)/menhirLib.ml
127
	@ for m in $(MENHIRLIB_MODULES) ; do \
128
129
130
	  echo "module $$m = struct" >> $(BUILDDIR)/menhirLib.ml ; \
	  cat src/$$m.ml >> $(BUILDDIR)/menhirLib.ml ; \
	  echo "end" >> $(BUILDDIR)/menhirLib.ml ; \
131
132
133
134
135
	done
# The source file menhirLib.mli is created in the same way. If a module
# does not have an .mli file, then we assume that its .ml file contains
# type (and module type) definitions only, so we copy it instead of the
# (non-existent) .mli file.
136
137
	@ echo "Creating menhirLib.mli"
	@ rm -f $(BUILDDIR)/menhirLib.mli
138
	@ for m in $(MENHIRLIB_MODULES) ; do \
139
	  echo "module $$m : sig" >> $(BUILDDIR)/menhirLib.mli ; \
140
	  if [ -f src/$$m.mli ] ; then \
141
	    cat src/$$m.mli >> $(BUILDDIR)/menhirLib.mli ; \
142
	  else \
143
	    cat src/$$m.ml >> $(BUILDDIR)/menhirLib.mli ; \
144
	  fi ; \
145
	  echo "end" >> $(BUILDDIR)/menhirLib.mli ; \
146
147
148
149
150
151
152
153
154
155
	done

# -------------------------------------------------------------------------

# The files that should be installed as part of menhirLib.

MENHIRLIB       := menhirLib.mli menhirLib.ml menhirLib.cmi menhirLib.cmo
ifneq ($(TARGET),byte)
MENHIRLIB       := $(MENHIRLIB) menhirLib.cmx menhirLib.$(OBJ)
endif
156
157
158
159

# ----------------------------------------------------------------------------
# Installation.

160
install:
161
# Install the executable.
162
	mkdir -p $(bindir)
163
	install $(BUILDDIR)/menhir.$(TARGET) $(bindir)/$(MENHIREXE)
164
165
# Install the library.
	mkdir -p $(libdir)
166
	install -m 644 $(MLYLIB) $(libdir)
fpottier's avatar
fpottier committed
167
	@if $(USE_OCAMLFIND) ; then \
168
	  echo Installing MenhirLib via ocamlfind. ; \
fpottier's avatar
fpottier committed
169
	  ocamlfind install menhirLib src/META $(patsubst %,$(BUILDDIR)/%,$(MENHIRLIB)) ; \
170
171
	else \
	  echo Installing MenhirLib manually. ; \
fpottier's avatar
fpottier committed
172
	  install -m 644 $(patsubst %,$(BUILDDIR)/%,$(MENHIRLIB)) $(libdir) ; \
173
	fi
174
175
176
177
178
179
180
# Install the documentation, if it has been built.
	if [ -f manual.pdf ] ; then \
	  mkdir -p $(docdir) ; \
	  mkdir -p $(mandir) ; \
	  cp -r $(DOCS) $(docdir) ; \
	  cp -r $(MANS) $(mandir) ; \
	fi
181
182
183
184
185
186
187
188

uninstall:
	rm -rf $(bindir)/$(MENHIREXE)
	rm -rf $(libdir)
	@if $(USE_OCAMLFIND) ; then \
	  echo Un-installing MenhirLib via ocamlfind. ; \
	  ocamlfind remove menhirLib ; \
	fi
189
190
	rm -rf $(docdir)
	rm -rf $(mandir)/$(MANS)